I'm trying to send a notification from Arduino to an email when something is triggered using PushingBox API, but the connection returns 0 and sometimes -1.
Can anyone assist in figuring out what might be the issue?
//Function for sending the request to PushingBox
void sendToPushingBox(char devid[]) {
client.stop();
if(DEBUG) Serial.println("connecting...");
client.connect(serverName, 80); //Dummy call
delay(3000);
int conn = client.connect(serverName, 80);
// actual call returns 0
int clientConnect = client.connected();
Serial.print(clientConnect);
Serial.print(" ");
Serial.println(conn);
if (clientConnect) {
if(DEBUG) Serial.println("connected");
if(DEBUG) Serial.println("sendind request");
client.print("GET /pushingbox?devid=");
client.print(devid);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(serverName);
client.println("User-Agent: Arduino");
client.println();
Serial.println("Request sent");
} else {
if(DEBUG) Serial.println("connection failed");
}
}