advertising via bluetooth is done

This commit is contained in:
2026-05-15 17:14:33 +10:00
parent 00ac34431d
commit 46ae344c0c
5 changed files with 50 additions and 28 deletions

View File

@@ -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)))