The use of the ESP8266 in the world of IoT

User avatar
By michaele6
#85131 i am able to connects to my wireless but changing status on pin2 does not send a message out
so i am trying to prove if this is a push issue or a local issue , so can some one help me with modifing the code so it turns the builtin led when the reed switch is closed , to confirm the hardware and pins are correct
/
#include <ESP8266WiFi.h>

// PushingBox scenario DeviceId code and API
String deviceId = "v8D7383561A3C58";
const char* logServer = "api.pushingbox.com";
char* ssid = "ub1xcv";
const char* password = "mypassword";
int reed_switch = 2;
boolean previous_doorStatus=0;
void setup() {
Serial.begin(74880);
// Sending a notification to your mobile phone
// function takes the message as a parameter
//sendNotification("Hello World from ESP8266!");
pinMode(reed_switch, INPUT);
previous_doorStatus = digitalRead(reed_switch );
}


void sendNotification(String message){

Serial.println("- connecting to Home Router SID: " + String(ssid));

WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println();
Serial.println("- succesfully connected");
Serial.println("- starting client");

WiFiClient client;

Serial.println("- connecting to pushing server: " + String(logServer));
if (client.connect(logServer, 80)) {
Serial.println("- succesfully connected");

String postStr = "devid=";
postStr += String(deviceId);
postStr += "&message_parameter=";
postStr += String(message);
postStr += "\r\n\r\n";

Serial.println("- sending data...");

client.print("POST /pushingbox HTTP/1.1\n");
client.print("Host: api.pushingbox.com\n");
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
client.stop();
Serial.println("- stopping the client");
}

void loop() {
// read the input pin:
boolean door_status = digitalRead(reed_switch );

//makes sure that push notification only on door open
if(door_status != previous_doorStatus && !door_status ){
// Sending a notification to your mobile phone
// function takes the message as a parameter
sendNotification("Door has been opened");
}
previous_doorStatus=door_status;
delay(5000);
}
User avatar
By survivingwithandroid
#86360 I wrote a tutorial about how to connect ESP8266 to PushingBox. It describes step by step how to do it. It may help you:

https://www.survivingwithandroid.com/implement-iot-notification-system-using-arduino-pushbullet/

Let me know it is helpful