Zum Hauptinhalt springen

Erstes Modul

Ein Module ist ein ESP32-basiertes Subsystem, das an einem ArmorLink-Netzwerk teilnimmt.

Bevor ein Module mit anderen Modules kommunizieren kann, muss es mit einem Gateway gekoppelt werden.

Weitere Informationen findest du unter Modules.

Was du bauen wirst

In dieser Anleitung erstellst du ein minimales ArmorLink Module.

Das Module wird:

  • Run ArmorLink
  • Connect through ESP-NOW
  • Expose one Action
  • Be pairable with a Gateway

Neuen Sketch erstellen

Start with a new Arduino sketch.

#include <ArmorLink.h>

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

void toggleFaceplate()
{
ArmorLink.info("Toggle faceplate");
}

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

module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate")
.command("Facemask", "toggle")
.onExecute([]{
toggleFaceplate();
});

ArmorLinkOptions options;
options.enableGateway = false;
options.enableEspNow = true;
options.enableBle = false;

ArmorLink.begin(module, options);

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

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

Lade den Sketch auf deinen ESP32 hoch.

Modul verstehen

Modulname

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

The module name identifies this module inside the ArmorLink network.

Module names should be unique.

Commands use this name as the target.

Modultyp

ArmorLinkModuleType::Helmet

The module type is descriptive.

It helps the ArmorLink App organize and identify modules.

It does not affect routing or behavior.

Regulärer Modulmodus

This module is not the Gateway.

options.enableGateway = false;

A regular module communicates through the Gateway.

It can:

  • Receive Commands
  • Execute Actions
  • Send Commands
  • Expose Configuration
  • Publish Telemetry
  • Send Remote Logs when requested

ESP-NOW

options.enableEspNow = true;

ESP-NOW is required for communication between modules and the Gateway.

BLE

options.enableBle = false;

Regular modules usually do not need BLE.

The ArmorLink App connects to the Gateway, not directly to each individual module.

Action definieren

Actions expose functionality through ArmorLink.

module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate")
.command("Facemask", "toggle")
.onExecute([]{
toggleFaceplate();
});

This Action reacts to:

  • Entity: Facemask
  • Command: toggle

When the module receives a matching Command, ArmorLink calls onExecute().

Weitere Informationen findest du unter Actions.

Modul koppeln

Before the module can participate in the network, it must be paired with a Gateway.

  1. Upload and start the Gateway sketch
  2. Upload and start this module sketch
  3. Start pairing on the Gateway
  4. Accept the module

Pairing über Serial

On the Gateway Serial Monitor:

start

Then list candidates:

candidates

You should see the module:

1) Helmet | Helmet | 34:85:18:12:34:56

Accept it:

pair 1

Check paired modules:

modules

Weitere Informationen findest du unter Pairing.

Command an das Modul senden

Once paired, another module can send a Command to the Helmet module:

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

The Command is routed through the Gateway.

The Helmet module receives it and executes the matching Action.

Weitere Informationen findest du unter Commands.

Commands aus lokaler Logik senden

A module can also send Commands from local firmware logic.

Example:

void btn1_handleClick()
{
ArmorLink.info("Button clicked");

ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
}

The button handler is normal firmware logic.

The Command is the ArmorLink message sent through the network.

Konfiguration hinzufügen

Modules can expose persistent settings.

Example:

int brightness = 100;

module.config()
.addInt("brightness", &brightness, 100)
.label("Brightness")
.section("LEDs")
.range(0, 255)
.step(1);

Configuration values are stored locally on the module and can be changed through the ArmorLink App.

No reboot is required when values are changed.

Weitere Informationen findest du unter Configuration.

Telemetry hinzufügen

Modules can publish live runtime data when requested by the ArmorLink App.

Example:

void sendBatteryTelemetry()
{
float voltage = 4.12f;

ArmorLink.sendTelemetry(
"battery",
"voltage",
voltage,
"V"
);
}

Telemetry is only transmitted when requested by the App.

Weitere Informationen findest du unter Telemetry.

Vollständiges Beispiel mit Konfiguration

#include <ArmorLink.h>

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

int brightness = 100;

void toggleFaceplate()
{
ArmorLink.info("Toggle faceplate");
}

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

module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate")
.command("Facemask", "toggle")
.onExecute([]{
toggleFaceplate();
});

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;

ArmorLink.begin(module, options);

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

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

Nächste Schritte

You now have a basic ArmorLink module.

Continue with: