Replies: 3 comments 5 replies
-
Please enclose the code in lines consisting of three backticks ``` |
Beta Was this translation helpful? Give feedback.
-
I don't know why, but the code below works. I tried changing my code to make it look the same, but my code still didn't work xD Source: https://github.com/avseng/MQTT-RPI-ESP8266 Code: from umqtt.simple2 import MQTTClient
import network
from machine import Pin
from time import sleep
MQTT_SERVER = "broker.hivemq.com"
CLIENT_ID = ""
MQTT_TOPIC = b""
MQTT_PASS = ""
MQTT_SSID = ""
WIFI_SSID = ""
WIFI_PASSWORD = ""
#led = Pin(2, Pin.OUT)
# WiFi connectivity function.
def connectWIFI():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID,WIFI_PASSWORD)
while not wlan.isconnected():
pass
print ("wifi connected")
print(wlan.ifconfig())
#MQTT callback service function
def sub_cb(topic, msg,r,t):
print(topic, msg)
try:
#led.value(1)
connectWIFI()
c = MQTTClient(CLIENT_ID,MQTT_SERVER,1883,MQTT_SSID,MQTT_PASS)
c.set_callback(sub_cb)
c.connect()
c.subscribe(MQTT_TOPIC)
print("MQTT connected and ready to receive message")
while True:
c.wait_msg()
finally:
c.disconnect() |
Beta Was this translation helpful? Give feedback.
-
@nastiliano Describing that as the latest version is incorrect. It is not a bugfix release, rather it is a user written library and is not officially supported. The current officially supported code is here. @Piootre The fault is occurring here indicating that the broker is returning an invalid response. I would check whether you have achieved a connection by doing a publication and testing that it can be received (e.g. by using |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a problem with the check_msg() function in umqtt.simple.
I don't know why I'm getting an error with this function. Below is the code and error text.
Thank you very much for your tips. (I use esp8266)
code:
Answer:
Beta Was this translation helpful? Give feedback.
All reactions