Integrating 24GHz Presence Sensors into MeshCore for Off-Grid Monitoring
MeshCore Blog by scottpowell

Integrating 24GHz Presence Sensors into MeshCore for Off-Grid Monitoring

This article explores how cost-effective 24GHz presence sensors can be integrated into the decentralized MeshCore mesh network. The objective is to create a system for off-grid communication and monitoring, which can be used, for example, for motion detection in remote areas.

The experiments are based on commercially available 24GHz radar sensors of type LD2410S, which can be sourced from platforms like AliExpress.

Hardware Connection

A Heltec StickLite development board was used for these experiments. Although it is an older model, it is more than adequate for this purpose. However, the underlying code example is flexible and can be adapted to any of the over 100 boards currently supported by MeshCore.

Wiring the LD2410S sensor to the main board is straightforward. Only four connections are required:

Sensor -> Main board

  • 3V3 -> any of the 3.3V power pins
  • GND -> any of the GND pins
  • OT1 -> Serial RX
  • RX -> Serial TX
The optional OT2 pin of the sensor can be connected to a digital input pin on the main board. This can be used as an interrupt for a "wake-up" function to save power in sleep mode.

Firmware Implementation

Integrating specific sensors requires firmware customization. Since the variety of sensors and their behaviors is too vast to offer a universal firmware, dedicated programming is necessary.

To simplify this process, the MeshCore project provides a simple_sensor sketch as a template. For the LD2410S motion sensor, a prepared implementation is already available in a separate repository.

To use this code, clone the repository:

CLI
https://github.com/ripplebiz/MeshCore-sensor-playground

Then, check out the dev branch and open the project in Visual Studio Code with the PlatformIO extension installed. The specific target build is configured for Heltec_StickLite_Sensor.

A detailed overview of the changes (diffs/commits) for this motion sensor code is available at the following link: https://github.com/meshcore-dev/MeshCore/compare/dev...ripplebiz:MeshCore-sensor-playground:dev

The implementation includes a custom MotionSensorManager class, which encapsulates all management of the LD2410S sensor. The querySensors() method collects three telemetry values:

CLI
bool MotionSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
  telemetry.addSwitch(TELEM_CHANNEL_SELF, _armed ? 1 : 0);
  telemetry.addPresence(TELEM_CHANNEL_SELF, ld2410s.isMotionDetected() ? 1 : 0);
  telemetry.addDistance(TELEM_CHANNEL_SELF, ((float)ld2410s.getDistance()) / 100.0f );  // convert to meters
  return true;
}

These values are transmitted over the MeshCore network in addition to the board's battery voltage.

sensor telemetry

Alert Functions

The example firmware also generates alerts when the sensor is "armed" and isMotionDetected() is true. This is implemented in the main.cpp module under /examples/simple_sensor/:

CLI
Trigger presence_alert, critical_batt;
TimeSeriesData  battery_data;

void onSensorDataRead() override {
  float batt_voltage = getVoltage(TELEM_CHANNEL_SELF);

  battery_data.recordData(getRTCClock(), batt_voltage);   // record battery
  alertIf(batt_voltage < 3.4f, critical_batt, HIGH_PRI_ALERT, "Battery is critical!");
  alertIf(sensors.isArmed() && sensors.isMotionDetected(), LOW_PRI_ALERT, "Motion detected!");
}

These alerts are managed by the underlying SensorMesh class. It is responsible for dispatching a MeshCore text DM (Direct Message) to all registered users in the ACL (Access Control List) who are subscribed to alerts. Users logging in with the admin password automatically receive this ACL permission.

Recipients will then see an unread message counter and, if configured, receive an alert sound.

app sensors

As a visual cue, the Ripple firmware (a specific MeshCore firmware variant) renders the Home grid cell with an orange border when the sensor is in the "armed" state, allowing for a quick overview of the sensor status. Additionally, the last telemetry value (in this case, the distance value) is displayed in the cell.

Arming and Disarming the Sensor

The example firmware extends the CLI (Command Line Interface) with specific commands to arm (arm) and disarm (disarm) the sensor. These commands are also handled in the main.cpp module:

CLI
bool handleCustomCommand(uint32_t sender_timestamp, char* command, char* reply) override {
  if (strcmp(command, "disarm") == 0) {    // example 'custom' command handling
    sensors.setArmed(false);
    strcpy(reply, "OK - now disarmed");
    return true;   // handled
  }
  if (strcmp(command, "arm") == 0) {    // example 'custom' command handling
    sensors.setArmed(true);
    strcpy(reply, "OK - now armed");
    return true;   // handled
  }
  return false;  // not handled
}

Conclusion

This type of node with an integrated motion sensor represents a valuable addition to the MeshCore ecosystem. The ability to operate these sensors in weatherproof enclosures with solar panels opens up numerous applications, such as intruder detection in remote areas. Thanks to MeshCore's open-source approach, further customizations and extensions are flexibly implementable.

Original on blog.meshcore.io →