This is a LoRaWAN end node example for the Seeed LoRa-E5 Mini dev board using v1.1.0 of the FW. The code provided by Seeed is based on v1.0.0 and running the STM32 code generation tool Stm32CubeMx undoes some of the necessary changes to the code which renders the code with many compilation errors and practically useless.
When testing this device, my test setup included 2 types of sensors:
- AHT20 temperatur & humidity (I use the Adafruit breakout This sensor uses I2C.
- PMS - Particle "counter" which communicates using UART. TODO: search reference for particle sensor.
These sensors can be activated in the code by defining
#define USE_AHT20_SENSOR
#define USE_PMS_SENSOR
in Core/inc/sys_conf.h
. Without these defines the sensors are not
used and random numbers are transmitted over Lorawan instead, this
is the default setting now.
I have set up this project for the Nucleo STM32WL55 board from scratch like it is done in v.1.1.0. There are some important changes with respect to v.1.0.0, CubeMX now only creates a skeleton and the user adds all necessary code as "user code" to get a functional application. This renders the code generation tool more versatil and user code and code automatically generated are clearly separated.
The necessary changes have then been included for the custom board which differs from the Nucleo board mainly in number of LEDs (1), buttons (1) and pins necessary to control the radio switch (2 instead of 3).
These code changes have been obtained from the original Seeed v.1.0.0 version at https://github.com/seeed-lora/LoRa-E5-LoRaWAN-End-Node.git and have been included as "user code".
The I2C2 and UART peripherals have been added for communicating with external sensors. User code is provided for initializing and reading the AHT20 sensor (similar to AHT20 arduino library) and for reading out the PMS sensor over UART.
Data is transferred over LoRaWAN in CayenneLPP format, as
- 10 * temperature in celsius
- 10 * relative humidity
There are 2 ways for changing/configuring this application:
-
Automatic code generation by running CubeMX (click on the .ioc file, configure your project and then run code creation). This only affects code outside of the ranges
/* USER CODE BEGIN xxx / ... / USER CODE END xxx */
You would do this for example if you want to add/remove some peripheral like UART or I2C. You also can configure LoraWan parameters with CubeMX.
-
Edit the files manually, but be careful to introduce your changes ONLY between
USER CODE BEGIN
andUSER CODE END
. This is usually your application specific code.
This separation between generated and user code is what not works well in the original code provided by Seeed and was the reason to make this app.
A little hint: Commit your changes before you run the code generation and
check with git status
and git diff
what the code generation tool has
changed. This sometimes reveals that you have written "user code" outside
of the specified ranges and that the code generator has just removed this
code.
When on Linux I run dos2unix
on all text files after code generation.
Otherwise git status
returns all files, just because of the line endings
generated by the tool. I have not yet found a way to configure this in
STM32CubeIDE.
These can be set from the configuration tool (.ioc file) in STM32CubeIDE,
selecting "Middleware -> LoraWAN -> LoRaWAN comissioning". These settings
are (over)written to se-identity.h
upon code creation. So if you intent to
use code creation it is probably better to define your keys here instead of
directly editing se-identity.h
- "App/Join EUI" is mapped to LORAWAN_JOIN_EUI
- "Application Key" is mapped to LORAWAN_APP_KEY in se-identity.h
- "Network Key" is mapped to LORAWAN_NWK_KEY The "Static Device Address" should not be used anyhow for security reasons and thus network and application session keys will not be used.
If you prefer, you can directly edit se-identity.h
but it will
be overwritten by code creation. So please don't open an issue "Why does
my device not connect anymore after code creation?" :)
In order to get accepted by TTN the settings in this application need to correspond to your application setup in TTN. The names map as follows
- TTN "AppEUI" corresponds to LORAWAN_JOIN_EUI in
se-identity.h
- TTN "DevEUI" corresponds to LORAWAN_DEVICE_EUI in
se-identity.h
- TTN "AppKEY" corresponds to LORAWAN_APP_KEY in
se-identity.h
For your device, in "Payload formatters" use "CayenneLPP". This should be enough to get you up and running. Please let me know if something important is missing in these instructions.
This software component is licensed by ST under Ultimate Liberty license SLA0044, the "License"; https://www.st.com/SLA0044.
This repository is the result of a hackaton at the TTN summer academy 2021,
a nice opportunity to learn LoRaWAN and meet nice people. I have added
the slides for the mini presentation we all gave in file ForestWatcher.odp
.