pushing box code hangs on sending request
Posted: Tue Apr 21, 2015 11:53 am
i have modified the pushing box code and have tried to run it on esp8266. The code is a as follows
the code compiles and loads on the esp8266 and when it runs i get this on the serial monitor
pinDevid1 is LOW
connecting...
connected
sendind request
the pushing box servers does not process the request and i do not get any notifications
Please Help
Thanks
Code: Select all
////
//
// General code from http://www.pushingbox.com for Arduino WiFI shield (official) v1.0
//
////
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <IPAddress.h>
/////////////////
// MODIFY HERE //
/////////////////
const char* ssid = "wifi-router";
const char* password = "password";
char DEVID1[] = "v0ACA232DF200xxxx"; //Scenario : "The mailbox is open"
//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 2; // Example : the mailbox switch is connect to the Pin 3
// Debug mode
boolean DEBUG = true;
//////////////
// End //
//////////////
char serverName[] = "api.pushingbox.com";
boolean pinDevid1State = false; // Save the last state of the Pin for DEVID1
boolean lastConnected = false;
int status = WL_IDLE_STATUS; // the Wifi radio's status
WiFiClient client;
void setup() {
// initialize serial:
Serial.begin(9600);
pinMode(pinDevid1, INPUT);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
WiFi.config(IPAddress(192,168,1,252), IPAddress(192,168,1,1), IPAddress(255,255,255,0));
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop() {
////
// Listening for the pinDevid1 state
////
if (digitalRead(pinDevid1) == LOW && pinDevid1State == true) // switch on pinDevid1 is ON
{
if(DEBUG){Serial.println("pinDevid1 is LOW");}
pinDevid1State = true;
//Sending request to PushingBox when the pin is HIGHT
sendToPushingBox(DEVID1);
}
if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is OFF
{
if(DEBUG){Serial.println("pinDevid1 is HIGH");}
pinDevid1State = true;
//Sending request to PushingBox when the pin is LOW
//sendToPushingBox(DEVID1); //Here you can run an other scenario by creating a DEVID2 variable
}
//DEBUG part
// this write the respons from PushingBox Server.
// You should see a "200 OK"
if (client.available()) {
char c = client.read();
if(DEBUG){Serial.print(c);}
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
if(DEBUG){Serial.println();}
if(DEBUG){Serial.println("disconnecting.");}
client.stop();
}
lastConnected = client.connected();
}
//Function for sending the request to PushingBox
void sendToPushingBox(char devid[]){
client.stop(); if(DEBUG){Serial.println("connecting...");}
if(client.connect(serverName, 80)) {
if(DEBUG){Serial.println("connected");}
if(DEBUG){Serial.println("sending 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();
}
else {
if(DEBUG){Serial.println("connection failed");}
}
}
the code compiles and loads on the esp8266 and when it runs i get this on the serial monitor
pinDevid1 is LOW
connecting...
connected
sendind request
the pushing box servers does not process the request and i do not get any notifications
Please Help
Thanks