Wi-Fi Üzerinden Kontrol Edilebilen
Röle / Fan / AC-DC Motor Örnek Kod Çalışması
aşağıdaki gibidir:
/*
Wi-Fi CONTROLLED RELAY / FAN / AC-DC MOTOR
||
Wİ-Fİ ÜZERİNDEN KONTROL EDİLEBİLEN RÖLE / FAN / AC-DC MOTOR Ö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;
void setup() {
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/f4n/f4n.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);
if (payload == "ON") {
digitalWrite(relay_pin, LOW);
digitalWrite(blue_led, HIGH);
}
else
{
digitalWrite(relay_pin, HIGH);
digitalWrite(blue_led, LOW);
}
}
else {
Serial.println("Error on HTTP request");
}
http.end(); //Free the resources
}
delay(1000);
}
Bir yanıt yazın