Skip to content

Instantly share code, notes, and snippets.

@SiddheshNan
Created March 27, 2020 09:39
Show Gist options
  • Save SiddheshNan/2f15419a2422bca70c922804ef71eb58 to your computer and use it in GitHub Desktop.
Save SiddheshNan/2f15419a2422bca70c922804ef71eb58 to your computer and use it in GitHub Desktop.
#define _DEBUG_
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>
#define USERNAME ""
#define DEVICE_ID ""
#define DEVICE_CREDENTIAL ""
#define SSID ""
#define SSID_PASSWORD ""
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
int device_1 = 16;
int device_2 = 5;
int device_3 = 4;
int device_4 = 14;
String device1_stat;
String device2_stat;
String device3_stat;
String device4_stat;
void setup() {
Serial.begin(115200);
pinMode(device_1, OUTPUT);
pinMode(device_2, OUTPUT);
pinMode(device_3, OUTPUT);
pinMode(device_4, OUTPUT);
delay(1000);
thing.add_wifi(SSID, SSID_PASSWORD);
thing["Device1"] << digitalPin(device_1);
thing["Device2"] << digitalPin(device_2);
thing["Device3"] << digitalPin(device_3);
thing["Device4"] << digitalPin(device_4);
thing["device1_stat"] >> outputValue(device1_stat);
thing["device2_stat"] >> outputValue(device2_stat);
thing["device3_stat"] >> outputValue(device3_stat);
thing["device4_stat"] >> outputValue(device4_stat);
}
void loop() {
//----------------
if (digitalRead(device_1) == 1) {
device1_stat = "ON";
}
if (digitalRead(device_1) == 0) {
device1_stat = "OFF";
}
//----------------
if (digitalRead(device_2) == 1) {
device2_stat = "ON";
}
if (digitalRead(device_2) == 0) {
device2_stat = "OFF";
}
//----------------
if (digitalRead(device_3) == 1) {
device3_stat = "ON";
}
if (digitalRead(device_3) == 0) {
device3_stat = "OFF";
}
//----------------
if (digitalRead(device_4) == 1) {
device4_stat = "ON";
}
if (digitalRead(device_4) == 0) {
device4_stat = "OFF";
}
thing.handle();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment