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 ...
MQTT: c.connect() -> IndexError: bytes index out of range
Re: MQTT: c.connect() -> IndexError: bytes index out of range
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
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?
--> Hence the micropython version should be 1.8.5 ... shouldn't it?
Re: MQTT: c.connect() -> IndexError: bytes index out of range
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
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
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MQTT: c.connect() -> IndexError: bytes index out of range
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
Index to my micropython libraries.
Index to my micropython libraries.
Re: MQTT: c.connect() -> IndexError: bytes index out of range
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. [/url].
of course, in my desperate attempts to find a solution on the www, I have read through this more than once alreadypythoncoder 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.
Re: MQTT: c.connect() -> IndexError: bytes index out of range
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.
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.