advertising via bluetooth is done
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import bluetooth
|
||||
import struct
|
||||
import time
|
||||
from micropython import const
|
||||
from queue import Queue
|
||||
import uasyncio
|
||||
|
||||
|
||||
# i just made a UUID up and changed the last number to change what protocol you're using
|
||||
@@ -39,6 +42,12 @@ class BluetoothHandler:
|
||||
def __init__(self):
|
||||
print("Initializing Bluetooth...")
|
||||
self.ble = bluetooth.BLE()
|
||||
|
||||
print("Resetting bluetooth...")
|
||||
# Deactivate BLE to clear the state
|
||||
self.ble.active(False)
|
||||
time.sleep(0.5)
|
||||
|
||||
print("Activating...")
|
||||
self.ble.active(True)
|
||||
print("Setting IRQ callback...")
|
||||
@@ -53,11 +62,12 @@ class BluetoothHandler:
|
||||
|
||||
self.connections = set()
|
||||
|
||||
self.packets = Queue()
|
||||
|
||||
self.advertise()
|
||||
|
||||
def deserialize_msg(self, s: bytes):
|
||||
# returns packet type (int) and deserialized data
|
||||
print(s[1:].decode())
|
||||
return s[0], eval(s[1:].decode())
|
||||
|
||||
def _get_mac_address(self):
|
||||
@@ -118,4 +128,5 @@ class BluetoothHandler:
|
||||
packet_type, msg = self.deserialize_msg(msg)
|
||||
|
||||
print(f"Received: \"{msg}\"")
|
||||
uasyncio.create_task(self.packets.put((packet_type, msg)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user