Reputation: 21
I'm trying to build a basic MQTT publisher using a nodemcu v3 and a dht11 to send temperature data. I'm using ESPlorer and when I try to upload my code it tells me that the paho
module does not exist. My code is as follows:
import time
import network
import paho.mqtt.client as mqtt
sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)
sta_if.connect('<MySSID>', '<MyPW>')
mqtt = mqtt.Client()
mqtt.connect("randomIPaddress")
pin = machine.Pin(4)
temp_instance = dht11.DHT11(pin)
result = temp_instance.read()
print("Temperature is: %d C" % result.temperature)
print("Humidity is: %d %%" % result.humidity)
message = result.temperature
mqtt.publish("base/dht11/temp", message)
mqtt.loop_forever()
I'm still very confused by how MQTT publishing works, and I can't seem to find any sources that agree with each other on this. Everywhere I look has a different solution for my problem.
Does anyone have an idea why ESPLorer keeps telling me that the paho
module doesn't exist? I've already tried installing the module as shown in the documentation but that got me nowhere.
Edit: https://pypi.python.org/pypi/paho-mqtt/1.1 These where the instructions I followed to install paho.
Upvotes: 0
Views: 2096
Reputation: 312790
The paho
MQTT client has been written for regular Python. It is unlikely that it would run under MicroPython.
MicroPython includes its own MQTT client called umqtt
. There are two versions, umqtt.simple and umqtt.robust.
You can see an example that uses it here.
Upvotes: 5