ratgdo / mqtt-ratgdo

ratgdo via mqtt
GNU General Public License v2.0
79 stars 18 forks source link

Why does sending a query command set all states to "unknown" #96

Closed xelwarto closed 2 hours ago

xelwarto commented 3 hours ago

Looking to understand why sending a query command initially sets all the states to "unknown":

if(command == "query"){
    Serial.println("MQTT: query");

    // Set all to unknown
    doorState = 0;
    lightState = 2;
    lockState = 2;
    motionState = 0;
    obstructionState = 2;

    if(controlProtocol == "secplus2"){
        getRollingCode("reboot2");
        transmit(txSP2RollingCode,SECPLUS2_CODE_LEN);
        delay(100);
    }
}

This results in the statusUpdateLoop sending a status message with an "unknown" state; once the state is updated, another status message is sent with the correct state.

QUEUE MSG ARRIVED [homegrg/gdohome/command] 
query
MQTT: query
rolling code for XXXXXXX 217|reboot2 : XXXXXXXXXXXXXXXXXX
Door state unknown
QUEUE MSG SENT [homegrg/gdohome/status/door] 
unknown
Light state unknown
QUEUE MSG SENT [homegrg/gdohome/status/light] 
unknown
Lock state unknown
QUEUE MSG SENT [homegrg/gdohome/status/lock] 
unknown
Obstruction status unknown
QUEUE MSG SENT [homegrg/gdohome/status/obstruction] 
unknown
Obstruction status clear
QUEUE MSG SENT [homegrg/gdohome/status/obstruction] 
clear
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX | STATUS: door:2 light:1 lock:0 obs:1
Door state closed
QUEUE MSG SENT [homegrg/gdohome/status/door] 
closed
Light state on
QUEUE MSG SENT [homegrg/gdohome/status/light] 
on
Lock state unlocked
QUEUE MSG SENT [homegrg/gdohome/status/lock] 
unlocked

Is there anything in the documentation which talks about this? It would appear any code would have to ignore messages which return with an "unknown" state; this just seems unnecessary.

PaulWieland commented 2 hours ago

It sets it to unknown so you have positive confirmation that the real status was returned by the GDO itself. Otherwise there is no way to confirm the GDO actually responded.

xelwarto commented 7 minutes ago

@PaulWieland - I understand the need to know if the GDO actually responded; is there a reason why that is not part of the gdoStateLoop function?