Hello.
I am using a Raspberry Pi 4 to install an MQTT broker so that I can send messages to it from an ESP01 device.
I have setup the broker correctly and I'm also able to subscribe to the topic (from within the Raspberry itself) successfully, using the mosquitto_sub application . I can publish messages, also from the Raspberry by using mosquitto_pub and I see them on the subscriber.
On the ESP01, I am using the library ArduinoMqttClient and I could connect to the broker and send 2 messages and get them on the subsctiber, but then, in the broker logs, I see the ESP01 client simply disconnects and no more messages are seen in the subscriber.
This is the subscriber:
ubuntu@ubuntu:~$ sudo mosquitto_sub -h 127.0.0.1 -p 58999 -t "CCS811/test"
hello 0
hello 1
^Cubuntu@ubuntu:~$ mosquitto_sub -h 127.0.0.1 -p 58999 -t "CCS811/test"
CCS881 testing message
CCS881 testing message 1
CCS881 testing message 2
CCS881 testing message 3
The first 2 Hello messages were sent from the ESP01 device. The other ones were sent from the Raspberry Pi 4 itself using:
ubuntu@ubuntu:~$ mosquitto_pub -d -h 127.0.0.1 -p 58999 -t "CCS811/test" -m "CCS
881 testing message"
Client mosq-oN5sPpVtULNAnxmy3Z sending CONNECT
Client mosq-oN5sPpVtULNAnxmy3Z received CONNACK (0)
Client mosq-oN5sPpVtULNAnxmy3Z sending PUBLISH (d0, q0, r0, m1, 'CCS811/test', ... (22 bytes))
Client mosq-oN5sPpVtULNAnxmy3Z sending DISCONNECT
ubuntu@ubuntu:~$ mosquitto_pub -d -h 127.0.0.1 -p 58999 -t "CCS811/test" -m "CCS881 testing message 1"
Client mosq-Qu4Y9VG3KnEvilLVkG sending CONNECT
Client mosq-Qu4Y9VG3KnEvilLVkG received CONNACK (0)
Client mosq-Qu4Y9VG3KnEvilLVkG sending PUBLISH (d0, q0, r0, m1, 'CCS811/test', ... (24 bytes))
Client mosq-Qu4Y9VG3KnEvilLVkG sending DISCONNECT
ubuntu@ubuntu:~$ mosquitto_pub -d -h 127.0.0.1 -p 58999 -t "CCS811/test" -m "CCS881 testing message 2"
Client mosq-Co0e2NeBcC3y3NYBbP sending CONNECT
Client mosq-Co0e2NeBcC3y3NYBbP received CONNACK (0)
Client mosq-Co0e2NeBcC3y3NYBbP sending PUBLISH (d0, q0, r0, m1, 'CCS811/test', ... (24 bytes))
Client mosq-Co0e2NeBcC3y3NYBbP sending DISCONNECT
ubuntu@ubuntu:~$ mosquitto_pub -d -h 127.0.0.1 -p 58999 -t "CCS811/test" -m "CCS881 testing message 3"
Client mosq-evJAJMTRE1c9xWlgzI sending CONNECT
Client mosq-evJAJMTRE1c9xWlgzI received CONNACK (0)
Client mosq-evJAJMTRE1c9xWlgzI sending PUBLISH (d0, q0, r0, m1, 'CCS811/test', ... (24 bytes))
Client mosq-evJAJMTRE1c9xWlgzI sending DISCONNECT
ubuntu@ubuntu:~$
In the mosquitto logs I see the following:
1663853975: New connection from 127.0.0.1 on port 58999.
1663853975: New client connected from 127.0.0.1 as mosq-sGpmPzl2otVMREzWnH (p2, c1, k60).
1663854348: New connection from 192.168.1.128 on port 58999.
1663854348: New client connected from 192.168.1.128 as Arduino-00005284 (p2, c1, k60).
1663854441: Client Arduino-00005284 has exceeded timeout, disconnecting.
1663854640: Client mosq-sGpmPzl2otVMREzWnH disconnected.
So, the 192.168.1.128 is the ESP01 device and it ends up disconnecting.
I am using the basic example from Arduino IDE examples and only changed needed configuration parameters.
In the loop function, there is a call to a poll()
function to, supposedly keep the connection alive and be able to communicate with the broker, but somehow the connection seems to drop and no more messages are seen in the subscriber!
Any help would be appreciated!
Psy