-
Notifications
You must be signed in to change notification settings - Fork 0
/
gs.py
50 lines (41 loc) · 1.14 KB
/
gs.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
44
45
46
47
48
49
50
from datetime import datetime
import serial
# Configure the serial connections
ser = serial.Serial(
port='/dev/ttyS3',
baudrate=57600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.isOpen()
def send(command):
dt = datetime.now().strftime("%H:%M:%S")
print('[' + dt + "] ~" + command)
ser.write(("~" + command + "\r\n").encode())
send("F434.225")
send("M0")
send("D")
send("V")
out=""
while 1 :
while ser.inWaiting() > 0:
char = ser.read(1)
try:
char = char.decode() # .decode("utf-8")
except:
#print(char)
continue
if char == '\n':
dt = datetime.now().strftime("%H:%M:%S")
# print('[' + dt + '] LoRaGo - ' + out)
fields = out.split('=', 2)
if len(fields) == 2:
if fields[0] == 'CurrentRSSI':
#send("Ttest")
pass
else:
print('[' + dt + '] LoRaGo - ' + out)
out = ""
else:
out += char