-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkos_02.ino
55 lines (44 loc) · 1.29 KB
/
kos_02.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>
#include "DHT.h"
#define DHTPIN D5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define USERNAME "............."
#define DEVICE_ID ".........."
#define DEVICE_CREDENTIAL "............."
#define SSID ".........."
#define SSID_PASSWORD "............."
#define relay_lamp D6
#define relay_doorLock D7
#define doorSensor D0
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void setup() {
dht.begin();
pinMode(doorSensor, INPUT_PULLUP);
pinMode(relay_lamp , OUTPUT);
pinMode(relay_doorLock, OUTPUT);
thing.add_wifi(SSID, SSID_PASSWORD);
// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
thing["Lamp All"] << digitalPin(relay_lamp);
thing["Door Lock"] << digitalPin(relay_doorLock);
thing["Sensor Temp & Humd"] >> [](pson & out) {
out["humidity"] = dht.readHumidity();
out["celsius"] = dht.readTemperature();
};
thing["Door Sensor"] >> [](pson & out) {
int door = digitalRead(doorSensor);
String doorState;
if (door == 1) {
doorState = "Door Open";
}
else {
doorState = "Door Close";
}
out["Door State"] = doorState;
};
}
void loop() {
thing.handle();
}