fizista / micropython-umqtt.simple2

MIT License
76 stars 36 forks source link

Second subscription gives exception 5 in simple2 #8

Closed hjgode closed 3 years ago

hjgode commented 3 years ago

I have following code on a m5stack Core2.

t='mqttGenericBridge/#' # can only subscribe to one topic tree and only one MQTTClient allowed? t2='cmnd/#' c=_MQTTClient('m5core2','192.168.0.40',1883,'','',300) c.connect() c.set_callback(fun_mqtt_callback) c.set_callback_status(fun_mqtt_status_callback)

pid1=c.subscribe(topic=t,qos=1) pid2=c.subscribe(topic=t2,qos=1) ... def updateThread(): global c, bThreadsRun while bThreadsRun: time.sleep_ms(500) c.wait_msg() #blocking call
_thread.start_new_thread(updateThread, ())

As soon as a publish of second topic is received, there is an error in line c.wait_msg() for ' if pid in self.rcv_pids:' and raises a MQTTException(5) inside def check_msg(self):... As long as only published topics with first topic are received, there is no error.

        if pid in self.rcv_pids:
            self.last_cpacket = ticks_ms()
            self.rcv_pids.pop(pid)
            self.cbstat(pid, 1)
        else:
            raise MQTTException(5)

I worked around this using your robust2 MQTTClient.

I a second subscription not supported with simple2?

fizista commented 3 years ago

When using simple2, you have to handle communication errors yourself.

It is difficult for me, based on the information provided, to say why this problem occurs.

The library was tested with mosquitto's mqtt server. For this server, communication was problem-free and multiple topics could be subscribed to. Check with this server to see if communication is correct.

hjgode commented 3 years ago

I am using mosquitto server.

For me the error seems to be that simple2 is looking for the pid in the received packet and does not find the pid in the list of rcvd pids.

Anyway, I am fine in using robust2.

On Thu, Aug 19, 2021 at 8:33 AM Wojciech Banaś @.***> wrote:

When using simple2, you have to handle communication errors yourself.

It is difficult for me, based on the information provided, to say why this problem occurs.

The library was tested with mosquitto's mqtt server. For this server, communication was problem-free and multiple topics could be subscribed to. Check with this server to see if communication is correct.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fizista/micropython-umqtt.simple2/issues/8#issuecomment-901648020, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZVWBJCJ6IJF5FQUYNYK63T5SQSLANCNFSM5CMJDXSA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .