tryna get bluetooth to work

This commit is contained in:
2026-03-07 09:15:45 +11:00
parent b19ad3ce82
commit 0f6cdabd25
4 changed files with 22 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
venv

View File

@@ -24,16 +24,23 @@ class BluetoothHandler:
self.ble.active(True) self.ble.active(True)
self.ble.irq(self.irq) self.ble.irq(self.irq)
self.mac_address = self._get_mac_address()
print(f"Mac Address: {self.mac_address}")
((self.tx_handle, self.rx_handle),) = self.ble.gatts_register_services((SERVICE,)) ((self.tx_handle, self.rx_handle),) = self.ble.gatts_register_services((SERVICE,))
self.connections = set() self.connections = set()
self.advertise() self.advertise()
def _get_mac_address(self):
mac = self.ble.config("mac")[1]
return ':'.join('{:02X}'.format(b) for b in mac)
def advertise(self): def advertise(self):
print("Advertising Bluetooth...") print("Advertising Bluetooth...")
# note: \x02\x01\x06\x0C\x09 is the BLE header that tells other devices we're BLE only and discoverable # note: \x02\x01\x06\x0C\x09 is the BLE header that tells other devices we're BLE only and discoverable
self.ble.gap_advertise(100_000, b"\x02\x01\x06\x0C\x09MeshConnectorNode") self.ble.gap_advertise(100_000, b"\x02\x01\x06\x0C\x09NODE-" + self.mac_address.encode())
def irq(self, event, data): def irq(self, event, data):
print(f"BLUETOOTH IRQ | EVENT: {event}, DATA: {data}") print(f"BLUETOOTH IRQ | EVENT: {event}, DATA: {data}")

View File

@@ -15,7 +15,9 @@ def main():
if LORA_ENABLED: if LORA_ENABLED:
lora_handler = LoRaHandler() lora_handler = LoRaHandler()
print("Halting Pico...")
while True:
pass
if __name__ == "__main__": if __name__ == "__main__":

10
test.py Normal file
View File

@@ -0,0 +1,10 @@
import bleak
import asyncio
async def main():
devices = await bleak.BleakScanner.discover()
print(devices)
asyncio.run(main())