diff --git a/docs/module_reference.md b/docs/module_reference.md index 68f60230..3805690b 100644 --- a/docs/module_reference.md +++ b/docs/module_reference.md @@ -653,6 +653,10 @@ The `disconnect()` method might be useful to access the other microcontroller on Note that the expander forwards all other method calls to the remote core module, e.g. `expander.info()`. +| Properties | Description | Data type | +| ------------------ | ------------------------------------------------------- | --------- | +| `last_message_age` | Time since last message from other microcontroller (ms) | `int` | + ## Proxy -- _This module is mainly for internal use with the expander module._ -- diff --git a/main/modules/expander.cpp b/main/modules/expander.cpp index 70660841..ba3c8bf0 100644 --- a/main/modules/expander.cpp +++ b/main/modules/expander.cpp @@ -12,6 +12,8 @@ Expander::Expander(const std::string name, const gpio_num_t enable_pin, MessageHandler message_handler) : Module(expander, name), serial(serial), boot_pin(boot_pin), enable_pin(enable_pin), message_handler(message_handler) { + this->properties["last_message_age"] = std::make_shared(); + serial->enable_line_detection(); if (boot_pin != GPIO_NUM_NC && enable_pin != GPIO_NUM_NC) { gpio_reset_pin(boot_pin); @@ -45,13 +47,14 @@ void Expander::step() { while (this->serial->has_buffered_lines()) { int len = this->serial->read_line(buffer); check(buffer, len); + this->last_message_millis = millis(); if (buffer[0] == '!' && buffer[1] == '!') { - /* Don't trigger keep-alive from expander updates */ - this->message_handler(&buffer[2], false, true); + this->message_handler(&buffer[2], false, true); // Don't trigger core keep-alive from expander broadcasts } else { echo("%s: %s", this->name.c_str(), buffer); } } + this->properties.at("last_message_age")->integer_value = millis_since(this->last_message_millis); Module::step(); } diff --git a/main/modules/expander.h b/main/modules/expander.h index dd88d05a..c86d6f65 100644 --- a/main/modules/expander.h +++ b/main/modules/expander.h @@ -8,6 +8,9 @@ class Expander; using Expander_ptr = std::shared_ptr; class Expander : public Module { +private: + unsigned long int last_message_millis = 0; + public: const ConstSerial_ptr serial; const gpio_num_t boot_pin;