0

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");
  }
}
dda
  • 6,030
  • 2
  • 25
  • 34
SmartKid
  • 71
  • 9
  • You are calling `client.connect(serverName, 80)` twice and we don't know what your `serverName` is, which could be the source of the problem. – gre_gor May 25 '17 at 13:25
  • Please find below the server name and the device ID. char DEVID1[] = "v4E***********"; char serverName[] = "api.pushingbox.com"; – SmartKid May 26 '17 at 07:53
  • I have 2 calls because the 1st one will initialize Arduino and ethernet connection as a dummy call because I realized it take a second or 2 to get the connection sorted and the second one is the actual call. – SmartKid May 26 '17 at 07:56

0 Answers0