Commit 7c421f58 by martin.slowinski

Upload New File

parent 6fe10f94
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
// Variables
byte pirPin = 13;
String mac = "Test";
void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);
WiFi.begin("e1s", "Edge123!@");
mac = WiFi.macAddress();
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.println("Waiting for connection");
}
Serial.println(mac);
}
void loop()
{
int isBusy = CheckIfBusy();
SendMessage(isBusy);
}
int CheckIfBusy()
{
int state1, state2, state3, state4, state5;
state1 = digitalRead(pirPin);
delay(2000);
state2 = digitalRead(pirPin);
delay(2000);
state3 = digitalRead(pirPin);
delay(2000);
state4 = digitalRead(pirPin);
delay(2000);
state5 = digitalRead(pirPin);
delay(2000);
byte val = (state1 + state2 + state3 + state4 + state5);
if (val > 2)
{
return 1;
}
else
{
return 0;
}
}
void SendMessage(int isBusy)
{
if (WiFi.status() == WL_CONNECTED)
{
String postLeft = "{\"sensorId\":\"";
String postMiddle = "\",\"isBusy\":\"";
String postRight = "\"}";
String post = postLeft + mac + postMiddle + isBusy + postRight;
HTTPClient http;
//http.begin("http://iot-challange.azurewebsites.net/api/status/write");
http.begin("http://10.0.100.8:5000/api/status/write");
http.addHeader("Content-Type", "application/json");
int httpCode = http.POST(post);
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
http.end();
}
else
{
Serial.println("Error in WiFi connection");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment