代码拉取完成,页面将自动刷新
同步操作将从 Walkline/MicroPython with Aligenie Voice Skill 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"""
The MIT License (MIT)
Copyright © 2020 Walkline Wang (https://walkline.wang)
https://gitee.com/walkline/MicroPython-with-Aligenie-Voice-Skill
"""
import gc
import ntptime
from utime import sleep_ms
from machine import Pin, Timer
from config import Config
from utils.wifihandler import WifiHandler
def hard_reset():
from machine import reset
reset()
def blink():
led = Pin(2, Pin.OUT, value=0)
for count in range(20):
led.value(not led.value())
sleep_ms(200)
def sync_ntp():
ntptime.NTP_DELTA = 3155644800
ntptime.host = "ntp1.aliyun.com"
ntptime.settime()
def connect_to_wifi():
WifiHandler.set_ap_status(False)
sleep_ms(1000)
result_code = WifiHandler.set_sta_mode(Config.WIFI_SSID, Config.WIFI_PASSWORD)
return result_code
def check_internet_cb(timer):
if not WifiHandler.get_sta_status() or not WifiHandler.check_internet_connection():
print("Wifi disconnected or lost internet connection, restarting now...")
hard_reset()
gc.collect()
if __name__ == "__main__":
if WifiHandler.STATION_CONNECTED == connect_to_wifi():
if WifiHandler.check_internet_connection():
sync_ntp()
Pin(2, Pin.OUT, value=1)
check_internet_timer = Timer(1)
check_internet_timer.init(
mode=Timer.PERIODIC,
period=(Config.MQTT_KEEPALIVE - 5) * 1000,
callback=check_internet_cb
)
print("Timer started, periodic {} seconds".format(Config.MQTT_KEEPALIVE))
gc.collect()
else:
print("Connected to wifi, but no internet connection, restarting now...")
blink()
sleep_ms(1000)
hard_reset()
else:
print("Cannot connect to specified wifi, restarting now...")
blink()
sleep_ms(1000)
hard_reset()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。