Created
March 21, 2017 15:25
-
-
Save ayublahsaya/918deee2abb5ecfa21049c3b8d73d754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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