ImportError: no module named 'umqtt.MQTTClient' but file with class exists

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Hack4Life
Posts: 1
Joined: Mon Feb 05, 2018 10:11 pm
Location: Austria

ImportError: no module named 'umqtt.MQTTClient' but file with class exists

Post by Hack4Life » Mon Feb 05, 2018 10:23 pm

Hello!
I installed MicroPython v1.9.3-8 on my ESP8266 board. Here is the beginning of my main.py file:

[code]from machine import Pin

led = Pin(2, Pin.OUT, value=1)

#---MQTT Sending---

from time import sleep_ms
from ubinascii import hexlify
from machine import unique_id
#import socket
from umqtt import MQTTClient

SERVER = "10.6.6.192"
CLIENT_ID = hexlify(unique_id())
TOPIC1 = b"/server/tem"
TOPIC2 = b"/server/hum"
TOPIC3 = b"/server/led"
[/code]
The line from umqtt import MQTTClient throws an error when I reset the module:

File "main.py", line 11, in < module >
ImportError: no module named 'umqtt.MQTTClient'

This is the umqtt.py file I use: https://cdn.hackaday.io/files/12979555293536/umqtt.py

I have the umqtt.py file uploaded to my esp8266 with webrepl. When I run:

[code]
import os
os.listdir() [/code]
I get this output:

[code]>>> os.listdir()
['boot.py', 'webrepl_cfg.py', 'umqtt.py', 'main.py'][/code]

Since in the umqtt.py file in line 8 the class MQTTClient is defined, I do not know what am I doing wrong to get this code to work.

I hope that someone in this forum knows a solution or can tell me what am I doing wrong..

Greets from Austria,
Fabian

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ImportError: no module named 'umqtt.MQTTClient' but file with class exists

Post by pythoncoder » Tue Feb 06, 2018 6:34 am

I suggest you look at the example progams for the correct way to import and use umqtt.
Peter Hinch
Index to my micropython libraries.

Post Reply