forked from psedge/microalert
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ser.py
43 lines (36 loc) · 1.21 KB
/
ser.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
import serial
import requests
import json
import random
def getCoords():
return [str(random.uniform(-25, 20)), str(random.uniform(120, 145))]
coords = {
'a': [str(random.uniform(-25, 20)), str(random.uniform(130, 135))],
'b': [str(random.uniform(-25, 20)), str(random.uniform(130, 135))],
'c': [str(random.uniform(-25, 20)), str(random.uniform(130, 135))],
'd': [str(random.uniform(-25, 20)), str(random.uniform(130, 135))],
}
while True:
try:
ser = serial.Serial("/dev/ttyACM0", 115200, timeout=2)
ser.flushInput()
ser.flushOutput()
data = ser.readline()
if data is not b'':
data = data.decode("UTF-8")
print(data)
id = data[0]
message = data[3]
body = json.dumps({
'type': message,
'lat': getCoords()[0],
'long': getCoords()[1],
'time': 154345345235,
'origin': id,
'temp': data[4:]
})
res = requests.post("https://m9po41o830.execute-api.eu-west-1.amazonaws.com/dev/event", data=body)
print(res)
except Exception as e:
print(str(e))
pass