Plugin development

MeshCore plugin development

Build custom modules and extend MeshCore functionality with your own plugins

What is MeshCore plugin development?

MeshCore has a modular plugin architecture that allows developers to extend the mesh network functionality without modifying the core firmware. With plugins you can add custom features like integrating sensors, logging data, calling external APIs and more.

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

Whether you want to connect a weather station, build an automatic emergency alert system or create custom visualizations - MeshCore plugins make it possible. This guide shows you how to get started with plugin development.

Plugin architecture overview

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

Plugin manifest

Every plugin starts with a manifest file that defines 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 setup the build tools:

git clone https://github.com/meshcore/meshcore-firmware.git
cd meshcore-firmware
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 need. Register callbacks for events like 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 sends 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 initialized");\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 send 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

Visualize 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, optimize 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. You just need to 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 the right permissions plugins can change radio parameters like transmit 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 + plugin.json via GitHub. Users can then add your plugin to their firmware build and compile themselves. A plugin marketplace may come in the future.

Can I make money with plugins?

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

Start with MeshCore plugin development

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

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