Hello to everyone
i have a problem with this program regarding the mqtt in fact it gives me this error message: ImportError: no module named 'umqtt' i don't know how to solve
thank you
P.S. forgive english but it is not my language
this is the program
import machine
import time
import dht
import network
from umqtt.simple import MQTTClient
SSID = "NETGEAR84"
PASSWD = ""
def do_connect():
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print("connecting to network.....")
sta_if.active(True)
sta_if.connect(SSID, PASSWD)
while not sta_if.isconnected():
pass
print("network config:",sta_if.ifconfig())
do_connect()
SERVER = "192.168.1."
CLIENT_ID = "ESP8266"
TOPIC = "t_h"
client = MQTTClient(CLIENT_ID,SERVER)
client.connect()
d = dht.DHT22(machine.Pin(14))
while True:
try:
d.measure()
t = d.temperature()
h = d.humidity()
msg = str(t) + "," + str(h)
client.publish(TOPIC,msg)
print(msg)
except OSError:
print("errore")
time.sleep(4)
problem with mqtt
Re: problem with mqtt
These files arfe not always included in the build. You can find them in the micropython-lib:
https://github.com/micropython/micropyt ... /robust.py
https://github.com/micropython/micropyt ... /simple.py
You have to create a directory name umqtt on you board and copy these files to that directory. I do not know, which board you are using, so the method for copying varies.
https://github.com/micropython/micropyt ... /robust.py
https://github.com/micropython/micropyt ... /simple.py
You have to create a directory name umqtt on you board and copy these files to that directory. I do not know, which board you are using, so the method for copying varies.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: problem with mqtt
you also need to create a __init__.py in that umqtt folder (an empty file).
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: problem with mqtt
I created the mqtt folder inside the esp8266 in the folder I inserted the empty __init__.py file but after doing this it is as if the card had stopped working to connect to the card I use the picocom command from the mac terminal but doing so now gives me terminal ready but no I can write nothing and if I press the reset button on the board it does not reset correctly because it no longer executes the two files boot.py and main.py if I did it before the creation of __init__.py everything worked correctly I already tried to clear the memory of the card and reinstall micropython but nothing has changed what could have happened?