This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Meshtastic firmware — an open-source LoRa mesh networking project for long-range, low-power communication. It supports ESP32, nRF52, RP2040/RP2350, STM32WL, and Linux/Portduino platforms. Build system is PlatformIO.
pio run -e tbeam # Build specific target (tbeam is the default)
pio run -e tbeam -t upload # Build and flash to device
pio run -e native # Build native/Linux version
pio test -e native # Run unit tests
trunk fmt # Format code before committing (required)
bin/regen-protos.sh # Regenerate protobuf code after .proto changesAll features are implemented as modules inheriting from MeshModule or ProtobufModule<T> (src/mesh/MeshModule.h, src/mesh/ProtobufModule.h):
handleReceivedProtobuf()— process incoming packetsallocReply()— generate response packetsrunOnce()— periodic task; returns next run interval in ms- Register new modules in
src/modules/Modules.cpp
src/mesh/— core networking:NodeDB,Router,Channels, radio interfaces, andgenerated/(protobuf output)src/modules/— feature modules (Position, Telemetry, CannedMessage, etc.)src/modules/Telemetry/Sensor/— I2C sensor drivers, each inheritingTelemetrySensorsrc/gps/— GPS handlingsrc/graphics/— display drivers and UI (includesniche/InkHUD/for e-ink)src/platform/— platform-specific codesrc/concurrency/— threading utilities (OSThread,Lock,SPILock)
Each variant lives under variants/<arch>/<name>/ and contains:
variant.h— pin definitions and capability flags (HAS_GPS,USE_SX1262, etc.)platformio.ini— build config, usuallyextendsa common base env
Custom board JSON files are in boards/.
config.*— device config (LoRa, position, power, display)moduleConfig.*— per-module configchannels.*— channel management- Default values:
src/mesh/Default.h(Default::getConfiguredOrDefaultMs(), etc.) - User-overridable defines:
USERPREFS_*prefix
- Source definitions:
protobufs/meshtastic/*.proto - Generated output:
src/mesh/generated/ - Types are prefixed with
meshtastic_(e.g.,meshtastic_Telemetry)
#if !MESHTASTIC_EXCLUDE_GPS // feature exclusion
#ifdef ARCH_ESP32 // architecture
#if defined(USE_SX1262) // radio chip
#ifdef HAS_SCREEN // hardware capability
#if USERPREFS_EVENT_MODE // user preferencesrc/mqtt/MQTT.cpp — singleton handling connection and routing. Topic format: {root}/{channel_id}/{gateway_id} (default root: msh). Controlled per-channel by uplink_enabled/downlink_enabled.
- Create
src/modules/Telemetry/Sensor/MySensor.hand.cppinheritingTelemetrySensor - Implement
initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)andgetMetrics(meshtastic_Telemetry *measurement) - Register the sensor type in
EnvironmentTelemetry.cppandsrc/detect/ScanI2C.h - Add the sensor type to the protobuf enum in
protobufs/if needed, then runbin/regen-protos.sh
- Logging:
LOG_DEBUG,LOG_INFO,LOG_WARN,LOG_ERROR - Classes:
PascalCase; functions/members:camelCase; constants:UPPER_SNAKE_CASE - Use
IF_ROUTER(routerVal, normalVal)for role-based power defaults - Respect minimum broadcast intervals on default/public channels via
Default::getConfiguredOrMinimumValue() - Run
trunk fmtbefore committing — CI enforces formatting viatrunk_check.yml
main_matrix.yml— builds all variants on push; usesbin/generate_ci_matrix.pyto select targetstest_native.yml— runspio test -e native- PR builds use
--level prsubset for speed - Variant support level set via
custom_meshtastic_support_levelinplatformio.ini