I wanted to shortly present a port of mcci-catena/arduino-lmic for a STM32L071KBT. The application is an electric fence monitor which in regular intervals wakes up and samples the fence voltage through a resistor divider. Should the voltage fall below a certain level or be not present it sends out a message using an RFM95 module. It also sends out a heartbeat with the current voltage measurement regularly.
You can find the source files for hardware and software at github.com/Luddi1/LoRaWAN-fence-monitor. Beware that the current hardware needs a second revision with a few fixes.
The software is based on generated code from STM32CubeMX using the LL drivers. It features:
- Regular wakeup with RTC.
- Save of all lmic variables in EEPROM with wear leveling.
- Comparator + ADC for voltage measurement.
- Simple battery empty detection with PVD.
- Current arduino-lmic v3.1.0 with HAL in pure C
The sleep current is ~4uA. So two AA batteries should last a few years.
I hope this helps a few people that want to use this library without Arduino, like I did.
Thanks to terrillmoore and all other contributers to this library.
I am aware that there are similiar projects like https://hackaday.com/2019/08/28/monitoring-an-electric-fence-with-lorawan which would work just as well. My goal was to have a smaller BOM cost. It should be around 20€ per device in low quantities.
Leave any questions or comments if you like.
One of the hardware problems is the PCB antenna which does not perform as expected. So i resorted to a simple monopole wire for now