Elsewhere in the forum are the 15 or so lines of code that enable a simple mqtt publish capability that has been tested on the esp8266.
The mqtt client code runs fine under the unix/linux version of micropython but at about 1400 lines of code I doubt it's much use on most hardware but at least demonstrates that the code works under micropython and there is a lot of additional code that can be stripped out or compressed. As the esp8266 kickstarter goals include an mqtt client this may or may not prove of any use for creating that but it was instructive to me in terms of the capabilities of micropython. (I am sure that Damien and/or Paul will create the equivalent in 25 lines or less.)
The client does use errno.py, ffilib.py, os.py, select.py, socket.py and stat.py from micropython-lib. Next step is to get something that does work on the esp8266.
For anyone interested the code below can be used to test the client:
Code: Select all
import umqtt as mqtt import utime as time def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) client.subscribe("test") def on_message(client, userdata, msg): print(msg.topic+" "+str(msg.payload)) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect(<host>, 1883, 60) while 1: client.loop() time.sleep(1)