This commit is contained in:
@ -5,14 +5,14 @@ WiFiUDP udpClient;
|
|||||||
Syslog syslog(udpClient, SYSLOG_PROTO_IETF);
|
Syslog syslog(udpClient, SYSLOG_PROTO_IETF);
|
||||||
|
|
||||||
const int PIN_RELAY = D1;
|
const int PIN_RELAY = D1;
|
||||||
#define OUTPUT(x) digitalWrite(PIN_RELAY, x ? LOW : HIGH);
|
#define OUTPUT_SET(x) digitalWrite(PIN_RELAY, x ? LOW : HIGH);
|
||||||
int timer = 0;
|
int timer = 0;
|
||||||
HomieNode powerNode("power", "switch");
|
HomieNode powerNode("power", "switch");
|
||||||
|
|
||||||
bool powerStateHandler(const HomieRange& range, const String& value) {
|
bool powerStateHandler(const HomieRange& range, const String& value) {
|
||||||
if (value != "true" && value != "false") return false;
|
if (value != "true" && value != "false") return false;
|
||||||
bool on = (value == "true");
|
bool on = (value == "true");
|
||||||
OUTPUT(on);
|
OUTPUT_SET(on);
|
||||||
powerNode.setProperty("state").send(value);
|
powerNode.setProperty("state").send(value);
|
||||||
if(!on)
|
if(!on)
|
||||||
powerNode.setProperty("timer").send("0");
|
powerNode.setProperty("timer").send("0");
|
||||||
@ -29,14 +29,14 @@ bool powerTimerHandler(const HomieRange& range, const String& value) {
|
|||||||
powerNode.setProperty("timer").send(String(settimer));
|
powerNode.setProperty("timer").send(String(settimer));
|
||||||
powerNode.setProperty("state").send("on");
|
powerNode.setProperty("state").send("on");
|
||||||
Homie.getLogger() << "Power is on for " << settimer << "minutes" << endl;
|
Homie.getLogger() << "Power is on for " << settimer << "minutes" << endl;
|
||||||
OUTPUT(true);
|
OUTPUT_SET(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setupHandler() {
|
void setupHandler() {
|
||||||
pinMode(PIN_RELAY, OUTPUT);
|
pinMode(PIN_RELAY, OUTPUT);
|
||||||
OUTPUT(false);
|
OUTPUT_SET(false);
|
||||||
powerNode.setProperty("state").send("off");
|
powerNode.setProperty("state").send("off");
|
||||||
powerNode.setProperty("timer").send("0");
|
powerNode.setProperty("timer").send("0");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user