Closed architmuchhal12 closed 6 years ago
Your library is not initialised properly. Take a look here - https://pubsubclient.knolleary.net/api.html
I am not sure what error I am making in initializing the PubSub client. Here is my code for the connection to MQTT Broker
Code -
boolean mqttConnect() {
Serial.print("Connecting to: ");
Serial.println(broker);
if (!mqtt.connect("ESP32Client", "user", "password")) {
Serial.println(" ----->> Fail!");
}
else {
Serial.print("Error code number for no connection: ");
Serial.println(mqtt.state());
return false;
}
I have also tried other combinations from the library for the "connect" function, but none of them returned a success.
I can't see where your WiFi library is initialised as a client. Take a look at this tutorial, it'll get you up and running. https://techtutorialsx.com/2017/04/24/esp32-publishing-messages-to-mqtt-topic/
@androidcho He is using an external GSM modem (SIM808) instead of Wifi, so don't need the wifi stuff =)
This issue is closed, because it looks as if it is not a bug or problem with the ESP32 Arduino core or its support libraries. For general API usage questions or help on specific coding challenges, please visit the arduino-esp32 Gitter channel. If you feel this issue was closed in error, reopen it and comment, why you think this is a bug in the Arduino-Core.
Hello,
I am using a Sparkfun ESP32 with Adafruti FONA 808 to connect to an MQTT Server.
Hardware:
Board: Sparkfun ESP32 Thing Core Installation/update date using this version: 41e36a7 IDE name: Arduino IDE Flash Frequency: 80Mhz Upload Speed: 115200
I am using the following 2 libraries.
I have modified the TinyGSM/examples/MqttClient/MQTTClient.ino accordingly.
I am using hardware serial at 115200 baud rate. The issue I am facing is the serial monitor displays the reason for no connection as (-4) which is due to Timeout Value. I have also tried increasing the timeout value in the library but with no success.
I know this issue isn't relevant to ESP32 but if I could get any help, it would be really great.
Please suggest me a solution! Thanks!
Init Code:
FONA808 Setup:
Serial Monitor Output: