Hello. I am trying to connect the TCALL ESP32 SIM800L to a Digital Ocean droplet via MQTT broker, using the code from this tutorial: https://randomnerdtutorials.com/esp32-cloud-mqtt-broker-sim800l/#more-99705
Unfortunately, the connection fails. I am using the IP address of that droplet and the user and password configured in mosquitto.
Any idea what am I doing wrong?
Hi.
Can you provide more information about the error you’re getting?
Regards,
Sara
Hi Sara, it is difficult to get more information about the error, as far as I know. The part of the code trying to make the connection is this:
boolean status = mqtt.connect("GsmClientN", mqttUsername, mqttPassword);
if (status == false) {
SerialMon.println(" fail");
ESP.restart();
return false;
}
Is this code correct?
Hi.
Do you know if your module is connecting correctly to the internet?
Regards,
Sara
Hi Sara. Apparently, the SIM card works well and this part of the code works properly;
SerialMon.print("Connecting to APN: ");
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(" fail");
ESP.restart();
}
else {
SerialMon.println(" OK");
}
if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
I get OK and GPRS connected.
Hi again.
Have you tried connecting to the broker using a “regular” ESP32?
Just to make sure we can make a connection with the broker…
Regards,
Sara
Hi Sara, I can try with an ESP32 with WIFI conectivity, for example following your tutorial:
Cloud MQTT Mosquitto Broker – Access Anywhere Digital Ocean | Random Nerd Tutorials
The first problem I get is that the tutorial refers to a library called ‘Async TCP’, but the code is actually using another one called ‘AsyncMqttClient’. So, that code cannot work.
Regards
Hi.
I’m sorry, but I didn’t understand your issue…
The code uses both libraries. Check the part about installing libraries. We mention to install both.
The AsyncMQTT client needs the AsyncTCP library to work.
You can test that code by installing the right libraries and see if the board connects to the broker.
Regards,
Sara
Another thing. Do you have more than one board trying to connect to that broker with the same code?
If so, they should have a different MQTTClient name. See the following line.
boolean status = mqtt.connect("GsmClientN", mqttUsername, mqttPassword);
The name is “GsmClientN”. If you have more than one board, they should have different name.
Thanks Sara. No, I only have one board connected (or trying to). But that name “GsmClientN” is something we need to set up in the server?
Hello. Now I have installed both Mqtt libraries and trying the code on page 152 of the Smart Home book with ESP-Dev module. It is also not connecting to MQTT:
Connecting to MQTT...
Disconnected from MQTT.
Connecting to MQTT...
Disconnected from MQTT.
Connecting to MQTT...
Now it works, after re-establishing the password in mosquito:
IP address:
192.168.178.119
Connecting to MQTT...
Connected to MQTT.
Session present: 0
Subscribing at QoS 2, packetId: 167
Publishing at QoS 0
Publishing at QoS 1, packetId: 168
Publishing at QoS 2, packetId: 169
Subscribe acknowledged.
packetId: 167
qos: 2
Publish acknowledged.
packetId: 168
Publish acknowledged.
packetId: 169
Great.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara
Hi Sara, Sorry, the connection using ESP32 via WiFi is resolved, but my initial issue (see the initial question) was regarding the connection of an ESP32 T-CALL via gsm, which is still not resolved. Using the same mosquito credentials does not solve the problem for the gsm connection.
Hi again.
I’m sorry, you’re right.
So, it means the broker is working….
Try changing the name of your device… give a different name than GsmClientN:
boolean status = mqtt.connect("GsmClientN", mqttUsername, mqttPassword);
Let me know the results.
Regards,
Sara
Hi Sara. I am still struggling with this. I was wondering if we need to open some ports in the Firewall of the droplet at Digital Ocean? However, with an ESP32 board with Wifi it works. So, must be something related to the SIM card, but I have tried different cards from different operators.
Hi Carlos.
I’m not sure what might be the problem.
In our case, we didn’t need to do anything different from what is described in the tutorial…
What do you get exactly on the serial monitor with that board? Does it connect to the internet properly first? Does it connect and get data service?
Regards,
Sara
SOLVED!!
I have first tested the connectivity to a public mqtt like test.mosquitto.org, and it was ok.
Then I tested the mosquitto broker installed at the digital ocean droplet using this tool: mqtt-explorer.com, and noticed that the stablished port was 8883 and not 1883. Then I corrected the port in the script and it works!!