Page 1 of 1

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

Posted: Sat Oct 29, 2016 2:48 pm
by BigMan
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 ...

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

Posted: Sat Oct 29, 2016 5:41 pm
by danielm
I experience something similar on CC3200 port when trying with MP version older than 1.8.x.

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

Posted: Sat Oct 29, 2016 8:16 pm
by BigMan
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?

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

Posted: Sun Oct 30, 2016 7:22 am
by danielm
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

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

Posted: Sun Oct 30, 2016 7:38 am
by pythoncoder
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.

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

Posted: Sun Oct 30, 2016 7:48 am
by BigMan
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 :-)

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

Posted: Sun Oct 30, 2016 9:47 am
by danielm

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

Posted: Tue Nov 29, 2016 4:22 pm
by mws
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.