Skip to main content

Basic Module

This example shows a regular ArmorLink 0.4.0 module that joins a Gateway-led network.

The module:

  • Exposes one Action
  • Exposes one persistent config value
  • Sends logs and optional telemetry through the Gateway
  • Does not expose BLE directly

For the conceptual overview, see Modules.

Complete Example

#include <ArmorLink.h>

ArmorLinkModule module(
"Helmet",
ArmorLinkModuleType::Helmet
);

bool eyesEnabled = false;
int brightness = 120;

void applyEyes()
{
ArmorLink.info(eyesEnabled ? "Eyes enabled" : "Eyes disabled");
}

void setup()
{
Serial.begin(115200);
delay(500);

module.profileTarget("muehliindustries.armorlink.helmet.v1");
module.profileName("Basic Helmet");

module.actions()
.add("toggleEyes")
.label("Toggle Eyes")
.section("Eyes")
.command("Eyes", "toggle")
.stylePrimary()
.onExecute([] {
eyesEnabled = !eyesEnabled;
applyEyes();
});

module.config()
.addInt("brightness", &brightness, 120)
.label("Brightness")
.section("Eyes")
.tooltip("Eye LED brightness.")
.range(0, 255)
.step(1)
.onIntChange([](int value) {
brightness = value;
ArmorLink.info("Brightness changed");
});

module.config()
.addBool("eyesEnabled", &eyesEnabled, false)
.label("On at Startup")
.section("Eyes")
.tooltip("Turns the eyes on automatically after startup.");

ArmorLinkOptions options;
options.nodeName = "Helmet";
options.enableGateway = false;
options.enableEspNow = true;
options.enableBle = false;
options.enableSerialCommands = true;
options.enableSerialLogging = true;
options.defaultLogTarget = "Chest";

ArmorLink.begin(module, options);

ArmorLink.info("Helmet module started");
}

void loop()
{
ArmorLink.loop();
}

Why BLE Is Disabled

Regular modules usually communicate through the Gateway. The App connects to the Gateway, and the Gateway routes commands/config requests to paired modules.

options.enableBle = false;

Use BLE on a regular module only when it should also be configurable directly over BLE.

defaultLogTarget

Remote logs and telemetry from a regular module need a Gateway target while routing is being established.

options.defaultLogTarget = "Chest";

Set this to the nodeName of your Gateway.

Pairing

Before the module can receive commands from the Gateway, pair it:

start
candidates
pair 1

If the module still remembers an old Gateway but the Gateway was reset, the Gateway emits module_pairing_required and the App asks whether pairing should be started.

Triggering the Action

After pairing, another node or the App can trigger:

ArmorLink.sendCommand("Helmet", "Eyes", "toggle");

Next Steps