micropython/micropython-lib

umqtt cannot import MQTTClient

DonPavlov opened this issue ยท 3 comments

Using the latest esp32 micropython build. Dowloaded the latest umqtt with these commands:
upip.install('micropython-umqtt.simple')
upip.install('micropython-umqtt.robust')

But as soon as i want to follow even the simplest of examples and try this:

from umqtt.simple import MQTTClient
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name MQTTClient

but if i put the umqtt.simple lib just onto the main memomry of the esp32

ampy --port COM6 put C:\Users\xxxx\Downloads\simple.py

and use simple.py import MQTTClient it works.
so somehow something seems broken.

I had exactly the same problem.
Digging around a little bit I found out that lib/umqtt/simple.py was simply empty:

f = open('lib/umqtt/simple.py')
f.read()

Probably the installation silently failed in any strange way...
Repeating upip.install('micropython-umqtt.simple') fixed the problem.

Came across this issue today while using f/w esp32-20180511-v1.9.4.bin.
The contents of file simple.py in lib/umqtt was empty. I downloaded another copy of simple.py and used ampy put to re-install it - 'ampy --port COM7 put simple.py 'lib/umqtt/simple.pyuse'

This solved the problem. So I thought I had stuffed up the firmware or mqtt install but went through the
exercise a second & third time with the same result.

Solution....Use ampy to copy a version of simple.py from the micropython-lib - and continue with installation.
ampy --port COM7 put simple.py 'lib/umqtt/simple.py

"import network
import upip

sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect("Wifi SSID", "Wifi password")

upip.install('micropython-umqtt.simple')
upip.install('micropython-umqtt.robust')"

PS - Followed this procedure to install BME280 and mqtt on esp32.

https://github.com/gloveboxes/ESP32-MicroPython-BME280-MQTT-Sample

I am Using NodeMCU esp board with newest version of micropython firmware and my solution to this problem is to load simple.py with WEBREPL and then use

uos.mkdir()

and

uos.rename()

to put this file to lib/umqtt.