-
Notifications
You must be signed in to change notification settings - Fork 1
/
receiver.py
43 lines (35 loc) · 1.43 KB
/
receiver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
import subprocess
from sx126x import sx126x
import time
import datetime
# Create sx126x node
node = sx126x(serial_num = "/dev/ttyS0",freq=915,addr=1,power=22,rssi=True,air_speed=2400,relay=False)
try:
time.sleep(1)
print(" ┓ ┳┓ ┏┓• ┏┓┏┓\n\
┃ ┏┓┣┫┏┓┃┃┓ ┃ ┏┛\n\
┗┛┗┛┛┗┗┻┣┛┗ ┗┛┗━\n\
-----------------\n\
Receiver Node\n")
while True:
log = open("/home/pi/LoRaPi-C2/receiver_node.log", "a")
clock = datetime.datetime.now()
incoming_data = node.receive()
if incoming_data:
command = incoming_data.decode().split(',')
print(f" {clock} Command Received: {command} @ -{node.get_rssi()} dBm\n")
log.write(f"{clock} Command Received: {command} @ -{node.get_rssi()} dBm\n")
try:
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
print("Command output:\n", output.decode())
log.write("Command output:\n" + output.decode())
except subprocess.CalledProcessError as e:
print("Error executing command:", e.output.decode())
log.write("Error executing command:", e.output.decode())
time.sleep(1)
log.close()
except KeyboardInterrupt:
node.close()
log.close()
exit()