Skip to content
This repository has been archived by the owner on Mar 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from linuxluigi/feature/presentation
Browse files Browse the repository at this point in the history
Feature/presentation
  • Loading branch information
linuxluigi authored Jun 26, 2019
2 parents 9b13b27 + 82115ca commit 40c1c5a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
4 changes: 2 additions & 2 deletions docs/Quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
Binary file added docs/_static/Presentation.odp
Binary file not shown.
20 changes: 17 additions & 3 deletions pylorawebchat/chat/lora_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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())
Expand All @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 40c1c5a

Please sign in to comment.