Skip to content

i have modified your code for esp8266 but need help #1

@rajbadri

Description

@rajbadri

my code is
////
//
// General code from http://www.pushingbox.com for esp8266 /arduino v1.0
//
////

include <ESP8266WiFi.h>

include <WiFiClient.h>

include <IPAddress.h>

/////////////////
// MODIFY HERE //
/////////////////
const char* ssid = "xxxxxxxxxxxx";
const char* password = "xxxxxxxx";

char DEVID1[] = "v0ACA232DF200D15"; //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);

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);
WiFi.config(IPAddress(192,168,1,200), 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) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON
{
if(DEBUG){Serial.println("pinDevid1 is HIGH");}
pinDevid1State = true;
//Sending request to PushingBox when the pin is HIGHT
sendToPushingBox(DEVID1);
}
if (digitalRead(pinDevid1) == LOW && pinDevid1State == true) // switch on pinDevid1 is OFF
{
if(DEBUG){Serial.println("pinDevid1 is LOW");}
pinDevid1State = false;
//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();
}

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("sendind request");}
if(client.connect(serverName,80)) // correctly when it shows up on my phone.
{
Serial.println("Connected to URL.");
Serial.println();

 client.print("POST /pushingbox?devid=");
 client.print(devid);
 client.println(" HTTP/1.1");
 client.println("Host: api.pushingbox.com");
 client.println("User-Agent: arduino-ethernet");
 client.println("Connection: close");
 client.println();

 Serial.print("POST /pushingbox?devid=");
 Serial.print(devid);
 Serial.println(" HTTP/1.1");
 Serial.println("Host: api.pushingbox.com");
 Serial.println("Connection: close");
 Serial.println();

 delay(2000);
 client.stop();

}
else
{
client.stop();
}
}

}

this is the output on serial monitor but i am not getting any notifications

pinDevid1 is HIGH
connecting...
connected
sendind request
Connected to URL.

POST /pushingbox?devid=v0ACA232DF200D15 HTTP/1.1
Host: api.pushingbox.com
Connection: close

pinDevid1 is LOW

please help

thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions