A comprehensive LoRaWAN gateway solution for ESP32-based devices that bridges local IoT networks with The Things Network (TTN). This project extends the LMIC-Node framework with advanced task management, power management, GPS synchronization, MQTT broker functionality, and a modern web interface.
- LoRaWAN Gateway: Acts as a bridge between local IoT devices and TTN
- Multi-Task Architecture: FreeRTOS-based task management for concurrent operations
- Power Management: Advanced power management with sleep modes and battery monitoring
- GPS Integration: Time synchronization and location tracking
- MQTT Broker: Local MQTT broker for device communication
- Web Interface: Modern Alpine.js-based dashboard served by the ESP32
- Payload Parsing: Automatic payload formatter generation for TTN console
- Tasmota Integration: Registry and management of Tasmota devices
- OTA Updates: Over-the-air firmware updates
- TTGO T-Beam V1.2
- GPS module
- OLED display
- Power management IC (AXP192)
- LoRa radio (SX1276)
- TTGO LoRa32 V2
- OLED display
- SD card support
- LoRa radio (SX1276)
- LoPy v1
- Real-time clock
- SD card support
- LoRa radio (SX1272)
LMIC Node Rebuild/
βββ src/ # Main ESP32 source code
β βββ main.cpp # Main application entry point
β βββ lmic-node.cpp # LoRaWAN functionality
β βββ mqtt.cpp # MQTT broker and client handling
β βββ gps.cpp # GPS time sync and location
β βββ power.cpp # Power management
β βββ parsers.cpp # Message parsing utilities
β βββ utils.cpp # Utility functions
βββ include/ # Header files
β βββ lmic-node.h # Main LoRaWAN interface
β βββ typedef.h # Data structures and payload definitions
β βββ mqtt.h # MQTT interface
β βββ *.h # Board-specific and utility headers
βββ web/ # Frontend application
β βββ src/ # Source files
β βββ build/ # Built web assets
β βββ package.json # Node.js dependencies
βββ data/ # Web assets served by ESP32
βββ payload-formatters/ # TTN payload formatter generator
βββ platformio.ini # PlatformIO configuration
The application uses FreeRTOS tasks for concurrent operations:
- LMIC Task: Handles LoRaWAN communication
- MQTT Task: Manages MQTT broker and client connections
- GPS Task: GPS time synchronization and location tracking
- Status Task: System monitoring and web interface
- Power Task: Power management and sleep modes
- UplinkQueue: Messages to be sent to TTN
- DownlinkQueue: Messages received from TTN
- MQTTQueue: Local MQTT messages
The system supports multiple payload types with automatic port mapping:
- Telemetry (Port 11): Temperature, humidity, voltage, current, power
- Tracer (Port 12): Battery and solar system data
- Meter (Port 13): Power consumption data
- CO2 (Port 14): Air quality sensors
- GPS (Port 15): Location and movement data
- Coolbox (Port 16): Cooling system monitoring
- PlatformIO IDE or CLI
- ESP32 development board
- LoRa radio module
- GPS module (for T-Beam)
- The Things Network account
-
Clone the repository
git clone <repository-url> cd "LMIC Node Rebuild"
-
Configure LoRaWAN keys
- Copy
keyfiles/lorawan-keys_example.htokeyfiles/lorawan-keys.h - Add your TTN device credentials
- Copy
-
Build and upload
# For TTGO T-Beam pio run -e tbeam pio run -e tbeam -t upload # For TTGO LoRa32 pio run -e ttgo-lora32-v2 pio run -e ttgo-lora32-v2 -t upload # For LoPy pio run -e lopy pio run -e lopy -t upload
-
Build web interface
cd web npm install npm run build -
Generate payload formatters
cd payload-formatters npm install npm run build
The platformio.ini file contains build configurations for different boards:
- tbeam: TTGO T-Beam with GPS and power management
- ttgo-lora32-v2: TTGO LoRa32 with display
- lopy: LoPy with SD card support
- Supports both OTAA and ABP activation
- EU868 frequency plan
- Configurable data rates and power levels
- Local MQTT broker on port 1883 (and 8080 for websockets)
- Automatic device discovery
- Topic structure:
tasmota/discovery/<MAC>/config
The web interface provides real-time monitoring and control:
- System Status: CPU, memory, uptime, and task information
- LoRa Status: Connection status, SNR, RSSI, and message queues
- Device Registry: Connected Tasmota devices and WiFi clients
- GPS Information: Current location and time synchronization
- Payload Parsing: Real-time message parsing and visualization
- Local Network:
http://<device-ip> - Captive Portal: Automatically redirects when connecting to device WiFi
The system automatically generates payload formatters for TTN console:
-
Build formatters:
cd payload-formatters npm run build -
Copy to TTN: Use the generated JavaScript in your TTN application
- Local devices send data via MQTT
- ESP32 parses and queues messages
- Messages are sent to TTN via LoRaWAN
- Downlink messages are forwarded to local devices
- Deep Sleep: Configurable sleep intervals
- Battery Monitoring: Real-time battery status
- Power Optimization: Automatic power mode switching
- Wake Sources: Timer, GPIO, or external events
#define DO_WORK_INTERVAL_SECONDS 60 // Work interval in seconds
#define SLEEP_VAR RTC_DATA_ATTR // RTC memory for sleep stateThe system automatically discovers Tasmota devices on the network:
{
"ip": "192.168.2.196",
"dn": "Tasmota",
"hn": "tasmota-80FF6D-8045",
"mac": "E0980680FF6D",
"md": "Generic",
"sw": "13.3.0.1"
}- Automatic device registration
- Status monitoring
- Configuration management
- Time synchronization
- Define structure in
include/typedef.h - Add parsing logic in
src/parsers.cpp - Rebuild payload formatters
- Update web interface if needed
To add support for a new board:
- Create board-specific header in
include/ - Create board-specific source in
src/ - Add build environment in
platformio.ini - Update pin definitions and features
- Serial output at 115200 baud
- Web interface status pages
- MQTT status messages
- Task monitoring
- Task heap usage
- Free memory
- CPU utilization
- Network statistics
- Connection status
- Signal quality (SNR/RSSI)
- Message success rates
- Queue status
- Serial console output
- Web interface logs
- MQTT status messages
- File system logging (SD card)
- AES-128 encryption
- OTAA/ABP authentication
- Secure key management
- WiFi encryption
- MQTT authentication
- HTTPS for web interface
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- TTN Mapper T-beam: Blueprint for using TBeam power management & GPS (https://github.com/bitconnector/ttn_mapper_t-beam)
- LMIC-Node: Base LoRaWAN functionality (https://github.com/lnlp/LMIC-node)
- PicoMQTT: Lightweight MQTT broker (https://github.com/mlesniew/PicoMQTT)
- Tasmota: IoT device firmware
- The Things Network: LoRaWAN network infrastructure
For issues and questions:
- Check the existing issues
- Review the documentation
- Test with supported hardware
- Provide detailed error information
Note: This project is actively maintained and supports multiple ESP32-based LoRaWAN gateways with advanced IoT integration capabilities.