Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266HTTPClient.h>
- #include<ArduinoJson.h>
- #include <Servo.h>
- const char * ssid = "maidiee1234@unifi";
- const char * password = "napsiah1";
- const char * host = "maker.ifttt.com";
- const int httpsPort = 443;
- Servo servo;
- int pos = 0;
- void setup() {
- Serial.begin(115200);
- Serial.print("Connecting to wifi");
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("\r\nWiFi connected.");
- Serial.println("access point:");
- Serial.println(WiFi.SSID());
- Serial.println("ip address:");
- Serial.println(WiFi.localIP());
- servo.attach(D8); //D8
- // wait for WiFi connection
- }
- void loop() {
- if (WiFi.status() == WL_CONNECTED) {
- HTTPClient http;
- WiFiClientSecure client;
- http.begin("https://fully-grown-apprent.000webhostapp.com/getdata.php", "42 E9 F5 F9 30 21 14 CD 75 A1 41 EF 39 33 E8:D4 C7 97 B9 7C");
- int httpCode = http.GET();
- if (httpCode > 0) { //Check for the returning code
- String payload = http.getString();
- Serial.println(httpCode);
- Serial.println(payload);
- // Parse JSON
- StaticJsonBuffer < 500 > jsonBuffer;
- JsonObject & json_parsed = jsonBuffer.parseObject(payload);
- if (!json_parsed.success()) {
- Serial.println("parseObject() failed");
- Serial.println("No data");
- return;
- }
- // Fetch values.
- // Most of the time, you can rely on the implicit casts.
- // In other case, you can do root["time"].as<long>();
- int status = json_parsed["status"];
- Serial.print("Status = ");
- Serial.println(status);
- http.end();
- int value = LOW;
- if (status == 0) {
- Serial.println("No");
- //http request to send Telegram alert to phone
- http.begin("https://maker.ifttt.com/trigger/passwrong/with/key/xxxxxxxxxxxxxxxxx", "AA 75 CB 41 2E D5
- F9 97 FF 5D A0 8B 7D AC 12 21 08 4B 00 8C");
- int httpCode = http.GET();
- http.end();
- closeDoor();
- value = HIGH;
- delay(3000);
- } else if (status == 1) {
- Serial.println("Yes");
- openDoor();
- delay(3000);
- }
- } else {
- Serial.println("Error on HTTP request");
- }
- //http.end();
- }
- delay(10000);
- }
- void openDoor() {
- for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
- // in steps of 1 degree
- servo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- }
- void closeDoor() {
- for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
- servo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement