Explication de la routine Abonnement 14-mqtt_sub mqtt
import time
import network
from mqtt import MQTTClient
SSID = ""
KEY = ""
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print('Trying to connect to "{:s}"...'.format(SSID))
time.sleep_ms(1000)
print("WiFi Connected ", wlan.ifconfig())
client = MQTTClient("openmv", "test.mosquitto.org", port=1883)
client.connect()
def callback(topic, msg):
print(topic, msg)
client.set_callback(callback)
client.subscribe("openmv/test")
while True:
client.check_msg()
time.sleep_ms(1000)