Help with ESP8266 PIR MQTT arduino sketch

I’ve been trying to get a sketch working to pair a NodeMCU/PIR sensor into Home Assistant via MQTT. My MQTT broker is working fine but I do have it set to require a username and password. All the example sketches I can find are running with no authentication enabled and I don’t know exactly how to integrate the user/pass into the sketch.

Can anyone share a simple sketch that I can use to connect these?

Look at this example - it works for me:

Sebastian

1 Like

using the pubsubclient library che connection to the broker is like this:

// client parameters PubSubClient client(mqtt_server, 1883, callback, espClient); if (client.connect("433toMQTTto433", "username", "password"))

find this part in your sketch and add user and pass… i think :slight_smile:

Thanks, I hadn’t considered the adafruit, I thought it was just for connecting to their cloud service. I’ll give that a shot!

I missed that part of the pubsubclient. Thanks for the heads up!

I’m using that exact same sketch - I just threw out the callback() function, because it’s not needed here and I added a line to turn off the LED on the nodeMCU board, because that thing ist bright as hell :wink:

Sebastian

1 Like

Thanks, I got this working using your example!