MQTT: c.connect() -> IndexError: bytes index out of range

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
BigMan
Posts: 22
Joined: Sat Oct 29, 2016 2:29 pm

MQTT: c.connect() -> IndexError: bytes index out of range

Post by BigMan » Sat Oct 29, 2016 2:48 pm

Hi,
My setting:

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:
>>> 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


I have no glue what I am doing wrong here ...

danielm
Posts: 167
Joined: Mon Oct 05, 2015 12:24 pm

Re: MQTT: c.connect() -> IndexError: bytes index out of range

Post by danielm » Sat Oct 29, 2016 5:41 pm

I experience something similar on CC3200 port when trying with MP version older than 1.8.x.

BigMan
Posts: 22
Joined: Sat Oct 29, 2016 2:29 pm

Re: MQTT: c.connect() -> IndexError: bytes index out of range

Post by BigMan » Sat Oct 29, 2016 8:16 pm

well ... I flashed the ESP8266 with following firmeware: esp8266-20161017-v1.8.5.bin
--> Hence the micropython version should be 1.8.5 ... shouldn't it?

danielm
Posts: 167
Joined: Mon Oct 05, 2015 12:24 pm

Re: MQTT: c.connect() -> IndexError: bytes index out of range

Post by danielm » Sun Oct 30, 2016 7:22 am

I also think so, but I never used MP on esp.
Maybe you could create an issue on GitHub. Please try to search through existing issues first, there are several related to MQTT client.
https://github.com/micropython/micropython/issues

User avatar
pythoncoder
Posts: 4665
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: MQTT: c.connect() -> IndexError: bytes index out of range

Post by pythoncoder » Sun Oct 30, 2016 7:38 am

Issues with MQTT should be raised against micropython-lib, so look there too. For general informtion on MQTT and useful URL's (alas no fix for your problem) see http://forum.micropython.org/viewtopic. ... FAQ#p12694.
Peter Hinch

BigMan
Posts: 22
Joined: Sat Oct 29, 2016 2:29 pm

Re: MQTT: c.connect() -> IndexError: bytes index out of range

Post by BigMan » Sun Oct 30, 2016 7:48 am

pythoncoder wrote:Issues with MQTT should be raised against micropython-lib, so look there too. [/url].
hmmm ... I cannot follow you (maybe because I am not a native english speaker, and new to Python). "Raised against micropython-lib" -> where exactly should I look for what?
pythoncoder wrote:Issues with MQTT should be raised against micropython-lib, so look there too. For general informtion on MQTT and useful URL's (alas no fix for your problem) see http://forum.micropython.org/viewtopic. ... FAQ#p12694.
of course, in my desperate attempts to find a solution on the www, I have read through this more than once already :-)


mws
Posts: 3
Joined: Mon Nov 14, 2016 7:13 pm

Re: MQTT: c.connect() -> IndexError: bytes index out of range

Post by mws » Tue Nov 29, 2016 4:22 pm

At the beginning I had exactly the same error, but I cannot remember what really solved it.

My current implementation speaks to "hbmqtt" and no more to mosquitto (might be one factor 3.1 vs. 3.1.1 mqtt, had some problems with mosquitto with different clients that I do not have with hbmqtt (+ the second one was easy to install on my synology)). And I explicitly pass bytes to the MQTTClient (b') (don't know if this even makes a difference in micropython):

import time
from umqtt.simple import MQTTClient
client = MQTTClient(b'esp8266_greenhouse', b'192.168.2.232')
client.connect()
client.publish(b'/greenhouse', data, retain=True)
time.sleep(0.2)
client.disconnect()

Had this code running (in a function with try/pass) for a few days for datalogging with a publish every few seconds and it ran without any problems.

Post Reply