Zoran Roncevic
Published © GPL3+

Test AllThingsTalk & Zerynth & NodeESP32

Testing module written on Zerynth Studio for ESP32. AllThingsTalk Maker platform is used for receiving data through MQTT protocol.

AdvancedProtip30 minutes1,164
Test AllThingsTalk & Zerynth & NodeESP32

Things used in this project

Hardware components

ESP32S
Espressif ESP32S
×1

Software apps and online services

Zerynth Studio
Zerynth Studio
AllThingsTalk Maker
AllThingsTalk Maker

Story

Read more

Code

main.py

Python
Zerynth code
import streams
from mqtt import mqtt
from wireless import wifi

# import wifi support
from espressif.esp32net import esp32wifi as wifi_driver

streams.serial()
sleep(1000)
# init the wifi driver!
# The driver automatically registers itself to the wifi interface
# with the correct configuration for the selected device
wifi_driver.auto_init()
sleep(3000)

att_device_id = "<DeviceID>"
att_device_asset = "<DeviceAsset>"
att_device_token = "<DeviceToken>"


def send_sample(obj):
    print("publishing: ", obj)
    client.publish("device/"+att_device_id+"/asset/"+att_device_asset+"/state", "0|"+str(obj))
    
print("Establishing Link...")
try:
    wifi.link("<SSID>",wifi.WIFI_WPA2,"<PASSWORD>")
except Exception as e:
    print("ooops, something wrong while linking :(", e)
    while True:
        sleep(1000)

try:
    # set the mqtt id to "zerynth-mqtt"
    client = mqtt.Client("zerynth-mqtt",True)
    client.set_username_pw(att_device_token,"Zerynth")
    for retry in range(10):
        try:
            print(retry)
            client.connect("api.allthingstalk.io", 60)
            print("connected or not...") # no exception at this moment !
            break
        except Exception as e:
            print(e)
    print("connected.")
except Exception as e:
    print(e)
    
while True:
    sleep(3000)
    x = random(0,50)
    send_sample(x)
    
print("End of program")

Credits

Zoran Roncevic

Zoran Roncevic

19 projects • 128 followers
Hackster Live ambassador in Serbia. Organizer of Maker NS community.

Comments