Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <ESP8266WiFi.h>
// PushingBox scenario DeviceId code and API
String deviceId = "xxxx"; // PushBox device ID
const char* logServer = "api.pushingbox.com";
const char* ssid = "xxxx"; // Fill in
const char* password = "xxxx"; // Fill in
int inPin = 5; // pushbutton connected to digital pin 5
int val = 0; // variable to store the read value
void setup() {
Serial.begin(74880);
// Sending a notification to your mobile phone
// function takes the message as a parameter
pinMode(inPin, INPUT);
Serial.println("- connecting to Home Router SID: " + String(ssid));
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void sendNotification(String message){
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()
{
delay(1000);
val = digitalRead(inPin); // read the input pin
if (val == HIGH){
Serial.print(val);
sendNotification("");
delay(3000);
val = LOW;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.