Esempio n. 1
0
def connect_wifi(ssid, pwd):
    global disp
    # 初始化网络
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(ssid, pwd)
    while True:
        print('wifi is connecting...')
        disp.text(20, 30, 'wifi is connecting...', disp.RED)
        if (wlan.isconnected() == True):
            print('wifi is connected')
            disp.textClear(20, 30, 'wifi is connecting...')
            disp.text(20, 30, 'wifi is connected', disp.RED)
            ip = wlan.ifconfig()[0]
            print('IP: %s' % ip)
            disp.text(20, 50, ip, disp.RED)
            # NTP时间更新,如果更新不成功,将不能进行识别
            print('NTP start')
            disp.text(20, 70, 'NTP start...', disp.RED)
            sntp.setTime('UTC')
            print('NTP done')
            disp.textClear(20, 70, 'sntp start...')
            disp.text(20, 70, 'NTP done', disp.RED)
            break
        utime.sleep_ms(500)
    utime.sleep(2)
Esempio n. 2
0
    # 等待设备成功连接到物联网平台
    while(True):
        if iot_connected:
            print('物联网平台连接成功')
            break
        else:
            print('sleep for 1 s')
            utime.sleep(1)
    print('sleep for 2s')
    utime.sleep(2)

if __name__ == '__main__':

    get_wifi_status()

    sntp.setTime('CST-8', 'cn.pool.ntp.org')

    connect_lk(productKey, deviceName, deviceSecret)

    frame = 0

    while True:

        frame += 1

        if screenMode == 0:
            # 0 - 关闭
            screen.fill(0)
            screen.show()
            utime.sleep(1)