Page 2 of 2

Re: paho-mqtt for MicroPython

Posted: Thu Oct 22, 2015 5:25 pm
by pfalcon
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.

Re: paho-mqtt for MicroPython

Posted: Wed Oct 28, 2015 7:05 am
by Nico
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.

Re: paho-mqtt for MicroPython

Posted: Wed Oct 28, 2015 9:06 am
by pfalcon
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.

Re: paho-mqtt for MicroPython

Posted: Wed Oct 28, 2015 12:22 pm
by danielm
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.

Re: paho-mqtt for MicroPython

Posted: Thu Oct 29, 2015 8:51 pm
by Nico
I'm new to micropython. I need some time for testing and investigating in uasyncio, but i'll try.

Re: paho-mqtt for MicroPython

Posted: Fri Oct 30, 2015 5:52 pm
by jeffeb3
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.

Re: paho-mqtt for MicroPython

Posted: Mon Nov 02, 2015 12:46 pm
by danielm
jeffeb3 can you share what application are you developing on top of MicroPython?

Re: paho-mqtt for MicroPython

Posted: Sun Nov 22, 2015 3:51 pm
by jeffeb3
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.