Wi-Fi Kontrollü
Çekmece Kilidi Çalışması’nda
Kullanılan Arduino kodları
aşağıdaki gibidir:
/*
SMART FURNITURE LOCK - AKILLI MOBİLYA KİLİDİ - ÖRNEK KOD ÇALIŞMASI
*/
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "FiberHGW_ZTHE6E_2.4GHz";
const char* password = "9sufxuJKgf";
int relay_pin = 15;
int blue_led = 2;
String lastpayload = "OFF";
String payload = "OFF";
void setup() {
Serial.println(payload);
Serial.println(lastpayload);
Serial.begin(115200);
pinMode (relay_pin, OUTPUT);
pinMode (blue_led, OUTPUT);
delay(2000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
http.begin("https://yasarseher.com/mobilock/mobilock.txt"); //Specify the URL
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
delay(100);
if (payload != lastpayload) {
if (payload == "ON") {
digitalWrite(relay_pin, LOW);
digitalWrite(blue_led, HIGH);
delay(100);
digitalWrite(relay_pin, HIGH);
digitalWrite(blue_led, LOW);
}
else
{
digitalWrite(relay_pin, HIGH);
digitalWrite(blue_led, LOW);
}
lastpayload = payload;
}
else {
digitalWrite(relay_pin, HIGH);
digitalWrite(blue_led, LOW);
}
}
else {
Serial.println("Error on HTTP request");
}
// payload = lastpayload;
Serial.println(lastpayload);
http.end(); //Free the resources
}
delay(500);
}
Bir yanıt yazın