fix cmd handling

This commit is contained in:
interfisch 2021-02-22 20:15:25 +01:00
parent 1e84da511c
commit 95c1e02048
1 changed files with 7 additions and 6 deletions

View File

@ -72,12 +72,13 @@ void setup() {
Homie_setBrand(FW_NAME);
Homie.setLoopFunction(loopHandler);
scaleNode.advertise("cmd").settable(cmdHandler); //function inputHandler gets called on new message on topic/input/set
scaleNode.advertise("human");
scaleNode.advertise("spread");
scaleNode.advertise("raw");
scaleNode.advertise("max");
scaleNode.advertise("cmd").settable(cmdHandler); //function inputHandler gets called on new message on topic/input/set
Homie.setup();
@ -282,9 +283,9 @@ bool cmdHandler(const HomieRange& range, const String& value) {
//boolean value
if (value=="reset") {
if (value=="reset") { //tares and resets calibration value. needed to prepare for calibration
if (scale.wait_ready_timeout(1000)) { //for non blocking mode
scale.set_scale(0);
scale.set_scale();
scale.tare();
scaleNode.setProperty("cmd").send("tared");
} else {
@ -292,21 +293,21 @@ bool cmdHandler(const HomieRange& range, const String& value) {
scaleNode.setProperty("cmd").send("HX711 not found");
}
}if (value=="adc") {
}else if (value=="adc") { //get raw value. use "reset" first. then adc to get value for calibration to enter in SCALE_CALIBRATION
if (scale.wait_ready_timeout(1000)) { //for non blocking mode
scaleNode.setProperty("cmd").send("adc="+scale.read_average(20));
} else {
Serial.println("HX711 not found.");
scaleNode.setProperty("cmd").send("HX711 not found");
}
}if (value=="live") {
}else if (value=="live") {
livesend=!livesend;
if (livesend) {
scaleNode.setProperty("cmd").send("live data enabled");
}else{
scaleNode.setProperty("cmd").send("live data disabled");
}
}if (value=="off") {
}else if (value=="off") {
powerOff();
scaleNode.setProperty("cmd").send("shutting down");
} else {