This project collects environmental and spectral data using a SeeedStudio XIAO ESP32-S3, a DHT22 temperature & humidity sensor, and an Adafruit AS7341 spectral sensor. The data is transmitted via LoRaWAN (SX1262 module) to a ChirpStack server, then decoded using MQTT and saved in a CSV file for logging and analysis.
| Component | Description |
|---|---|
| Seeed XIAO ESP32-S3 | Microcontroller with Wi-Fi/BLE/USB-C |
| Adafruit AS7341 | 10-channel Spectral Sensor |
| LAMBDA62 (SX1262) | LoRa Transceiver (868/915 MHz) |
| WisGate RAK7268 | Indoor LoRaWAN Gateway |
| DHT22 | Temperature and Humidity Sensor |
| 3 × AA Batteries | Power source |
| 10kΩ Resistor | Pull-up resistor for DHT22 |
| Device | XIAO ESP32-S3 Pin |
|---|---|
| DHT22 | D7 (signal) |
| 3V3 (VCC) | |
| GND | |
| 10kΩ Resistor | Between D7 and 3V3 |
| AS7341 | SDA → D5 |
| SCL → D6 | |
| VIN → 3V3 | |
| GND | |
| LAMBDA62 LoRa | NSS → D3 |
| RST → D2 | |
| SCK → D8 | |
| MISO → D9 | |
| MOSI → D10 | |
| DIO1 → D0 | |
| BUSY → D1 | |
| 3V3 & GND |
- Install Arduino IDE (v1.8+ or Arduino 2.0)
- Install ESP32 Board Support
- Go to Preferences → Add this URL in Additional Board URLs:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - Then install ESP32 by Espressif in the Board Manager.
- Go to Preferences → Add this URL in Additional Board URLs:
- Install Required Libraries:
- LoRaWan-Arduino (by IBM)
- SX126x-Arduino (by Bernd Giesecke)
- CayenneLPP (by Electronic Cats)
- Adafruit AS7341 (by Adafruit)
- DHT sensor library (by Adafruit)
- Adafruit Unified Sensor (by Adafruit)
- Board Selection:
- Board: Seeed XIAO ESP32-S3
- Partition Scheme: Default
- Configure LoRaWAN Settings:
-
Go to MCCI_LoRaWAN_LMIC_library > project_config > lmic_project_config.h
-
Edit config file to match EU frequency and SX1262 radio:
#define CFG_eu868 1 #define CFG_sx1262_radio 1
-
Settings used for this project:
-
Channel Plan:
- Region:
EU863-870 - Conform to LoRaWAN: ✅ Enabled
- LoRaWAN Public: ✅ Enabled
- Region:
-
LoRa Network:
- Mode:
Packet Forwarder
- Mode:
-
Packet Forwarder Settings:
- Protocol:
Semtech UDP GWMPP Protocol - Server Address: [your local server address]
- Server Port Up:
1700 - Server Port Down:
1700
- Protocol:
-
DISCLAIMER:
- The current setup works if device running ChirpStack server is connected directly to RAK gateway
-
Steps for connecting gateway to your home Wi-Fi router:
- Connect gateway to your home router via Ethernet cable (preferrably for stable connection)
- Connect your laptop to the same router as your gateway
- Use command
ipconfigorhostname -Ito locate your device (or use Angry IP Scanner to locate connected devices) - Now that you know your laptop's IP address on home network, connect back to your gateway and then go to LoRa Network --> Network Settings --> Server Address and put your laptop's IP address (the one which your home router assigns)
- Click Save & Apply
- Connect back to your home router and run the code
The MQTT broker (e.g., Mosquitto) used in this project is run inside a Docker container for ease of deployment and management.
Install Docker: The easiest way to run ChirpStack and its dependencies (PostgreSQL database, Redis cache, MQTT broker) is with Docker. Install Docker Desktop on your laptop.
🔧 After installing Docker, be sure to complete the “Post-installation steps” to ensure proper permissions and setup.
Ensure this container is running before starting the Python MQTT logger script.
Download and Run ChirpStack: Use the official chirpstack-docker repository.
# Clone the repository
git clone https://github.com/chirpstack/chirpstack-docker.git
cd chirpstack-docker
# Start everything
# This command will download and run ChirpStack, its Gateway Bridge, a Mosquitto MQTT Broker, and databases.
docker-compose up -d- Provision your device on ChirpStack:
- Register the DevEUI, AppEUI, and AppKey.
- Use OTAA mode.
- Match with your Arduino sketch values:
uint8_t DEVEUI[8] = {...};
uint8_t APPEUI[8] = {...};
uint8_t APPKEY[16] = {...};- Install Dependencies:
pip install paho-mqtt- Run the script:
python mqtt_lora_logger.pyMake sure the MQTT broker (like Mosquitto) is running and ChirpStack is configured to publish uplink events to it.
Once data is received by ChirpStack, it is sent to MQTT broker. This Python script:
- Connects to MQTT (localhost:1883)
- Listens to topic application/+/device/+/event/up
- Decodes CayenneLPP payload (base64)
- Extracts:
- Temperature (channel 1)
- Humidity (channel 2)
- AS7341 F1-F8 readings (channels 3–10)
- Appends it into lora_sensor_data.csv
The firmware does:
- Initializes LoRa radio, AS7341, and DHT22 sensors
- Joins LoRaWAN network (OTAA)
- Reads temperature, humidity, and spectral data
- Encodes them using CayenneLPP
- Sends the data to LoRaWAN server every 15 minutes
- Goes into deep sleep to save power
- lora_sensor_data.csv will contain rows like:
timestamp,device_name,dev_eui,temperature,humidity,f1_415nm,f2_445nm,...f8_680nm
2025-07-11T10:12:45,EnvNode,ABC12345,24.6,45.5,235,240,...199- Deep Sleep saves battery by putting the ESP32-S3 to sleep for 15 minutes.
- CayenneLPP helps pack multiple sensor readings into a compact LoRa message.
- Make sure antennas are connected before powering LoRa module.
- If sensor readings are failing:
- Double-check wiring (especially pull-up resistor on DHT)
- Ensure AS7341 is properly detected on I2C bus