This article describes a Lora-based mini weather station that measures temperature, humidity, pressure and wind direction via TTN and Cayenne LPP.


Using this B-L072Z-LRWAN1 board in combination with STM's Mems-Sensor Arduino Shield X-NUCLEO-IKS01A1 or X-NUCLEO-IKS01A2, you can combine wireless IoT with simple sensors like temperature, pressure, humidity and magnetic sensors . This project uses The Things Network and Cayenne LPP to adapt the demo firmware to build a WindVane weather station.


In addition to the 3D printer, the PCB demo board and the complete toolset, an additional requirement is some metal construction hardware to make it easy to rotate: a 28/15mm bearing glued to a 20cm long rod (M8 rod )superior.

Some simple Lora module tests showing 20+km range: LinkedIn.

1. Set up STM tools and firmware

Visit the STM website and download LoraWan and the STM Open Development Environment SW4STM32 (Eclipse based).

Install SW4STM32 (Eclipse) and optionally LoraWan software (STM32CubeExpansion_LRWAN_V1.1.0) to a new workspace directory (do not change the naming of the directory structure).

Download the new End_Node firmware from this project and add the LoraWan project directory in the workspace. (Zip file contains complete project directory):



Start the .project file. Location:. . \End_Node\SW4STM32\B-L072Z-LRWAN1\mlm32l07x01\.project. View the code in Eclipse

The next step is to set up Lora network information (via TTN).

2. Get the device EUI of your Lora-Board

The B-L072Z-LRWAN1 is equipped with a Murata module containing a Semtech Lora Radio and SMT32L0 MCU. This radio has a unique device identifier called [Equipment EUI]. The board ships with firmware to display the device EUI through the virtual Com port. So connect your Loraboard via USB and open a terminal like Putty or TeraTerminal (115200 baud, 8 bits 1 stop, noparity, Flowctrl XonXoff).

If you don't find the correct COM port, check the device manager on your system and look for ST-link Virtual Comport. You will see something like this:


Copy and save the DevEui hex code, you will need it in TTN. AppEui and AppKey will also be obtained through TTN.

3. Set up your TTN app and device

Go to TTN and open or set up your account. Go to your console and launch a new app that uses OTAA (Over the Air Activation). TTN will issue an Application EUI copying this hex code. Create a new device in your application. This requires DevEui from the previous section. TTN will also generate a security key called Application Key, so copy that too. It displays the following in your device overview:


You can click the eye icon to make the App Key visible. Also use '«»' to change the hex code style – copy it into the C code.

4. Customize your Lora application C code: Comissioning.h

Now to make the firmware in the device unique to the TTN application, you need to adjust the settings of the OTAA lora ID. Go to the comissioning.h include file and change the hex codes for LORAWAN_APPLICATION_EUI and LORAWAN_APPLICATION_KEY using the TTN data from the previous section. LORAWAN_DEVICE_EUI is read by software and does not need to be changed.


Save the file and compile the entire project. Go to the Debug directory and copy the .bin file to a temporary drive (ST-link will automatically generate an external drive when the Lora board is inserted, copy the .bin file here). The ST-link controller on the board will flash the STM32L0 MCU and reboot the board.

NOTE: Use the IKS01A2 version of the Mems-shield, but this requires some software library adaptation as it uses a different pressure sensor on the shield. Physically, it fits in the same casing/enclosure.

5. Lora WindVane application running

After flashing, the B-L072Z-LRWAN1 board resets and starts running. You can reset the board manual by pressing the black reset button.

Open a terminal connection and watch the console. The firmware will first state when it starts calibration. This is the maximum-minimum required for the magnetic sensor calculation to convert the operating value into the correct orientation angle. During calibration, the BlueLED flashes for 10 seconds. Place the board in a flat position (XY plane), then turn it in a north-south direction and wait a moment. After 10 seconds, it is calibrated and the console shows OTAA activity and gives status.

If you are close enough to the TTN gateway, the board will join and your message will be sent every 10 seconds. These 10 seconds are for testing, in a real case you should change APP_TX_DUTYCYCLE in main.c to a value around 15 minutes (values ​​are set in milliseconds). The terminal monitor dumps some calculated values ​​of data on the screen – just for verification purposes.

If you don't want to see this data, you can set the defined compiler variable: VERBOSE_ENABLED.

6. TTN console – Cayenne LPP format

After adding the board to the TTN network, you can see the device data (data section) in the TTN console. Data comes in bursts of a series of bytes. This information is set in Cayenne LPP format: [channel][type][data]. In Main.c, you can find the LoraTxData() function that does this.

Now you can preset the payload format in TTN to Cayenne LPP and TTN will display the converted data. It looks like this:


The payload is translated into recognizable fields.

Some notes on this application: The wind direction is not a common LPP type, so the wind angle is passed through analog input 5 (LPP channel 5). other information:

Analog_in_5 is the wind angle (0 is north, 90 east, 180 south, etc.)

Analog_in_3 is the battery status in %

Digital_out_6 is the state of the blue LED (on/off)

gps_4 is a fixed coordinate that can be modified in the code.

other name of the payload field with the same name

Remark: LPP channel has nothing to do with TTN channel and is used for uplink and downlink communication with TTN gateway; downlink information can be sent to Lora Board through TTN-Application Channel 2: 01h or 00h to turn on or off the blue LED.

7. Cayenne app and console

To push this information from TTN to your Cayenne console, you must set "Integration" in TTN to "Cayenne" and use the device EUI in your Cayenne project:

Create a project

Select "LoRa" -> The Things Network -> Cayenne LPP as the device:


After setting up the project, you can view the received data fields and choose the format in which you want to view the console, including data over time, graphs, gauges, and more. Also, you should be able to use the Cayenne app on your phone.


8. Battery Operation

For battery operation, the B-L072Z-LRWAN1 board is equipped with 3xAAA battery holders. In order for the battery to work properly, the ST-link controller on the board needs to be turned off and the reset connection disconnected. The ST-link controller is not powered by battery power, but the reset still affects the MCU reset, so this connection needs to be disconnected.

This can be done by removing the SB37 connection. This is not a jumper option though, so you'll have to remove the very small zero ohm resistor (0603). SB37 is located on the back of the board.

Also need to remove the SB18 stub so the battery doesn't get drained by the red power LED.

9. 3D printed casing

A total of three 3D printed enclosures support the B-L072Z-LRWAN1 + X-NUCLEO-IKS01A1 shield.

STL files for printing shells can be found on ThingIverse. Made 3 versions:

V1 : Tight housing for front and rear pin connections

V2: Larger case with slide-in edges to make it tighter.

V3: Same as V2, but with air intakes at the front and air outlets at the back.

The V3 is better at measuring humidity and temperature, as the case heats up in direct sun, and when it cools, moisture can get trapped in the case.

TIP: It is best to use ABS plastic or special plastics like Polymaker's Pc-Max for printing. To prevent warping of connected parts (front and back), the best result is to use rafts and supports, print nose down (or bottom down):


Leave a Reply

Your email address will not be published. Required fields are marked *