Project · Engineering

LoraSky Weather Station

Weather station for home use: sensors in a 3D-printed enclosure, readings sent over LoRaWAN to a desktop dashboard.

Ref.
02.03
Period
Dec 2023
Status
Completed
Organization
Master — IMERIR
Contributors
Axel COLMANT and Jules DUTILLEUX
Stack
  • ESP32 (Heltec WiFi LoRa 32)
  • LoRaWAN
  • The Things Network
  • MQTT
  • JavaScript
  • Python
  • 3D printing

Key points

  1. Five sensors and two relays on an ESP32 LoRa board, in a 3D-printed enclosure.
  2. All readings packed into a 32-bit frame and sent over LoRaWAN.
  3. Decoding script on The Things Network, then MQTT to a Python dashboard with history and relay control.
  4. LoRa settings chosen from reliability tests at 50 m: SF7, 125 kHz, 14 dBm.

The idea

A weather station for home use (Fig. 1): measure the conditions outside, send them in real time, keep a history, and act on them, for example switching on a light.

The IoT course first had us study LoRaWAN, then apply it to a project of our own. We built LoraSky in a team of two, with Jules Dutilleux, and shared every part of it.

Fig. 1The station.
The weather station, a white cylinder, standing in the grass

Fig. 1The station.

The system

Four steps take a reading from the garden to the screen (Fig. 2):

  1. Measure. The station reads its sensors.
  2. Pack. All readings fit in one 32-bit LoRaWAN frame.
  3. Decode. A LoRaWAN gateway provided for the course picks up the frame and forwards it to The Things Network, where a script turns the frame back into real values and publishes them over MQTT.
  4. Show and act. A desktop app keeps the history, draws the charts and drives the relays.
Fig. 2From the station to the app: readings go up, relay commands come back down.
Architecture in four steps: sensors feed the station, which packs a 32-bit frame and sends it over LoRa to a LoRaWAN gateway, which forwards it to The Things Network; its JavaScript decoder publishes the values over MQTT to the LoraSky app, which stores the history and shows it to the user. Commands go back the same way to the station's relays (light, window)

Fig. 2From the station to the app: readings go up, relay commands come back down.

Studying LoRa first

Before building anything, we measured how reliable a LoRa link is depending on its settings, with two ESP32 LoRa boards talking directly to each other, one sending and one receiving. To test many configurations, the sender and the receiver switch to the next one together, and fall back to the last working one if they lose each other (Fig. 3).

Fig. 3Switching both ends to the next configuration, with retries and rollback.
Sequence diagram of the configuration switch between sender and receiver: each side tracks a working, current and LoRa configuration; Start messages are retried up to 5 times, the receiver moves to the next configuration after that, and the sender rolls back if no new Start arrives

Fig. 3Switching both ends to the next configuration, with retries and rollback.

We then measured the delivery rate at 50 m for spreading factors 7, 9 and 11, bandwidths of 125 and 250 kHz, and transmit powers from 1 to 19 dBm (Fig. 4).

We picked SF7, 125 kHz and 14 dBm for the station: short airtime, with a margin on power.

Fig. 4Delivery rate at 50 m by transmit power (dBm), per spreading factor and bandwidth (labels from our French report).
Chart of the delivery rate at 50 m against transmit power, one line per spreading factor and bandwidth

Fig. 4Delivery rate at 50 m by transmit power (dBm), per spreading factor and bandwidth (labels from our French report).

The station

The enclosure is 3D-printed in two parts, with the electronics at the top and the rain collector below; the soil probe sticks out underneath (Model 1).

Model 1Our Onshape model, with a see-through shell to show the board and sensors.

Everything runs on a Heltec WiFi LoRa 32, an ESP32 board with a LoRa radio (Fig. 5).

The BMP280 sits on the I²C bus, the soil probe on an analog input, and the other sensors and the two relays each take one pin.

Each sensor gets just enough bits in the frame for the precision it needs (Table 1).

Fig. 5Pin of each sensor and relay on the Heltec board (labels from our French report).
Pinout of the Heltec WiFi LoRa 32 with the pin used by each part: soil moisture on 36, relays on 32 and 33, sonar on 12, BMP280 on 22 and 21, light sensor on 23, raindrop sensor on 2

Fig. 5Pin of each sensor and relay on the Heltec board (labels from our French report).

PartMeasuresBits
BMP280Temperature7
BMP280Pressure, then altitude5
Ultrasonic sensorWater level in the collector, then rainfall6
Soil probeSoil moisture6
PhotoresistorLight, day or night1
Raindrop sensorRain, yes or no1
Two relaysState of the light and of the window2
FreeRoom for another sensor4
Table 1Sensors and relays, and their share of the 32-bit frame.

Getting the data out

LoRaWAN messages are small, so every reading is packed into a single 32-bit frame (Fig. 6), with the bit budget of Table 1, then split into bytes for sending.

Fig. 6The 32-bit frame sent by the station.
The 32-bit frame: 4 unused bits, relay 1, relay 2, rain, 6 bits of soil moisture, 5 bits of pressure, light, 7 bits of temperature and 6 bits of water level

Fig. 6The 32-bit frame sent by the station.

The course's LoRaWAN gateway receives the frame over the air and forwards it to The Things Network, where a JavaScript decoder receives the bytes, turns them back into real values, computes the extra ones (altitude from pressure, rainfall from the water level) and publishes the result over MQTT, where the app picks it up.

The app

A Python desktop app subscribes to MQTT, stores the readings and shows them as charts: temperature, rain, pressure and altitude, humidity and light, for any date (Fig. 7). A second tab drives the light and the window, by hand or automatically (Fig. 8).

Fig. 7The LoraSky dashboard.
LoraSky dashboard with charts for temperature, rain, pressure and altitude, humidity and light

Fig. 7The LoraSky dashboard.

Fig. 8The control tab: light, window and automatic mode.
LoraSky control tab with a light button, a window button and an Auto button

Fig. 8The control tab: light, window and automatic mode.

Going further

A mobile app, a more compact enclosure, choosing how often the station measures from the app, and connecting it to other smart devices.

#iot#lorawan#embedded#sensors#3d-printing