fix cmd handling
This commit is contained in:
parent
1e84da511c
commit
95c1e02048
13
src/main.cpp
13
src/main.cpp
|
@ -72,12 +72,13 @@ void setup() {
|
||||||
Homie_setBrand(FW_NAME);
|
Homie_setBrand(FW_NAME);
|
||||||
Homie.setLoopFunction(loopHandler);
|
Homie.setLoopFunction(loopHandler);
|
||||||
|
|
||||||
|
scaleNode.advertise("cmd").settable(cmdHandler); //function inputHandler gets called on new message on topic/input/set
|
||||||
scaleNode.advertise("human");
|
scaleNode.advertise("human");
|
||||||
scaleNode.advertise("spread");
|
scaleNode.advertise("spread");
|
||||||
scaleNode.advertise("raw");
|
scaleNode.advertise("raw");
|
||||||
scaleNode.advertise("max");
|
scaleNode.advertise("max");
|
||||||
|
|
||||||
scaleNode.advertise("cmd").settable(cmdHandler); //function inputHandler gets called on new message on topic/input/set
|
|
||||||
|
|
||||||
Homie.setup();
|
Homie.setup();
|
||||||
|
|
||||||
|
@ -282,9 +283,9 @@ bool cmdHandler(const HomieRange& range, const String& value) {
|
||||||
|
|
||||||
|
|
||||||
//boolean 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
|
if (scale.wait_ready_timeout(1000)) { //for non blocking mode
|
||||||
scale.set_scale(0);
|
scale.set_scale();
|
||||||
scale.tare();
|
scale.tare();
|
||||||
scaleNode.setProperty("cmd").send("tared");
|
scaleNode.setProperty("cmd").send("tared");
|
||||||
} else {
|
} else {
|
||||||
|
@ -292,21 +293,21 @@ bool cmdHandler(const HomieRange& range, const String& value) {
|
||||||
scaleNode.setProperty("cmd").send("HX711 not found");
|
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
|
if (scale.wait_ready_timeout(1000)) { //for non blocking mode
|
||||||
scaleNode.setProperty("cmd").send("adc="+scale.read_average(20));
|
scaleNode.setProperty("cmd").send("adc="+scale.read_average(20));
|
||||||
} else {
|
} else {
|
||||||
Serial.println("HX711 not found.");
|
Serial.println("HX711 not found.");
|
||||||
scaleNode.setProperty("cmd").send("HX711 not found");
|
scaleNode.setProperty("cmd").send("HX711 not found");
|
||||||
}
|
}
|
||||||
}if (value=="live") {
|
}else if (value=="live") {
|
||||||
livesend=!livesend;
|
livesend=!livesend;
|
||||||
if (livesend) {
|
if (livesend) {
|
||||||
scaleNode.setProperty("cmd").send("live data enabled");
|
scaleNode.setProperty("cmd").send("live data enabled");
|
||||||
}else{
|
}else{
|
||||||
scaleNode.setProperty("cmd").send("live data disabled");
|
scaleNode.setProperty("cmd").send("live data disabled");
|
||||||
}
|
}
|
||||||
}if (value=="off") {
|
}else if (value=="off") {
|
||||||
powerOff();
|
powerOff();
|
||||||
scaleNode.setProperty("cmd").send("shutting down");
|
scaleNode.setProperty("cmd").send("shutting down");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue