Last active
April 11, 2024 17:16
-
-
Save SiddheshNan/892c06af1fa7ae3f5d9f870ba516c98c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ThingESP.h> | |
ThingESP8266 thing("username", "project_name", "device_credentials"); | |
int LED = LED_BUILTIN; | |
unsigned long previousMillis = 0; | |
const long INTERVAL = 6000; | |
void setup() | |
{ | |
Serial.begin(115200); | |
pinMode(LED, OUTPUT); | |
thing.SetWiFi("wifi_ssid", "wifi_password"); | |
thing.initDevice(); | |
} | |
String HandleResponse(String query) | |
{ | |
if (query == "led on") { | |
digitalWrite(LED, 0); | |
return "Done: LED Turned ON"; | |
} | |
else if (query == "led off") { | |
digitalWrite(LED, 1); | |
return "Done: LED Turned OFF"; | |
} | |
else if (query == "led status") | |
return digitalRead(LED) ? "LED is OFF" : "LED is ON"; | |
else return "Your query was invalid.."; | |
} | |
void loop() | |
{ | |
/* if (millis() - previousMillis >= INTERVAL) { | |
previousMillis = millis() ; | |
String msg = digitalRead(LED) ? "LED is OFF" : "LED is ON"; | |
thing.sendMsg("phone_num", msg); | |
}*/ | |
thing.Handle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment