-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (46 loc) · 1.4 KB
/
main.py
File metadata and controls
56 lines (46 loc) · 1.4 KB
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
from network import WLAN
import time
import machine
from machine import RTC
import pycom
print('\nStarting LoRaWAN concentrator')
# Disable Hearbeat
pycom.heartbeat(False)
# Define callback function for Pygate events
def machine_cb (arg):
evt = machine.events()
if (evt & machine.PYGATE_START_EVT):
# Green
pycom.rgbled(0x103300)
elif (evt & machine.PYGATE_ERROR_EVT):
# Red
pycom.rgbled(0x331000)
elif (evt & machine.PYGATE_STOP_EVT):
# RGB off
pycom.rgbled(0x000000)
# register callback function
machine.callback(trigger = (machine.PYGATE_START_EVT | machine.PYGATE_STOP_EVT | machine.PYGATE_ERROR_EVT), handler=machine_cb)
print('Connecting to WiFi...', end='')
# Connect to a Wifi Network
wlan = WLAN(mode=WLAN.STA)
wlan.connect(ssid='<ENTER SSID>', auth=(WLAN.WPA2, "< Enter Password>"))
while not wlan.isconnected():
print('.', end='')
time.sleep(1)
print(" OK")
# Sync time via NTP server for GW timestamps on Events
print('Syncing RTC via ntp...', end='')
rtc = RTC()
rtc.ntp_sync(server="au.pool.ntp.org")
while not rtc.synced():
print('.', end='')
time.sleep(.5)
print(" OK\n")
# Read the GW config file from Filesystem
# fp = open('/flash/config_new.json','r') old version
fp = open('/flash/config_new.json','r')
buf = fp.read()
# Start the Pygate
machine.pygate_init(buf)
# disable degub messages
machine.pygate_debug_level(1)