Created
May 18, 2018 19:56
-
-
Save rahul-thakoor/de4c47b7cbbce49976cc54f6fe89bfae to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <WiFiClient.h> | |
#include <Thing.h> | |
#include <WebThingAdapter.h> | |
const char* ssid = <>; | |
const char* password = <>; | |
const int lampPin = 13; | |
WebThingAdapter adapter("esp8266"); | |
ThingDevice lamp("lamp", "Devcon2018 Demo Lamp", "onOffLight"); | |
ThingProperty lampOn("on", "Whether the lamp is turned on", BOOLEAN); | |
//ThingProperty lampLevel("level", "The level of light from 0-100", NUMBER); | |
void setup() { | |
pinMode(lampPin, OUTPUT); | |
digitalWrite(lampPin, HIGH); | |
analogWriteRange(255); | |
Serial.begin(115200); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, password); | |
Serial.println(""); | |
// Wait for connection | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.print("Connected to "); | |
Serial.println(ssid); | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); | |
lamp.addProperty(&lampOn); | |
//lamp.addProperty(&lampLevel); | |
adapter.addDevice(&lamp); | |
adapter.begin(); | |
Serial.println("HTTP server started"); | |
} | |
void loop() { | |
adapter.update(); | |
if (lampOn.getValue().boolean) { | |
digitalWrite(lampPin, HIGH); | |
} else { | |
digitalWrite(lampPin, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment