-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
61 lines (49 loc) · 1.86 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
# main.py
import machine, utime
import sys
import urequests
import json
import network
import micropython
import ure # For regular expressions
# Number used for differentiating between the different physical trackers
trackerID = 0
# Regular expression for parsing GPRMC formatted GPS data
gprmcREG = "\$GPRMC,[0-9][0-9][0-9][0-9][0-9][0-9],(A|V),[0-9]+\.[0-9]+,(N|E|S|W),[0-9]+\.[0-9]+,(N|E|S|W),[0-9]+\.[0-9]+,[0-9]+\.[0-9]+,[0-9]+,[0-9]+\.[0-9],[A-Z]\*[0-9][A-Z]"
# `gprmcREG` = the regex object returned by compiling the above regular expression
gprmcREG = ure.compile(gprmcREG)
led = machine.Pin(2, machine.Pin.OUT)
dataBaseURL = "https://bloombus-163620.firebaseio.com/Tracker/.json"
nic = network.WLAN(network.STA_IF)
nic.active(True)
nic.connect('bloomu')
led.on()
if nic.isconnected():
led.off()
def main():
micropython.kbd_intr(-1)
machine.UART(0, 9600).init(9600) # 9600 baud rate recommended by LoLin NodeMcu board
for line in sys.stdin:
raw=line
if not nic.isconnected():
led.on()
if not network.STAT_CONNECTING:
nic.connect('bloomu')
else:
led.off()
if gprmcREG.match(raw):
raw=raw.split(',')
raw.pop(0)
dateTime=raw[8]+raw[0]
dateTime=dateTime.replace('.','')
locData = {
"lat": raw[2] + raw[3],
"long": raw[4] + raw[5],
"speed":raw[6]
}
data={dateTime:locData}
urequests.patch(dataBaseURL, data=json.dumps(data), headers = {"content-type":"application/json"})
data={dateTime:raw}
urequests.patch("https://bloombus-163620.firebaseio.com/rawLog/.json",data=json.dumps(data),headers={"content-type":"application/json"})
if __name__ == "__main__":
main()