problem with mqtt

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
llucaa
Posts: 2
Joined: Fri Mar 06, 2020 8:38 pm

problem with mqtt

Post by llucaa » Fri Mar 06, 2020 9:04 pm

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 :D :D




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)

User avatar
Roberthh
Posts: 1886
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: problem with mqtt

Post by Roberthh » Fri Mar 06, 2020 9:17 pm

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.

kevinkk525
Posts: 638
Joined: Sat Feb 03, 2018 7:02 pm

Re: problem with mqtt

Post by kevinkk525 » Fri Mar 06, 2020 9:43 pm

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

llucaa
Posts: 2
Joined: Fri Mar 06, 2020 8:38 pm

Re: problem with mqtt

Post by llucaa » Sat Mar 07, 2020 2:56 pm

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?

Post Reply