diff --git a/README.rst b/README.rst index 6b83d47..9ba7f4d 100644 --- a/README.rst +++ b/README.rst @@ -70,11 +70,11 @@ Website starten:: Admin Benutzer erstellen:: - $ docker-compose run --rm web python manage.py createsuperuser + $ docker-compose -f local.yml run --rm django python manage.py createsuperuser LoRa Daemon starten:: - $ docker-compose run --rm web python manage.py lora_daemon + $ docker-compose -f local.yml run --rm django python manage.py lora_daemon Nun ist es möglich auf der Website mit dem erstellten Admin Benutzer im Backend ein zu loggen um zugriff auf die Hauptwebsite zu erhalten. Dafür auf den Hostname des Host Systems im Browser eingeben wie ``http://localhost:8000/admin``. diff --git a/docs/Quickstart.rst b/docs/Quickstart.rst index 1e89e02..e9fdb6c 100644 --- a/docs/Quickstart.rst +++ b/docs/Quickstart.rst @@ -50,11 +50,11 @@ Website starten:: Admin Benutzer erstellen:: - $ docker-compose run --rm web python manage.py createsuperuser + $ docker-compose -f local.yml run --rm django python manage.py createsuperuser LoRa Daemon starten:: - $ docker-compose run --rm web python manage.py lora_daemon + $ docker-compose -f local.yml run --rm django python manage.py lora_daemon Nun ist es möglich auf der Website mit dem erstellten Admin Benutzer im Backend ein zu loggen um zugriff auf die Hauptwebsite zu erhalten. Dafür auf den Hostname des Host Systems im Browser eingeben wie ``http://localhost:8000/admin``. diff --git a/docs/_static/Presentation.odp b/docs/_static/Presentation.odp new file mode 100644 index 0000000..cd09fca Binary files /dev/null and b/docs/_static/Presentation.odp differ diff --git a/pylorawebchat/chat/lora_daemon.py b/pylorawebchat/chat/lora_daemon.py index dfbf2e5..d7fdde0 100644 --- a/pylorawebchat/chat/lora_daemon.py +++ b/pylorawebchat/chat/lora_daemon.py @@ -23,7 +23,7 @@ def __init__(self, address: str = None, msg: str = None): def from_string(self, message_string: str): self.address = message_string[:4] - self.msg = message_string[5:] + self.msg = message_string[4:] print("{}: {}".format(self.address, self.msg)) def to_string(self): @@ -73,6 +73,9 @@ def __init__(self): self.serial_worker = serial.threaded.ReaderThread(self.ser, self) self.serial_worker.start() + # set the not busy + self.device_busy: bool = False + # serial buffer self.buffer = bytearray() self.transport = None @@ -136,6 +139,12 @@ def handle_packet(self, packet: bytes): print(incoming_packet) + # set device busy state + if incoming_packet == "AT,SENDING": + self.device_busy = True + if incoming_packet == "AT,SENDED": + self.device_busy = False + # check if packet is a message if incoming_packet[:2] == "LR": msg: Message = Message( @@ -162,18 +171,20 @@ def send_message(self, msg: str, dest_address: str = "FFFF") -> None: :param msg: messages :param dest_address: address """ + self.wait_till_device_is_ready() + print("{}: {}".format(dest_address, msg)) time.sleep(0.1) self.ser.write("AT+DEST={}\r\n".format(dest_address).encode()) time.sleep(0.1) self.ser.write("AT+SEND={}\r\n".format(len(msg)).encode()) time.sleep(0.1) self.ser.write("{}\r\n".format(msg).encode()) - time.sleep(2) def add_messages_to_queue(self, address: str, msg: str): self.message_queue.append(Message(address=address, msg=msg)) def send_rti(self): + self.wait_till_device_is_ready() print("send RTI: {}".format(datetime.datetime.now())) time.sleep(0.1) self.ser.write("AT+DEST=FFFF\r\n".encode()) @@ -185,6 +196,10 @@ def send_rti(self): # set time for next RTI broadcast self.next_rti_broadcast: float = time.time() + random.randint(30, 61) + def wait_till_device_is_ready(self): + while self.device_busy: + time.sleep(0.1) + def run(self): """ main threat to send RTI & messages """ while self.active: @@ -218,6 +233,5 @@ def run(self): message: Message = Message() message.from_string(message_queue[1].decode("utf-8")) self.lora_daemon.message_queue.append(message) - print(message.to_string()) except TypeError: continue