Hi All,
I’m trying out a simple thing. Using this ESP8266 Witty Wifi Cloud board to control a 1CH low level trigger relay, using Thinger app.
Here’s the code I wrote for the same:
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h> //THINGER.IO library
// Your WiFi credentials.
const char ssid[] = "xxxxxxxxxx";
const char pass[] = "yyyyyyyyy";
int led = 13;
int relay = 5;
ThingerESP8266 thing("myUser", "abcdefg", "xxxxyyyy");
void setup()
{
// Debug console
Serial.begin(9600);
thing.add_wifi(ssid, pass);
pinMode(led, OUTPUT);
thing["LED"] << [](pson & in) {
if (in.is_empty()) {
in = (bool) digitalRead(led);
}
else {
digitalWrite(led, in ? HIGH : LOW);
}
};
pinMode(relay, OUTPUT);
thing["RELAY"] << [](pson & in) {
if (in.is_empty()) in = (bool) digitalRead(relay);
else digitalWrite(relay, in ? HIGH : LOW);
};
// LDR resource
thing["LUX"] >> outputValue(analogRead(A0));
}
void loop()
{
thing.handle();
}
With this code, I can control the the LED On/Off, and I can see the value of LDR everytime I refresh on the mobile app. So I know the connection is proper. But the relay stays ON all the time, and doesn’t switch Off/On when switching from the App. (I’ve connected the relay VCC and GND to an external USB power, and the IN pin to the GPIO5 on the ESP8266 Witty Wifi board.)
Any ideas, on how to get the relay to work?