BenQ: Added power callback handling

This commit is contained in:
Nis Wechselberg 2017-03-30 14:50:35 +02:00
parent dff4191572
commit 42b9adf394

View file

@ -108,6 +108,18 @@ void incoming_mqtt(char* topic, byte* payload, unsigned int length) {
} }
if (strcmp(topic, mqtt_topic_power) == 0) { if (strcmp(topic, mqtt_topic_power) == 0) {
if (length == 1) {
if (DEBUGTOSERIAL) {
Serial.println("Setting new power state");
}
if ((char)payload[0] == '0') {
// Switch power off
Serial.print("\r*pow=off#\r");
} else {
// Switch power on
Serial.print("\r*pow=on#\r");
}
}
} }
} }
@ -121,7 +133,7 @@ void reconnect() {
Serial.print("Attempting MQTT connection..."); Serial.print("Attempting MQTT connection...");
} }
// Attempt to connect // Attempt to connect
if (client.connect(mqtt_device_name)) { if (client.connect(mqtt_device)) {
if (DEBUGTOSERIAL) { if (DEBUGTOSERIAL) {
Serial.println("connected"); Serial.println("connected");
} }
@ -139,7 +151,16 @@ void reconnect() {
} }
} }
void clearSerialInput() {
while(Serial.available() > 0) {
char t = Serial.read();
}
}
void updateLamptime() { void updateLamptime() {
// Clean input buffer
clearSerialInput();
// Write request to serial // Write request to serial
Serial.print("\r*ltim=?#\r"); Serial.print("\r*ltim=?#\r");
delay(250); delay(250);