Official MicroPython MQTT client
Official MicroPython MQTT client
During May, while we resolved issues with ESP8266 port initial release and technical debt in MicroPython code in general, there was also work on MQTT client implementation, which is a first ESP8266 port Kickstarter campaign stretch goals. We briefly considered included code we had at that time in 1.8.1 binary release to the backers, but decided against it, as it was largely in flux, and releasing unfinished design and code could do more harm than good.
However, after 1.8.1 release, I immediately finished most of the remaining work items for initial working version, and pondering about it during this week, didn't find something which requires further big changes. So, I'm going to proceed to the next stage of testing and optimization, and wanted to share this progress report.
If you're interested to play with a still unfinished client, or waited for MQTT support all this time and want to give it a try, you may find related info and share your findings at https://github.com/micropython/micropython/issues/2055 .
Just to clarify again, this is not a release of MQTT client, but a progress report and an invitation for developers and advanced MQTT users to give it a try and report results. It's not yet suitable for end users, but we are definitely going to include it in the next release, by which time it should be much better tested and optimized.
Thanks again to all the Kickstarter campaign backers which made this work possible!
However, after 1.8.1 release, I immediately finished most of the remaining work items for initial working version, and pondering about it during this week, didn't find something which requires further big changes. So, I'm going to proceed to the next stage of testing and optimization, and wanted to share this progress report.
If you're interested to play with a still unfinished client, or waited for MQTT support all this time and want to give it a try, you may find related info and share your findings at https://github.com/micropython/micropython/issues/2055 .
Just to clarify again, this is not a release of MQTT client, but a progress report and an invitation for developers and advanced MQTT users to give it a try and report results. It's not yet suitable for end users, but we are definitely going to include it in the next release, by which time it should be much better tested and optimized.
Thanks again to all the Kickstarter campaign backers which made this work possible!
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/
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/
Re: Official MicroPython MQTT client
I tried to look at the code, but couldn't find anything. The only link to a branch in that issue is a 404, and there are no mqtt-related commits in either micropython or miropython-lib repo.
Are you *sure* you want us to look at it?
Are you *sure* you want us to look at it?
Re: Official MicroPython MQTT client
I found this branch in micropython-lib: https://github.com/micropython/micropyt ... /tree/mqtt
It seems to have some mqtt-related work in it. Is this the code you are talking about, or some earlier experiment?
It seems to have some mqtt-related work in it. Is this the code you are talking about, or some earlier experiment?
Re: Official MicroPython MQTT client
Let me know how I can help, I do use MQTT but on a very(!!!) limited class I made based on some work I found around here on the forum. Would be nice to have a client which supports login and optionally ssl/tls.
Code: Select all
import socket
import time
try:
import binascii
except ImportError:
import ubinascii as binascii
import config
class MQTT(object):
s = None
addr = None
prefix = ""
def __init__(self, host, port=1883, prefix=config.MQTT_PREF):
self.addr = socket.getaddrinfo(host, port)[0][4]
self.prefix = prefix
self.reset_socket()
def reset_socket(self):
self.s = socket.socket()
def connect(self):
address = self.addr
self.s.connect(address)
self.s.send(self.mtpConnect(config.DEVICE_NAME))
def disconnect(self):
self.s.send(self.mtpDisconnect())
self.s.close()
def publish(self, topic, data, sleep=1):
self.s.send(self.mtpPub(self.prefix+topic, bytes(str(data), 'ascii')))
if sleep:
time.sleep(sleep)
def recv(self, length=4096):
return binascii.hexlify(self.s.recv(length))
@staticmethod
def mtStr(s):
return bytes([len(s) >> 8, len(s) & 255]) + s.encode('utf-8')
@staticmethod
def mtPacket(cmd, variable, payload):
return bytes([cmd, len(variable) + len(payload)]) + variable + payload
def mtpConnect(self, name):
return self.mtPacket(
0b00010000,
self.mtStr("MQTT") + # protocol name
b'\x04' + # protocol level
b'\x00' + # connect flag
b'\xFF\xFF', # keepalive
self.mtStr(name)
)
@staticmethod
def mtpDisconnect():
return bytes([0b11100000, 0b00000000])
def mtpPub(self, topic, data):
return self.mtPacket(0b00110001, self.mtStr(topic), data)
NodeMCU v0.9 / V1 / V2 / V3
WeMos D1 Mini
WeMos Lolin32 v1.0.0
WeMos Lolin D32 Pro V2
WeMos D1 Mini
WeMos Lolin32 v1.0.0
WeMos Lolin D32 Pro V2
Re: Official MicroPython MQTT client
I do think that's what he was referring to, I was actually looking at that branch when the commits appeared and then the post followed :)deshipu wrote:I found this branch in micropython-lib: https://github.com/micropython/micropyt ... /tree/mqtt
It seems to have some mqtt-related work in it. Is this the code you are talking about, or some earlier experiment?
Re: Official MicroPython MQTT client
am I correct in assuming where TLS support currently exists it is only TLSv1 and not TLSv2 ?
Examples like this https://www.pycom.io/connecting-to-microsoft-azure/ only mention v1, has the capability been expanded since then ?
Examples like this https://www.pycom.io/connecting-to-microsoft-azure/ only mention v1, has the capability been expanded since then ?
Re: Official MicroPython MQTT client
umqtt.simple module was officially "released": https://pypi.python.org/pypi/micropython-umqtt.simple . It's also included in ESP8266 official binary release as sent to the backers of the Kickstarter campaign. Documentation and examples are available at https://github.com/micropython/micropyt ... qtt.simple . The module will be of course developed further - it's only v1.0.1 now .
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/
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/
Re: Official MicroPython MQTT client
I would like to ask - what does value returned by connect() mean?
Re: Official MicroPython MQTT client
Now described in the documentation https://github.com/micropython/micropyt ... README.rstwhat does value returned by connect() mean?
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/
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/
Re: Official MicroPython MQTT client
A version of MQTT client with auto-reconnect on errors support, umqtt.robust, was merged to master: https://github.com/micropython/micropyt ... qtt.robust . Docs are coming, in the meantime, see comments in an example: https://github.com/micropython/micropyt ... _robust.py
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/
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/