Files
Smartwave/tests/mqtt/micropython_example.py
Ninluc 5c60017e8d
Build, push image, and notify Watchtower / build-image (push) Successful in 3m32s
Build, push image, and notify Watchtower / notify (push) Successful in 13s
Wait, is this peak ?
2026-08-04 18:21:20 +02:00

40 lines
744 B
Python

"""Small MicroPython MQTT example for ESP32.
Edit BROKER_HOST so it points to the broker machine IP address.
Do not use localhost from the ESP32.
"""
import shared
BROKER_HOST = "192.168.50.1"
TOPIC = b"smartwave/demo"
CA_FILE = "/certs/ca.crt"
def on_message(message):
print("received:", message)
def main():
client = shared.get_mqtt_client(
host=BROKER_HOST,
client_id="smartwave-esp32-demo",
use_tls=True,
cafile=CA_FILE,
keepalive=30,
)
client.set_callback(on_message)
client.connect()
client.subscribe(TOPIC, qos=2)
client.publish(TOPIC, b"hello from MicroPython", qos=1, retain=False)
for _ in range(30):
client.poll()
client.close()
main()