homieiot / homie-esp8266

💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
http://homieiot.github.io/homie-esp8266
MIT License
1.36k stars 308 forks source link

The globalInputHandler not working #700

Open kartom opened 3 years ago

kartom commented 3 years ago

When assigning a global input handler with the following code:

void onHomieEvent(const HomieEvent& event) {
    if(event.type == HomieEventType::MQTT_READY) {
        //Update MQTT about current state when reconnecting
        nodes.setProperty("on").send(on? "true":"false");
    }
}

bool inputHandler(const HomieNode& node, const HomieRange& range, const String& property, const String& value)     {
    return false;
}

void setup() {
    Homie.onEvent(onHomieEvent);
    Homie.setGlobalInputHandler(inputHandler);
    Homie.setup();

This will cause the MQTT connection to be continuously connected / disconnected.

There is also wrong information in the documentation for the global input handler. According to the documentation is should be: bool globalInputHandler(const HomieNode& node, const String& property, const HomieRange& range, const String& value) but this is the correct declaration: bool globalInputHandler(const HomieNode& node, const HomieRange& range, const String& property, const String& value)

kartom commented 3 years ago

There is something fishy going on with my code, now i get the problem even when commenting out both the onEvent ant the setGlobalInputHandler. The documentation problem still exists though.

This is the output from the log:

 MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
✖ MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
✖ MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
✖ MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
✔ MQTT ready
Triggering MQTT_READY event...
〽 Sending statistics...
  • Interval: 65s (60s including 5s grace time)
  • Wi-Fi signal quality: 54%
  • Uptime: 210s
✖ MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
✖ MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
✔ MQTT ready
Triggering MQTT_READY event...
〽 Sending statistics...
  • Interval: 65s (60s including 5s grace time)
  • Wi-Fi signal quality: 58%
  • Uptime: 210s
✖ MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
✔ MQTT ready
Triggering MQTT_READY event...
〽 Sending statistics...
  • Interval: 65s (60s including 5s grace time)
  • Wi-Fi signal quality: 60%
  • Uptime: 210s
✖ MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
✖ MQTT disconnected, reason: 0
Triggering MQTT_DISCONNECTED event...
↕ Attempting to connect to MQTT...