Ejemplo n.º 1
0
def connectWifi(SSID, PASSWORD):
    print("Connecting to Wi-Fi router...")
    
    for i in range(0,5):
    try:
        wifi.link(SSID,wifi.WIFI_WPA2,PASSWORD)
        break
    except Exception as e:
        print("Error: ", e)
    else:
        print("Cannot connect.")
        while True:
            sleep(1000)
            


def on_switch():
    digitalWrite(D5,LOW)
    print("ON")

def off_switch():
    digitalWrite(D5,HIGH)
    print("OFF")
    




# Intialize APP
pinMode(RELAY_PIN, OUTPUT)
wifi_driver.auto_init()
connectWifi(SSID,PASSWORD)
info = wifi.link_info()
print("Connected to WiFI IP:",info[0])

zapp = zerynthapp.ZerynthApp(UID, TOKEN, log=True)
zapp.on("on_switch", on_switch)
zapp.on("off_switch",off_switch)
zapp.run()

while True:
    try:
        sleep(1000)
    except Exception as e:
        print("Error: ",e)
Ejemplo n.º 2
0
# Create a device instance by passing the device UID and TOKEN (copy and paste from the ADM panel)
# enable logging to debug
z = zadm.Device("DEVICE-UID-HERE",
                "DEVICE-TOKEN-HERE",
                log=False,
                fota_callback=fota_callback)

try:
    # Get information about the currently running configuration
    # Check documentation here: https://docs.zerynth.com/latest/official/core.zerynth.stdlib/docs/official_core.zerynth.stdlib_fota.html
    rec = fota.get_record()
    bcslot = rec[4]
    valid_runtime = rec[0]

    # connect to the wifi network (Set your SSID and password below)
    wifi_driver.auto_init()
    for i in range(0, 5):
        try:
            wifi.link("SSID", wifi.WIFI_WPA2, "password")
            break
        except Exception as e:
            print("Can't link!", e)
    else:
        print("Impossible to link!")
        while True:
            sleep(1000)

    # Start the device instance!
    # It immediately returns while a background thread keeps trying to connect and receive messages
    z.start()