mirror of
https://github.com/sascha-hemi/pycom-documentation.git
synced 2026-03-21 04:06:11 +01:00
pygate: say hello and wait for ntp
This commit is contained in:
@@ -56,6 +56,7 @@ import machine
|
||||
from machine import RTC
|
||||
import pycom
|
||||
|
||||
print('\nStarting LoRaWAN concentrator')
|
||||
# Disable Hearbeat
|
||||
pycom.heartbeat(False)
|
||||
|
||||
@@ -75,19 +76,26 @@ def machine_cb (arg):
|
||||
# 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='<SSID>', auth=(WLAN.WPA2, "<PASSWORD>"))
|
||||
|
||||
while not wlan.isconnected():
|
||||
print('.', end='')
|
||||
time.sleep(1)
|
||||
|
||||
print("Wifi Connection established")
|
||||
print(" OK")
|
||||
|
||||
# Sync time via NTP server for GW timestamps on Events
|
||||
print('Syncing RTC via ntp...', end='')
|
||||
rtc = RTC()
|
||||
rtc.ntp_sync(server="0.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.json','r')
|
||||
buf = fp.read()
|
||||
|
||||
Reference in New Issue
Block a user