0

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.

3
  • 2
    Can you please post the instructions you followed to install paho? Commented Mar 4, 2018 at 20:56
  • Welcome to SO. Your code looks like Python so I added the corresponding tag. To get more detailed answers, consider adding the exact error you are getting to the question. Also, as @killthrush suggested, can you add how you installed paho? Commented Mar 5, 2018 at 9:16
  • pypi.python.org/pypi/paho-mqtt/1.1 Those are the instructions I followed to install paho. Where they the wrong ones? Commented Mar 5, 2018 at 11:26

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ahhhhh I see! Thanks so much for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.