I have been going through the Smart Home Raspberry Pi book and have gone through all modules successfully up to module 5. Here, I am using a NodeMCU ESP32S and I copied the example code provided in the book for the ESP32. I modified the locations with my SSID, Password, Broker User Name and Password. When I try to run this code, I successfully connect to WiFi, but I cannot connect to the MQTT. Here is my result on the monitor:
mode:DIO,���div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4
Connecting to Wi-Fi…
[WiFi-event] event: 0
[WiFi-event] event: 2
[WiFi-event] event: 4
[WiFi-event] event: 7
WiFi connected
IP address:
192.168.86.37
Connecting to MQTT…
Publishing on topic counter at QoS 1, packetId: 0
Publishing on topic counter at QoS 1, packetId: 0
Disconnected from MQTT.
Connecting to MQTT…
Publishing on topic counter at QoS 1, packetId: 0
Publishing on topic counter at QoS 1, packetId: 0
Disconnected from MQTT.
Connecting to MQTT…
Publishing on topic counter at QoS 1, packetId: 0
Publishing on topic counter at QoS 1, packetId: 0
Disconnected from MQTT.
Connecting to MQTT…
Publishing on topic counter at QoS 1, packetId: 0
Publishing on topic counter at QoS 1, packetId: 0
Disconnected from MQTT.
As I said, up to this point I have had no issues — I installed Node-Red and was able to control the GPIO on the RPi5. Next, I installed Mosquitto Broker, sent the “Hello World” message to testTopic, and then enabled remote access/authentication. All of this worked fine with the username and password. Then, using MQTT with Node-Red also controlled an LED on the RPi GPIO.
As can be seen from the output, I never get a message indicating that MQTT is connected. I never get to this function:
void onMqttConnect(bool sessionPresent) {
Serial.println(“Connected to MQTT.”);
Serial.print(“Session present: “);
Serial.println(sessionPresent);
I have double checked the mosquitto.conf file for correctness and verified that it is at /etc/mosquitto/.
Differences from your book: a) I am using Platformio b) I am using a RPi5.
Any suggestion for me to try would be greatly appreciated.
Thanks
I just installed the Arduino IDE, and everything works fine using it, so I think this issue is more appropriate for the Platformio community.
Thanks.