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
ImportError: no module named 'umqtt.MQTTClient' but file with class exists
- 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
I suggest you look at the example progams for the correct way to import and use umqtt.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.