I am using ArduinoMqttClient library, On running a loop every 70 seconds, it connects the first time and sends the message, then on the second message and after retries every 5 mins, I am getting
MQTT connection failed! Error code = -1
I cannot find any reference on the interweb for (-1) error code,
Anyone any ideas??
Thanks in advance.
Read How to use this forum, and post your sketch- all of it- using code tags.
const char apn = "data.com";
const char login = ""; // keep blank if not sure
const char password = ""; // keep blank if not sure
const char broker = "220.127.116.11";
int port = 1883;
const char topic = "test2";
const char publishTopic = "357520078007230";
void parseData(String dataToSend)
Serial.print("Attempting to connect to the MQTT broker: ");
while (!mqttClient.connect(broker, port))
Serial.print("MQTT connection failed! Error code = ");
Serial.println("You're connected to the MQTT broker!");
// set the message receive callback
This is the code I am calling from the main script for MQTT connection. The main script only sets up GSM connection and gets a temperature reading.
I don’t see anything wrong with the code but I have never used the ArduinoMqttClient library.
Try the PubSubClient library, which I suspect is a lot more commonplace here.
Thanks for all your help. The problem turned out to be a problem with the local SIM card operator. They were having some outage in the area, I switched provider and the problem has been rectified. Once again thanks.
This can be now closed.