ArmorLink Runtime
The ArmorLink runtime is the central entry point used by a sketch to start and update ArmorLink.
It connects an ArmorLinkModule with ArmorLinkOptions and provides runtime functions such as command sending and logging.
For more information about options, see ArmorLinkOptions.
Basic Usage
A typical ArmorLink sketch initializes the runtime in setup() and updates it in loop().
#include <ArmorLink.h>
ArmorLinkModule module("Helmet", ArmorLinkModuleType::Helmet);
ArmorLinkRuntime ArmorLink;
void setup()
{
Serial.begin(115200);
ArmorLinkOptions options;
options.enableEspNow = true;
ArmorLink.begin(module, options);
}
void loop()
{
ArmorLink.loop();
}
begin(...)
Initializes ArmorLink for a module.
ArmorLink.begin(module, options);
begin(...) connects the runtime to the module definition and applies the selected runtime options.
This is where ArmorLink starts the enabled subsystems such as ESP-NOW, BLE or Gateway functionality.
Example:
ArmorLinkModule module("Chest", ArmorLinkModuleType::Chest);
ArmorLinkRuntime ArmorLink;
void setup()
{
Serial.begin(115200);
ArmorLinkOptions options;
options.enableGateway = true;
options.enableEspNow = true;
options.enableBle = true;
options.enableSerialMenu = true;
ArmorLink.begin(module, options);
}
For more information about modules, see ArmorLinkModule.
loop()
Updates the ArmorLink runtime.
ArmorLink.loop();
loop() should be called continuously from the Arduino loop() function.
It allows ArmorLink to process communication, routing, pairing, logging, telemetry and other runtime tasks.
Example:
void loop()
{
ArmorLink.loop();
// Your application logic can run here as well.
}
Call ArmorLink.loop() regularly.
Blocking code, long delays or slow loops may affect communication and responsiveness.
sendCommand(...)
Sends a Command through the ArmorLink network.
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
A Command contains:
- Target module
- Entity
- Command
Commands are routed through the Gateway and may trigger matching Actions on the target module.
For more information, see Commands.
broadcastCommand(...)
Sends a Command to all modules.
ArmorLink.broadcastCommand(
"Flaps",
"toggle"
);
A Broadcast Command contains:
- Entity
- Command
The target is automatically treated as all modules.
Any module with a matching Action can react to the Broadcast Command.
Example matching Action:
module.actions()
.add("toggleFlaps")
.label("Toggle Flaps")
.command("Flaps", "toggle")
.onExecute([]{
toggleFlaps();
});
For more information, see Commands.
Sending Commands from Application Logic
Commands are often sent from normal firmware code such as button handlers, sensor events or timers.
Example:
void btn1_handleClick()
{
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
}
The button handler itself is application logic.
The Command is the ArmorLink message sent to another module.
For more information about this separation, see Modules.
debug(...)
Writes a debug message through ArmorLink logging.
ArmorLink.debug("Opening helmet");
Depending on the runtime options and App state, log messages may be printed locally through Serial and optionally forwarded to the ArmorLink App through Remote Logging.
For more information, see Remote Logging.
Gateway Runtime Behavior
When enableGateway is enabled, the runtime also handles Gateway responsibilities.
ArmorLinkOptions options;
options.enableGateway = true;
Gateway behavior includes:
- Command routing
- Module discovery
- Pairing
- Module presence management
- BLE communication with the ArmorLink App, when enabled
For more information, see Gateway.
Regular Module Runtime Behavior
When enableGateway is disabled, the runtime behaves as a regular module.
ArmorLinkOptions options;
options.enableGateway = false;
A regular module can:
- Send Commands
- Receive Commands
- Execute Actions
- Expose Configuration
- Publish Telemetry when requested
- Send Remote Logs when requested
For more information, see Modules.
Summary
The ArmorLink runtime is responsible for running ArmorLink inside an Arduino sketch.
Most sketches use the runtime through:
ArmorLink.begin(module, options)ArmorLink.loop()ArmorLink.sendCommand(...)ArmorLink.broadcastCommand(...)ArmorLink.debug(...)
begin(...) initializes ArmorLink.
loop() keeps ArmorLink running.
sendCommand(...) sends Commands to a specific target module.
broadcastCommand(...) sends Commands to all modules.
debug(...) writes diagnostic output.