Instantly share code, notes, and snippets.

Embed
What would you like to do?
import streams
from mqtt import mqtt
from wireless import wifi
from espressif.esp32net import esp32wifi as wifi_driver
wifi_driver.auto_init()
sleep(1000)
streams.serial()
print("Establishing WiFi Link...")
try:
wifi.link("<ENTER SSID>", wifi.WIFI_WPA2,"<WIFI PASS>")
print("Connected to WiFi")
except Exception as e:
print("ooops, something wrong while linking :(", e)
while True:
sleep(1000)
def send_sample(obj):
print("publishing: ", obj)
client.publish("temp/random", str(obj))
try:
print("connecting...")
client = mqtt.Client("zerynth-mqtt",True)
for retry in range(10):
try:
client.connect("37.187.106.16", 8883)
break
except Exception as e:
print(e)
print("connected.")
# publish a random value every three seconds
while True:
sleep(3000)
x = random(0,50)
send_sample(x)
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment