Hi everybody
i am playing with Wio RP2040 board
I use this example : https://wiki.seeedstudio.com/Use_MQTT_to_remotely_light_up_LED_lights/
I can send msg via MQTT to mosquitto on a Raspberry Pi 400.
On the other way, when I send a message from mosquitto, it seems that the callback function is not called, so i can’t on/off the USER LED on the board.
Here is my test program
Programme test MQTT
import network
import mqtt
from machine import Pin, I2C, ADC, UART, SPI, PWM
from time import sleep
N1 = network.WLAN_SPI(network.STA_IF)
N1.active(True)
N1.connect(“Livebox-57A9”,“258xxxxxxxxxx279”)
“”“if N1.isconnected():
print(” ip gateway netmask MAC ssid")
print(N1.ifconfig())
“”"
print (“Connecté au Wi-Fi”)
print(N1.ifconfig()[0])
sleep(1)
led = Pin(13, Pin.OUT)
led.value(0)
SERVER = ‘192.168.1.31’
CLIENT_ID = ‘Wio RP2040_Dev_board’
TOPIC = ‘LED’
def mqtt_callback(topic) :
print(“Received !”)
print(‘topic: {}’.format(topic[0]))
print(‘msg:{}’.format(topic[1]))
if(topic[1] == “off”):
led.value(0)
if(topic[1] == “on”):
led.value(1)
cl = mqtt.MQTTClient(CLIENT_ID, SERVER, mqtt_port = 1883)
cl.connect()
cl.publish(“Wio_RP2040”,“Démarrage Wio”)
cl.subscribe(TOPIC)
cl.set_callback(mqtt_callback)
print(‘Connecté au broker MQTT %s, inscrit au topic %s’ % (SERVER, TOPIC))
print(‘ok’)
compteur = 0
while True:
compteur += 5
cl.wait_msg()
print (“Compteur :”, compteur)
cl.publish(“Wio_RP2040”, str(compteur))
sleep(1)
I verify twice the function name but when i send a message to the topic LED, i never see “Received !” in the shell windows in Thonny IDE.
Maybe somebody can telle me what i made wrong…
have a nice day
François