IndexError: bytes index out of range
When I run the code simple.py on a Pi Pico.
I was getting "IndexError: bytes index out of range" after the internet was connected, but the MQTT broker connection failed.
From line 112 of simple.py: assert resp[0] == 0x20 and resp[1] == 0x02
It was saying "in connect" but afterward, it is giving me IndexError: bytes index out of range. Has anyone had this issue before?
What I have to do is unplug the USB and plug it back in multiple times to make it work.
MQTT: c.connect() -> IndexError: bytes index out of range
On a raspian (IP=10.0.0.32) I installed mosquitto:
service mosquitto status
gives me: [ ok ] mosquitto is running.
An ESP8266 is in the same network:
FW: esp8266-20161017-v1.8.5.bin
'>>> sta_if.ifconfig()
gives me: ('10.0.0.105', ...)
On the raspian-terminal I can also ping my ESP8266:
ping 10.0.0.105
gives me: 64 bytes from 10.0.0.105: icmp_req=1 ttl=255 time=2.62 ms ...
But I am failing to connect with the MQTT:
'>>> from umqtt.simple import MQTTClient
'>>> c = MQTTClient("client", "10.0.0.32")
'>>> c.connect()
gives me:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "umqtt/simple.py", line 84, in connect
IndexError: bytes index out of range
Likely, in that case, the
respobject is shorter than the two bytes.The library is simple, it does not handle all possible error, so you may need to wrap it in additional error handling,
also to deal with external glitches in networks , DNS and other interferences.