paho-mqtt for MicroPython

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.
pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: paho-mqtt for MicroPython

Post by pfalcon » Thu Oct 22, 2015 5:25 pm

kfricke wrote:
Question: Is this correct, or does some of the major platforms not support non-blocking-/async-IO on the network socket?
That's rather peculiarly formulated question - what "major platforms" do you mean? ;-)
  1. STM HAL
  2. CC3200
  3. Unix (and Android)
  4. ESP8266
  5. PIC 16-Bit
I still don't see an issue. Unix port of course supports non-blocking I/O for example. MicroPython internal APIs also support non-blocking mode, and it's simply up to the ports to use it. As not many people used it so far, fixes are still made, e.g.: https://github.com/micropython/micropyt ... fbf1efecca

And socket (and in general, file/stream) non-blocking API is pretty easy: if it's not possible to read/write, return with EAGAIN error on lower level, which will translate to returning None with higher-level stream functions (.read()/.write()).

There's however another part to support async I/O - being able to wait on file-like objects/streams for data available and other events. I may imagine that part is much less consistent. For example, micropython-lib provides Linux-specific, the most efficient epoll() support, while stmhal provides POSIX poll inspired mechanism, which still deviates from it.

Either way, there're mechanisms available, but they are: 1) should be made more consistent across ports (there's big gap between baremetal and unix, unfortunately - we've let it be that, despite maintainers being well aware that's bad thing); 2) actual leveraging of those mechanisms are up to ports and their maintainers/community.

kfricke, if you're interested in this, and helping to progress this area, please finish your research/comparison how it works across different ports, and write it down somewhere (wiki page would be better than forum). That will be good initial data to work off.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Nico
Posts: 10
Joined: Wed Oct 28, 2015 6:56 am

Re: paho-mqtt for MicroPython

Post by Nico » Wed Oct 28, 2015 7:05 am

Hi,
I'm the author of hbmqtt a MQTT client / broker implementation (https://github.com/beerfactory/hbmqtt) running on Python 3.5.
HBMQTT doesn't use threading but asyncio. I would be happy to make it run on uPy but I don't know if asyncio is supported on uPy.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: paho-mqtt for MicroPython

Post by pfalcon » Wed Oct 28, 2015 9:06 am

Nico wrote:Hi,
I would be happy to make it run on uPy but I don't know if asyncio is supported on uPy.
Reading the forum will help. For example, very this section of the forum, where you posted your message, has a sticky (i.e. always at the top, first-to-see) topic titled "asyncio-like cooperative multitasking framework for uPy". Answers to many other question asked by newcomers can also be found by searching and reading the forum.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

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

Re: paho-mqtt for MicroPython

Post by danielm » Wed Oct 28, 2015 12:22 pm

Nico, I would really be happy if you could make your MQTT client implementation run on MicroPython. Please post an update with your findings regarding compatibility of uasyncio for MicroPython with hbmqtt.

Nico
Posts: 10
Joined: Wed Oct 28, 2015 6:56 am

Re: paho-mqtt for MicroPython

Post by Nico » Thu Oct 29, 2015 8:51 pm

I'm new to micropython. I need some time for testing and investigating in uasyncio, but i'll try.

jeffeb3
Posts: 11
Joined: Sun Jan 18, 2015 3:08 pm

Re: paho-mqtt for MicroPython

Post by jeffeb3 » Fri Oct 30, 2015 5:52 pm

This is great. I'm not certain micropython is the right choice for my application right now (I'm getting some instability, but there could be lots of reasons causing that), but being able to just publish to mqtt would be great. Certainly, when this gets more mature (and it definitely will) having mqtt on micropython, and the esp8266 specifically is going to create lots of interest.

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

Re: paho-mqtt for MicroPython

Post by danielm » Mon Nov 02, 2015 12:46 pm

jeffeb3 can you share what application are you developing on top of MicroPython?

jeffeb3
Posts: 11
Joined: Sun Jan 18, 2015 3:08 pm

Re: paho-mqtt for MicroPython

Post by jeffeb3 » Sun Nov 22, 2015 3:51 pm

Sorry, I don't have my notifications set up on these forums correctly, I didn't know you were asking.

I've got many esp8266's and a single micropython board. The application for mqtt would be using an ESP8266 to read a DHT sensor, or a motion sensor, or something like that, and make the data available to home automation software, like home-assistant.io

Another example would be to have a relay connected, to a thermostat, or something, and control using the ESP.

Post Reply