Example #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)
Example #2
0
pinMode(light_test_pin, OUTPUT)
digitalWrite(light_test_pin, LOW)
pinMode(photoresistor, INPUT_ANALOG)
onPinFall(btn_pin, button_press) #quando BTN0 viene premuto tutto viene spento
    
try:
    sleep(5000)
    print('Initialize wifi')
    spwf01sa.init(SERIAL2, wifi_reset_pin)
    sleep(3000)
    
    print('Connecting...')
    wifi.link('Vodafone2.4GHz-33915375', wifi.WIFI_WPA2, 'Rosato65wifi95')
    print('Connected to wifi')
    sleep(1000)
    zapp = zerynthapp.ZerynthApp(uid, token)
    print('zapp object created!')
    #############################################
    #Associate the method calls to Python funcs
    zapp.on('set_desired_temp', set_desired_temp) #gestione della temperatura desiderata
    zapp.on('heating_switch', heating_switch)       #gestione on/off riscaldamento
    zapp.on('water_switch', water_switch)           #gestion on/off acqua
    zapp.on('light_switch', light_switch)           #gestion on/off luce
    zapp.on('set_delay', set_delay)                 #gestion on/off "doccia automatica"
    zapp.on('set_state', set_state)                 #var bool che tiene traccia dell'effettivo on/off del sistema automatico 
    zapp.on('get_initial_state', get_initial_state) #invia lo stato iniziale di tutte le variabili
    
    print('Start the app instance...')
    zapp.run()
    print('Instance started.')
    sleep(3000)
Example #3
0

# define a RPC function: generate a random number
def do_random(a, b):
    return random(a, b)


# send events on button pressed
def on_btn():
    zapp.event({"my_button": "pressed"})


onPinFall(BTN0, on_btn, debounce=1000)

# Device UID and TOKEN can be created in the ADM panel
zapp = zerynthapp.ZerynthApp("DEVICE UID HERE", "DEVICE TOKEN HERE", log=True)

# link "random" to do_random
zapp.on("random", do_random)

try:
    # connect to the wifi network (Set your SSID and password below)
    wifi_driver.auto_init()
    for i in range(0, 5):
        try:
            wifi.link("NETWORK SSID", wifi.WIFI_WPA2, "NETWORK PASSWORD")
            break
        except Exception as e:
            print("Can't link", e)
    else:
        print("Impossible to link!")
Example #4
0
#Read gyroscope values from MPU6050 and return an array containing x, y and z values on indexes 0, 1 and 2. need an initialized i2c port for communication with device
def mpu6050GetGyroValues(initializedI2CPort):
    x = initializedI2CPort.write_read(0x43, 2)
    y = initializedI2CPort.write_read(0x45, 2)
    z = initializedI2CPort.write_read(0x47, 2)
    return [buildVal(x[0], x[1]), buildVal(y[0], y[1]), buildVal(z[0], z[1])]


sleep(1000)
print("STARTING...")

#Main Function
try:
    # Device UID and TOKEN can be created in the ADM panel
    zapp = zerynthapp.ZerynthApp("p4ZSd_21TIyMjpQE3E5P9g",
                                 "QP1MfuJzS6qhh40QI59AMQ",
                                 log=True)
    # Start the Zerynth app instance!
    zapp.run()
    #connection wifi/mosquito
    wifi_connect()
    #create instance for MQTT connection
    client = mqtt.Client(MQTT_CLIENTID, True)
    # and try to connect to "test.mosquitto.org"
    for retry in range(5):
        try:
            client.connect("broker.mqtt-dashboard.com",
                           60,
                           aconnect_cb=print_connectOK)
            break
        except Exception as e:
for i in range(0, 5):
    try:
        # connect to the wifi network (Set your SSID and password below)
        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)

try:
    # Device UID and TOKEN can be created in the ADM panel
    zapp = zerynthapp.ZerynthApp("DEVICE UID", "DEVICE TOKEN", log=True)
except Exception as e:
    print(e)

# Start the Zerynth app instance!
# Remember to create a template with the files under the "template" folder you just cloned
# upload it to the ADM and associate it with the connected device
zapp.run()


def set_led(pin, status):

    if status == "ON":
        digitalWrite(LED[pin], HIGH)
    elif status == "OFF":
        digitalWrite(LED[pin], LOW)
Example #6
0
    running_message = message
    running_message = clean_message(running_message)

def enable_sound(flipswitch_status):
    global sound_enabled
    if flipswitch_status == 'on':
        sound_enabled = 1
        print(flipswitch_status)
        print(sound_enabled)
    elif flipswitch_status == 'off':
        sound_enabled = 0
        print(flipswitch_status)
        print(sound_enabled)

# configure the zerynth app with a name, a descripton and the template url
zp = zerynthapp.ZerynthApp("Stranger Blinks","Messages from the Upside Down","resource://template.html")

# everytime Javascript generates the event "change_message" the function change_message is called
zp.on("change_message",change_message)

# everytime Javascript generates the event "enable_sound" the function enable_sound is called
zp.on("enable_sound", enable_sound)

# run the ZerynthApp!
zp.run()

# since zp.run starts a new thread, you can do whatever else you want down here!

# define the threads that allow to blink the message and play the sound
thread(play_sound)
thread(blink_message)
Example #7
0
# :: Javascript to Python ::
# the following functions will be called when buttons are pressed
def change_color(r, g, b):
    animation.setup_color(r, g, b)


def change_animation(n):
    animation.setup_anim(n)


def change_speed(n):
    animation.setup_anim_speed(n)


# configure the Zerynth app with a name, a descripton and the template url
vp = zerynthapp.ZerynthApp("Zerynth Lamp", "Try me!",
                           "resource://template.html")

# everytime Javascript generates events the corresponding functions are called
vp.on("change_color", change_color)
vp.on("change_animation", change_animation)
vp.on("change_speed", change_speed)

# run the ZerynthApp!
vp.run()

# since vp.run starts a new thread, you can do whatever else you want down here!
# let's control leds

animation.start(D6, 24)
                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)