Basic Module
This example shows the smallest useful ArmorLink module.
The module:
- Creates an ArmorLink module
- Enables ESP-NOW
- Exposes one Action
- Sends log messages
- Joins an ArmorLink network
For the conceptual overview, see Modules.
Complete Example
#include <ArmorLink.h>
ArmorLinkModule module(
"Helmet",
ArmorLinkModuleType::Helmet
);
void setup()
{
Serial.begin(115200);
delay(500);
module.actions()
.add("toggleEyes")
.label("Toggle Eyes")
.command("Eyes", "toggle")
.onExecute([]{
ArmorLink.info("Eyes toggled");
});
ArmorLinkOptions options;
options.enableGateway = false;
options.enableEspNow = true;
options.enableBle = false;
options.enableSerialLogging = true;
ArmorLink.begin(module, options);
ArmorLink.info("Helmet module started");
}
void loop()
{
ArmorLink.loop();
}
What This Example Does
This sketch creates a regular ArmorLink module named Helmet.
ArmorLinkModule module(
"Helmet",
ArmorLinkModuleType::Helmet
);
The module exposes one Action:
module.actions()
.add("toggleEyes")
.label("Toggle Eyes")
.command("Eyes", "toggle")
.onExecute([]{
ArmorLink.info("Eyes toggled");
});
When the module receives a matching Command, ArmorLink executes the Action callback.
For more information, see Actions.
Module Options
This example configures the module as a regular module.
options.enableGateway = false;
It enables ESP-NOW communication:
options.enableEspNow = true;
It disables BLE:
options.enableBle = false;
Regular modules usually do not need BLE because the ArmorLink App connects to the Gateway.
For more information, see ArmorLinkOptions.
Pairing
Before this module can communicate with the Gateway, it must be paired.
Start pairing on the Gateway:
start
List candidates:
candidates
Pair the module:
pair 1
For more information, see Pairing.
Triggering the Action
After pairing, another module or the ArmorLink App can trigger the Action by sending:
ArmorLink.sendCommand(
"Helmet",
"Eyes",
"toggle"
);
The Command is routed through the Gateway and delivered to the Helmet module.
For more information, see Commands.
Adding Configuration
A module can expose persistent configuration values.
int brightness = 100;
module.config()
.addInt("brightness", &brightness, 100)
.label("Brightness")
.section("LEDs")
.range(0, 255)
.step(1);
Configuration values are displayed in the ArmorLink App and persist automatically across reboots.
For more information, see Configuration.
Adding Telemetry
A module can publish live runtime data when requested by the ArmorLink App.
void sendBatteryTelemetry()
{
float voltage = 4.12f;
ArmorLink.sendTelemetry(
"battery",
"voltage",
voltage,
"V"
);
}
Telemetry is only transmitted when requested by the App.
For more information, see Telemetry.
Complete Example with Configuration
#include <ArmorLink.h>
ArmorLinkModule module(
"Helmet",
ArmorLinkModuleType::Helmet
);
int brightness = 100;
void setup()
{
Serial.begin(115200);
delay(500);
module.actions()
.add("toggleEyes")
.label("Toggle Eyes")
.command("Eyes", "toggle")
.onExecute([]{
ArmorLink.info("Eyes toggled");
});
module.config()
.addInt("brightness", &brightness, 100)
.label("Brightness")
.section("LEDs")
.range(0, 255)
.step(1);
ArmorLinkOptions options;
options.enableGateway = false;
options.enableEspNow = true;
options.enableBle = false;
options.enableSerialLogging = true;
ArmorLink.begin(module, options);
ArmorLink.info("Helmet module started");
}
void loop()
{
ArmorLink.loop();
}
Next Steps
Continue with: