advertising via bluetooth is done
This commit is contained in:
@@ -6,7 +6,8 @@ import uasyncio as asyncio
|
||||
|
||||
|
||||
class Connection:
|
||||
def __init__(self):
|
||||
def __init__(self, bluetooth_handler=None):
|
||||
self.bluetooth_handler = bluetooth_handler
|
||||
self.load_public_constants()
|
||||
|
||||
# generate diffie-hellman keys
|
||||
@@ -19,16 +20,23 @@ class Connection:
|
||||
# start lora handler
|
||||
self.lora = LoRaHandler()
|
||||
|
||||
async def bluetooth_listener(self):
|
||||
while True:
|
||||
msg_type, payload = await self.bluetooth_handler.packets.get()
|
||||
|
||||
if msg_type == 3: # advertise self
|
||||
self.lora.advertise()
|
||||
|
||||
async def start(self):
|
||||
print("Starting connection...")
|
||||
self.lora.advertise()
|
||||
|
||||
if self.bluetooth_handler:
|
||||
asyncio.create_task(self.bluetooth_listener())
|
||||
|
||||
while True:
|
||||
msg: LoRaMessage = await self.lora.message_queue.get()
|
||||
|
||||
print(f"Received message from {msg.sender_id}: {msg.payload}")
|
||||
print("Sending response...")
|
||||
self.lora.send(b"Pong!", msg.sender_id)
|
||||
|
||||
def load_public_constants(self):
|
||||
with open("public_constants.txt", "r") as f:
|
||||
|
||||
Reference in New Issue
Block a user