micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

umqtt.simple not working: MQTTException: 2

Open jberes-ae opened this issue 3 years ago • 6 comments

I am trying to run a demo program for Digi Xbee cellular modem to publish and subscribe MQTT packets.

  • Error: File "/flash/lib/umqtt/simple.py", line 110, in connect
  • running mosquitto 2.0.13 on Windows 10
  • port 1883, so not authentication needed

Any insights to resolving would be greatly appreciated. Thank you.

umqtt error 2

mostquitt 2013 running

jberes-ae avatar Nov 19 '21 04:11 jberes-ae

same message MQTTException: 2

log from docker MQTT server eclipse-mosquitto(457fe4154880)

1639972746: New client connected from xxxx as mqtt-explorer-8c09a901 (p2, c1, k60).
1639972796: New connection from xxxx on port 1883.
1639972796: New client connected from xxxx as ESP8266Client1 (p2, c1, k0).
1639972796: Bad socket read/write on client ESP8266Client1: Invalid arguments provided.

rollback to 2.0.11 work fine

1639973149: New connection from xxxx on port 1883.
1639973149: New client connected from xxxx as ESP8266Client1 (p2, c1, k0).

chouex avatar Dec 20 '21 04:12 chouex

image

by compare another client, seems new version can not just set keep alive to 0 ~~so change msg = bytearray(b"\x04MQTT\x04\x02\0\0") to msg = bytearray(b"\x04MQTT\x04\x02\0\x3c") #60s keep alive~~ update: just set non-zero keepalive option to MQTTClient's constructor.

tested 2.0.12 and latest

chouex avatar Dec 20 '21 13:12 chouex

Hi there,

the issue you might be observing here has been reported and discussed at #445 and https://github.com/hiveeyes/terkin-datalogger/pull/97 already. In this context, please be aware of CVE-2020-13849, which is the main reason for this change in Mosquitto 2.0.12:

- Fix `max_keepalive` not applying to MQTT v3.1.1 and v3.1 connections.
  These clients are now rejected if their keepalive value exceeds
  max_keepalive. This option allows CVE-2020-13849, which is for the MQTT
  v3.1.1 protocol itself rather than an implementation, to be addressed.

Now, Mosquitto 2.0.13 adds the possibility for max_keepalive to be set to 0 with https://github.com/eclipse/mosquitto/commit/d942ed7ee, if you really need it.

With kind regards, Andreas.

amotl avatar Dec 20 '21 14:12 amotl

Dear @chouex,

so change msg = bytearray(b"\x04MQTT\x04\x02\0\0") to msg = bytearray(b"\x04MQTT\x04\x02\0\x3c") #60s keep alive

There is no need to manipulate this on a binary/bytes level. There is already the keepalive option as a parameter to MQTTClient's constructor. You can easily pass a custom value from your application code, or adjust the default value of the library like https://github.com/daq-tools/pycopy-lib/commit/fe68f4186.

With kind regards, Andreas.

amotl avatar Dec 20 '21 14:12 amotl

Dear @amotl,

World you consider set keepalive value deafault to non-zero? I beleive many people like me just want to try the example and run into issue immediately. It is better if default setting work.

chouex avatar Dec 20 '21 14:12 chouex

As I see on screenshot from @jberes-ae - your mosquito running in local mode, it listen only on localhost. You need to add listener 1883 0.0.0.0 into your mosquitto.conf

oooeeee avatar Feb 17 '22 21:02 oooeeee