Module Timeout Detection
This example demonstrates how a Gateway can react when a paired module goes offline.
Presence is Gateway-managed. Whenever a paired module sends valid traffic, the Gateway updates its last-seen timestamp. If the module stays silent longer than moduleTimeoutMs, the timeout hook runs and the App receives presence updates.
Complete Example
#include <ArmorLink.h>
ArmorLinkModule module(
"Chest",
ArmorLinkModuleType::Chest
);
void setup()
{
Serial.begin(115200);
ArmorLinkOptions options;
options.nodeName = "Chest";
options.enableGateway = true;
options.enableEspNow = true;
options.enableBle = true;
options.enableSerialMenu = true;
options.bleName = "ArmorLink Chest";
options.modulePresenceCheckIntervalMs = 5000;
options.moduleTimeoutMs = 30000;
ArmorLink.begin(module, options);
ArmorLink.setModuleTimeoutHook(
[](const ArmorLinkStoredPairedModule& module, uint32_t silentMs) {
Serial.printf(
"%s offline for %lu ms\n",
module.name,
silentMs
);
ArmorLink.warn(String(module.name) + " went offline");
});
}
void loop()
{
ArmorLink.loop();
}
What Happens
When a paired module exceeds the configured timeout:
- The Gateway marks the module offline.
- The timeout hook executes.
- The Gateway emits App-facing presence updates.
- The application can react locally.
Possible reactions:
- Display warning LEDs
- Trigger alarms
- Update displays
- Log diagnostic information
- Notify the App through remote logs
Choosing Timeout Values
Use short values while testing:
options.modulePresenceCheckIntervalMs = 5000;
options.moduleTimeoutMs = 30000;
Use longer values for battery-powered or quiet modules that do not send traffic frequently.