Plugin development

MeshCore plugin development

Build custom modules and extend MeshCore functionality with your own plugins

What is MeshCore plugin development?

MeshCore features a modular plugin architecture enabling developers to extend mesh network functionality without modifying core firmware. With plugins you can add custom features such as integrating sensors, logging data, calling external APIs, and considerably more.

The plugin API provides hooks into the firmware lifecycle, allowing you to react to events such as messages received, nodes detected, telemetry updates, and routing decisions. This renders MeshCore exceptionally flexible for specific use cases.

Whether you want to connect a weather station, build an automatic emergency alert system, or create custom visualisations, MeshCore plugins make it achievable. This guide demonstrates how to commence plugin development.

Plugin architecture overview

MeshCore plugins are based on an event-driven architecture with clearly defined interfaces

Plugin manifest

Every plugin begins with a manifest file defining metadata and capabilities:

plugin.json with name, version, author, and dependencies

Event handlers

Plugins register handlers for specific events in the mesh:

onMessageReceived(), onNodeDetected(), onRouteUpdated()

State management

Plugins can store persistent state in the firmware:

plugin.setState(), plugin.getState(), automatic persistence

API integration

Access to MeshCore core functionality via plugin API:

sendMessage(), getNodes(), getRoutes(), getTelemetry()

Plugin development step by step

From setting up development environment to deploying your first plugin

1

Step 1: set up development environment

Clone the MeshCore repository and set up the build tools:

git clone https://github.com/meshcore-dev/MeshCore.git
cd MeshCore
git submodule update --init --recursive
pip install platformio
pio run
2

Step 2: create plugin skeleton

Create a new plugin folder with the basic files:

mkdir -p src/plugins/myPlugin
touch src/plugins/myPlugin/plugin.json
touch src/plugins/myPlugin/myPlugin.h
touch src/plugins/myPlugin/myPlugin.cpp
3

Step 3: configure plugin manifest

Define your plugin metadata in plugin.json:

{\n "name": "MyPlugin",\n "version": "1.0.0",\n "author": "Your Name",\n "description": "Custom plugin",\n "dependencies": ["core", "radio"],\n "capabilities": ["messaging", "telemetry"]\n}
4

Step 4: implement plugin logic

Write your plugin code in C++ and implement the event handlers you require. Register callbacks for events such as messages received, nodes detected, or telemetry updates.

5

Step 5: build and test

Compile the firmware with your plugin and flash to a test device. Test your functionality thoroughly and debug any issues with serial monitor.

Example: temperature sensor plugin

A simple plugin that reads a DHT22 sensor and transmits temperature via mesh

#include "myPlugin.h"\n#include <DHT.h>\n\n#define DHT_PIN 4\n#define DHT_TYPE DHT22\nDHT dht(DHT_PIN, DHT_TYPE);\n\nvoid MyPlugin::init() {\n dht.begin();\n Log.info("MyPlugin initialised");\n}\n\nvoid MyPlugin::loop() {\n static unsigned long lastRead = 0;\n if (millis() - lastRead > 60000) { // Every minute\n float temp = dht.readTemperature();\n float humidity = dht.readHumidity();\n \n if (!isnan(temp) && !isnan(humidity)) {\n String payload = "T:" + String(temp, 1) + "C H:" + String(humidity, 1) + "%";\n MeshCore.sendMessage(payload, BROADCAST_ADDR);\n Log.info("Sent: " + payload);\n }\n lastRead = millis();\n }\n}\n\nvoid MyPlugin::onMessageReceived(MeshMessage* msg) {\n if (msg->payload.startsWith("TEMP_REQUEST")) {\n float temp = dht.readTemperature();\n MeshCore.sendMessage("T:" + String(temp, 1) + "C", msg->sender);\n }\n}

How does this work?

This plugin reads temperature and humidity from a DHT22 sensor every minute and broadcasts it via the mesh network. It also responds to "TEMP_REQUEST" messages by immediately sending a temperature reading back to the requester.

Popular plugin types

🌑️

Sensor integration

Connect external sensors (temperature, GPS, pressure) and transmit data via mesh

πŸ“Š

Data logging

Log mesh events to SD card or external database for analysis

πŸ””

Notification systems

Send automatic alerts based on mesh events or sensor values

πŸ—ΊοΈ

Mapping plugins

Visualise network topology, node positions, and Signal strength

πŸ”Œ

Protocol bridges

Connect MeshCore to other networks (WiFi, LoRaWAN, MQTT)

πŸ€–

Automation

Build bots that automatically respond to messages or events

Best practices for plugin development

Follow these guidelines to build stable and performant plugins

  • βœ“

    Keep plugins small and focused - A plugin should do one thing well, not everything at once

  • βœ“

    Respect resource limits - ESP32 has limited memory and CPU; optimise your code

  • βœ“

    Use async patterns - Never block the main loop; use callbacks and timers

  • βœ“

    Implement error handling - Catch exceptions and log errors clearly

  • βœ“

    Document your API - Write clear comments and a README for users

  • βœ“

    Test thoroughly - Test on real hardware and in different network conditions

Frequently asked questions

In which programming language do I write MeshCore plugins?

MeshCore plugins are written in C/C++ because the firmware runs on embedded hardware (ESP32, nRF52). You can also use Python for external plugins that communicate with the firmware via serial or MQTT.

Can I use existing arduino libraries in my plugin?

Yes, most Arduino libraries are compatible with MeshCore because it is built on the Arduino framework. Simply watch out for library conflicts and memory usage.

How do I debug my plugin during development?

Use the serial monitor in PlatformIO for debug output. You can use Log.info(), Log.debug(), and Log.error() for structured logging. You can also use a hardware debugger (like J-Link) to set breakpoints.

Can plugins modify radio configuration?

Yes, with appropriate permissions plugins can alter radio parameters such as transmission power, spreading factor, and bandwidth. This should be done carefully to maintain network stability.

How do I distribute my plugin to other users?

You can share your plugin as a folder with code plus plugin.json via GitHub. Users can then add your plugin to their firmware build and compile themselves. A plugin marketplace may arrive in future.

Can I earn money with plugins?

MeshCore is open source, but you can create commercial plugins if desired. Many developers choose an open source plus donations model, or sell support and custom development.

Start with MeshCore plugin development

With the plugin API you can customise MeshCore for your specific use case without modifying the core firmware

Start building your first plugin today and share your creations with the community!