This file provides guidance to WARP (warp.dev) when working with code in this repository.
This is the Meshtastic firmware repository - an open-source LoRa mesh networking project for ESP32, nRF52, RP2040/RP2350, and Linux platforms. The firmware enables decentralized communication over long distances without cellular or internet infrastructure.
Build for a specific target board:
pio run -e tbeam # Build for TTGO T-Beam
pio run -e heltec-v2.1 # Build for Heltec LoRa v2.1
pio run -e rak4631 # Build for RAK4631 (nRF52)
pio run -e pico # Build for Raspberry Pi PicoPlatform-specific builds:
./bin/build-esp32.sh tbeam # ESP32 platform
./bin/build-nrf52.sh rak4631 # nRF52 platform
./bin/build-rp2xx0.sh pico # RP2040/RP2350 platform
./bin/build-native.sh # Linux native buildList all available board targets:
pio project data | grep env:Build all targets for CI/testing:
python ./bin/generate_ci_matrix.py esp32 # Generate ESP32 target listRun native platform tests:
pio test -e native # Unit tests on native platform
pio test -e coverage # Unit tests with coverage
platformio test -e coverage -v --junit-output-path testreport.xmlRun integration tests with simulator:
.pio/build/coverage/program & # Start simulator
python3 -c 'from meshtastic.test import testSimulator; testSimulator()'Hardware-in-loop testing:
./bin/test-simulator.sh # End-to-end simulator testStatic analysis and checking:
pio check --flags "-DAPP_VERSION=1.0.0 --suppressions-list=suppressions.txt"
./bin/check-all.sh tbeam # Check specific target
./bin/check-all.sh # Check common targetsCode formatting:
trunk fmt # Format all code using Trunk
trunk check # Run all linters and checksFlash firmware to device:
pio run -e tbeam -t upload # Build and flash to device
./bin/device-install.sh # Install script for released firmware
./bin/device-update.sh # Update script for released firmwareMonitor serial output:
pio device monitor -e tbeam # Serial monitor for specific target
pio device monitor --baud 115200Debug with GDB (native builds):
./bin/native-gdbserver.sh # Start GDB server for native debugging
gdb .pio/build/native/program # Attach GDB to native buildException decoding:
python ./bin/exception_decoder.py <crash_log> # Decode ESP32 crash logsMain Application (src/main.cpp):
- Hardware initialization and platform detection
- Service startup and coordination
- Main event loop and power management
MeshService (src/mesh/MeshService.h):
- Central coordination of mesh networking
- Packet routing and queue management
- Phone app communication via Bluetooth/WiFi
RadioInterface Hierarchy:
RadioInterface: Base class for all radio driversSX1262Interface,SX1268Interface: Semtech SX126x driversRF95Interface: Semtech SX127x (RFM95) driverSX1280Interface: 2.4GHz Semtech SX1280 driverLR11xxInterface: Semtech LR11xx drivers with GNSS
ProtobufModule Base Class (src/mesh/ProtobufModule.h):
All application modules inherit from this class and handle specific Protocol Buffer message types.
Key Modules:
AdminModule: Device configuration and managementRoutingModule: Mesh routing and packet forwardingPositionModule: GPS/GNSS position sharingTextMessageModule: Text messaging functionalityTelemetryModule: Environmental sensor dataRemoteHardwareModule: GPIO control over mesh
Module Discovery: Modules are auto-registered via setupModules() in src/modules/Modules.cpp
Platform Layer (src/platform/):
esp32/: ESP32-specific implementationsnrf52/: Nordic nRF52-specific coderp2xx0/: Raspberry Pi Pico implementationsportduino/: Linux native platform layer
Hardware Variants (variants/):
- Board-specific pin definitions and configurations
- Each variant has
variant.hand optionalplatformio.ini - Organized by platform:
esp32/,nrf52840/,rp2040/, etc.
Generated Code (src/mesh/generated/):
- Auto-generated from
.protofiles inprotobufs/submodule - Core types:
meshtastic_MeshPacket,meshtastic_Config, etc. - Regenerate with:
./bin/regen-protos.sh
Key Message Types:
MeshPacket: Wire format for all mesh messagesAdminMessage: Administrative commandsPosition: GPS coordinates and metadataTelemetry: Sensor data and device metrics
NodeDB (src/NodeDB.h):
- Persistent storage of configuration and node database
- Flash-based storage with wear leveling
- Manages channels, user settings, and device configuration
Configuration Loading:
- Factory defaults from
src/configuration.h - Variant-specific overrides from
variants/*/variant.h - User configuration from persistent storage
- Runtime modifications via AdminModule
-
Create variant directory:
variants/{platform}/{board_name}/ -
Create variant.h with pin definitions:
#define LORA_SCK 5
#define LORA_MISO 19
#define LORA_MOSI 27
#define LORA_CS 18
#define LORA_DIO0 26
#define LORA_RST 23
#define LORA_DIO1 33- Add platformio.ini configuration:
[env:myboard]
extends = esp32_base
board = esp32dev
build_flags =
${esp32_base.build_flags}
-I variants/esp32/myboard
-D MYBOARD_VARIANT- Test the variant:
pio run -e myboardFrequency Plans (src/mesh/RadioInterface.cpp):
Frequency selection is automatic based on:
- Hardware region detection (GPIO strapping)
- Regulatory database in
src/mesh/FrequencyList.h - User configuration override
Power and Range Tuning:
- Modify
txPowerin LoRa region configurations - Adjust spreading factor
sfand bandwidthbwfor range vs. speed - Consider duty cycle regulations per region
- Inherit from ProtobufModule:
class MyModule : public ProtobufModule<meshtastic_MyMessage>
{
protected:
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp,
meshtastic_MyMessage *p) override;
}- Register in Modules.cpp:
myModule = new MyModule();-
Define Protocol Buffer message in
protobufs/submodule -
Handle power management:
virtual void onSleep() override { /* prepare for sleep */ }
virtual void onWake() override { /* wake up actions */ }Broadcast Messages: Send to NODENUM_BROADCAST
Direct Messages: Send to specific NodeNum
Local Processing: Use handleReceived() for non-protobuf packets
Phone Integration: Override getUIFrameState() for app display
Monitor mesh traffic:
pio device monitor -f direct -e tbeam # Raw serial output
tail -f ~/.meshtastic/meshtasticd.log # Linux daemon logsKey Debug Information:
- SNR values for link quality assessment
- Hop count analysis for routing efficiency
- Packet retransmission patterns
- Channel utilization percentage
High Packet Loss:
- Check channel congestion with
CHANNEL_UTILIZATIONtelemetry - Verify antenna connections and SWR
- Analyze frequency plan conflicts
Poor Range Performance:
- Monitor received SNR values
- Check power settings and duty cycle limits
- Verify antenna radiation pattern orientation
Routing Loops:
- Enable routing debug logs
- Check node database synchronization
- Monitor hop limit handling
Light Sleep (ESP32):
- CPU stops, radio stays active for wake on packet
- Automatic in
PowerFSM.cppbased on activity
Deep Sleep (ESP32):
- Everything off except RTC
- Wake on timer, button, or external interrupt
- Configure in device settings
Built-in ADC Reading:
float batteryVoltage = readBatteryLevel(); // Platform-specificPower Telemetry:
- Battery voltage reporting
- Charging status detection
- Power consumption estimates
- PlatformIO Core 6.0+ with PlatformIO extension for VS Code
- Python 3.8+ for build scripts and protocol buffer generation
- Git with submodules support (
git submodule update --init)
- Fork and clone with submodules:
git clone --recursive https://github.com/yourusername/firmware- Create feature branch:
git checkout -b feature/my-awesome-feature- Build and test:
pio run -e tbeam
pio test -e native- Format code:
trunk fmt- Create pull request with detailed description and test results
- master: Latest stable release
- develop: Integration branch for new features
- release/x.y.z: Release preparation branches
- feature/*: New feature development
Pull requests require:
- Successful CI builds on all platforms
- Code review approval
- CLA signature via GitHub integration
- Passing automated tests
Bluetooth Low Energy (nRF52, ESP32):
- Primary interface for mobile apps
- Automatic discovery and pairing
- Packet streaming and configuration
WiFi HTTP API (ESP32):
- Web-based configuration interface
- JSON REST API for automation
- Access point mode for initial setup
TCP/Serial API (Linux):
- Command-line client interface
- Integration with existing systems
- Daemon mode for always-on operation
- Phone App → BLE/WiFi → Firmware
- Firmware processes via AdminModule or MeshService
- Firmware → Radio Interface → Mesh Network
- Remote Firmware → Radio Interface → Local Firmware
- Local Firmware → BLE/WiFi → Phone App
Understanding this flow is essential for debugging client connectivity issues and implementing new API features.