Micropython and MQTT Libs


#1

Looking for micropython implementation of the losant MQTT libs…
The current lib is not compatible and I am not having luck trying to use umqtt in its place…

thanks
Gavin


#2

Umm not sure I agree.

What platform are you using. In what way is it incompatible ? Are trying to use TLS ?

I have an ESP8266 which working with Losant at home not using TLS . (I prefer to use a local broker for this specific project so didn’t continue further with that path.)

At work I have pycoms (8) on mechanical pumps talking to Losant over LTE-Cat M1 direct. I did want to use TLS so am using the guts of the Pycom AWS library (to get the TLS support)


#3

I snagged an xbee cat1 cellular modem and have it on verizon’s plan for iot… the support micro python right on the device…


#4

Hi Gavin

You would need to post some detail as to what is not working, error etc. And as I asked are you trying to use TLS ?

Then I might be able to help

T


#5

Not using TLS… looks like the umqtt module is having trouble with the length of the password?

File "/flash/lib/umqtt/simple.py", line 97, in connect
IndexError: bytes index out of range

and I see it connect to the broker but it kicks back an index error


#6

so I went another way and found a trimmed down lib for losant for micropython

MP Lib

I am not a strong python programmer and am having troubles getting it to execute a connect the the broker… any direction would be great


#7

Hi

Can you post the simplest example of your code ?

T


#8

Hello Gavin,

I downloaded the library that you mentioned above: micropython and losant example. I was able to successfully connect to my device (pycom GPy) with the Losant Platform using SSL. The updates I made are shown below.

I downloaded the SSL certificate from the Losant Python MQTT library from here and put it in the /flash/cert/ directory that I created. This certificate is not needed but recommended. If you choose to not use it, then remove “ca_certs’:’/flash/cert/RootCA.crt’,” from the call to the MQTTClient constructor shown in the screenshot above.

Here are the values that were added to the call to the MQTTClient constructor in losant_mqtt.py:

  • 60 - this is the keep-alive value in seconds and set to keep the connection with the Losant MQTT broker open
  • True - specifies to use SSL
  • SSL parameters to properly connect to the Losant MQTT broker

The last change I made was setting the port to 0 as shown in the screenshot. With this value at 0 and True specified in the MQTTClient constructor above to use SSL, the umqtt-simple library will set the correct port number.

Hope this helps!
Kevin