Skip to main content

Telemetry Example

This example shows how a module can publish live telemetry values to the ArmorLink App.

Telemetry is useful for runtime data such as:

  • Battery voltage
  • Battery percentage
  • Temperature
  • Sensor values
  • System status

Telemetry is only transmitted when requested by the ArmorLink App.

For the conceptual overview, see Telemetry.

What This Example Does

This module:

  • Creates a regular ArmorLink module
  • Sends battery voltage telemetry
  • Sends battery percentage telemetry
  • Uses telemetry only when requested by the App
  • Avoids unnecessary ESP-NOW traffic
Module
|
v
Gateway
|
v
ArmorLink App

Complete Example

#include <ArmorLink.h>

ArmorLinkModule module(
"Battery Module",
ArmorLinkModuleType::Generic
);

const int BATTERY_PIN = 34;

float readBatteryVoltage()
{
int raw = analogRead(BATTERY_PIN);

// Example conversion only.
// Adjust this formula for your voltage divider and ADC setup.
float adcVoltage = (raw / 4095.0f) * 3.3f;
float batteryVoltage = adcVoltage * 2.0f;

return batteryVoltage;
}

float calculateBatteryPercent(float voltage)
{
// Simple example mapping for a single Li-Ion cell.
// Adjust this for your battery chemistry and voltage range.
const float minVoltage = 3.3f;
const float maxVoltage = 4.2f;

float percent = (voltage - minVoltage) / (maxVoltage - minVoltage) * 100.0f;

if (percent < 0.0f) {
percent = 0.0f;
}

if (percent > 100.0f) {
percent = 100.0f;
}

return percent;
}

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

pinMode(BATTERY_PIN, INPUT);

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

ArmorLink.begin(module, options);

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

void loop()
{
ArmorLink.loop();

sendBatteryTelemetry();

delay(500);
}

void sendBatteryTelemetry()
{
float voltage = readBatteryVoltage();
float percent = calculateBatteryPercent(voltage);

ArmorLink.telemetryGroup("battery", "main")
.value("voltage", voltage)
.value("percent", percent)
.unit("V")
.send();
}

On-Demand Telemetry

Telemetry is not continuously broadcast.

Even though this example calls sendBatteryTelemetry() repeatedly, ArmorLink only transmits telemetry when telemetry is enabled by the ArmorLink App.

void loop()
{
ArmorLink.loop();

sendBatteryTelemetry();

delay(500);
}

If telemetry is disabled in the App, the module does not continuously send telemetry traffic.

tip

You can call telemetry functions regularly from your firmware.

ArmorLink decides internally whether telemetry should actually be transmitted.

Sending a Single Telemetry Value

Use sendTelemetry(...) to send a single value.

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

Parameters:

ParameterExampleDescription
GroupbatteryLogical telemetry group
NamevoltageName of the telemetry value
Value4.12Numeric runtime value
UnitVOptional display unit

Sending Multiple Values

Use telemetryGroup(...) when multiple related values should be sent together.

ArmorLink.telemetryGroup("battery", "main")
.value("voltage", voltage)
.value("percent", percent)
.unit("V")
.send();

This sends a telemetry object containing both values.

Gateway Behavior

If this module is a regular module, telemetry is sent to the Gateway and forwarded to the ArmorLink App.

Battery Module
|
v
Gateway
|
v
ArmorLink App

If the module itself is the Gateway, telemetry is sent directly to the App over BLE.

Example: Temperature Telemetry

float readTemperature()
{
return 24.5f;
}

void sendTemperatureTelemetry()
{
float temperature = readTemperature();

ArmorLink.sendTelemetry(
"environment",
"temperature",
temperature,
"C"
);
}

Example: Runtime Status

void sendStatusTelemetry()
{
ArmorLink.telemetryGroup("system", "status")
.value("uptimeSeconds", millis() / 1000.0f)
.value("freeHeap", ESP.getFreeHeap())
.send();
}

Telemetry vs Logging

Telemetry should be used for structured runtime values.

Examples:

  • Battery voltage
  • Temperature
  • Sensor readings
  • Runtime status

Logging should be used for developer-focused diagnostic messages.

Examples:

ArmorLink.debug("Button pressed");
ArmorLink.warn("Battery voltage low");

For more information, see Remote Logging.

Next Steps

Continue with: