Today I want to present my latest project to you:
YALP (yet another lora project )
Motivation:
I built a couple of beehive scales for friends of mine some years ago. I am no beekeeper myself but I do like honey and now I have more than I can eat.
All these scales were based on a Raspberry Pi which brought some issues along the way.
One is high energy consumption when using a RPi because these scales are bound to a power supply.
The other issue is the data transmission via WiFi, which limits the range and adds to the power consumption.
Later I stumbled upon ESPEasy which opened the option to reduce power consumption and therefore get rid of a power supply using a chargeable battery instead. But since the Wifi range issue remained I waited patiently until someone would integrate LoRa and/or LoRaWAN in form of a cheap module like the SX1276…. (… I am still waiting )
In the meantime, I took matters into my own hands and hacked together a solution.
Goals:
- affordable
- commonly available parts
- easy to assemble
- runs basically forever
- the possibility to also use LoRa (without the WAN) with my own Gateway
- easily adjustable software
What I did:
I started with creating a board in KiCad.
The first attempt had no integrated battery holder.
In the second attempt I added a battery holder and an option for charging circuitry including a port for a solar cell.
I also wanted to save costs and made the board multi-functional so that I can choose between node and gateway using the same board.
After assembly I realized, that I used the wrong LoRa template in KiCad (SX1278 instead of SX1276).
But in my third attempt, I got it almost right. I only had to reroute RX and TX to the Hardware UART of the ESP in the gateway option. After that I tried to bundle a software package where one can easily choose between LoRa (client or gateway), LoRaWan and a set of given sensors.
While the LoRa implementation worked almost out of the box, LoRaWAN made me almost giving up and starting from scratch.
Since one of my goals is affordability, I used the Arduino Pro Mini. Not necessarily because it costs a bit less than other MCUs but also because I still had a lot of them lying around. (Lesson learned: Don’t pick your hardware without knowing which obstacles this brings software wise because of hardware limitations)
The LoraWAN library is quite heavy memory wise so it took me some time to understand what to do (I am no programmer nor do I know a lot about hardware but I love to learn ).
I had to reduce the size of memory allocated for the payload and to disable the serial communication. (Which made debugging a bit harder)
With Tinkercad I then created the housing. Not the most sophisticated piece of cad software but I am very pragmatic and it is good for creating simple things quickly. The top part consists of 2 parts which adds a layer of protection against water. (I did extensive tests with a bowl of water )
Issues:
1. Using the Atmega328P was not the smartest choice. Memory wise and also because using a watchdog timer only gives you 10 different time settings to choose from where 8 seconds is the maximum. Therefor I had to add a counter which puts the MCU to sleep immediately after waking up until the counter meets the actual wakeup time value which is of course always a multiple of 8s. (I never used the watchdog of this chip so I didn’t know about this limitation)
2. Initially I wanted to use a MOSFET for cutting power to all peripherals while asleep. Since I only had N-channel MOSFET lying around I used this one even though I had a hunch, that this might not work as expected but it didn’t add up the to the total cost so I gave it a try.
…and it didn’t work
Next iteration of the board will get a high side switch (P-channel MOSFET)
Power consumption and runtime:
I was a little bit afraid because of the aforementioned issues regarding power consumption and the resulting runtime.
But luckily the peripherals went to sleep nicely and the current draw while sleeping is less than 20uA. Waking the MCU up for a fraction of time every 8 seconds adds to power consumption too but I calculated an average current draw of 30uA. That’s not great but given the circumstances I am fine with it.
Awake (500ms), the system draws in average 40mA where 300ms is for gathering the data (10mA) and around 200ms for sending (100mA). (These are rough estimations more than exact measurements)
This all becomes negligible when we add the solar panel to the equation since even in the shade it charges the battery more than the circuit consumes.
(https://www.of-things.de/battery-life-calculator.php)
What does all this have to do with ESPEasy?
Well, not so much but it is the only forum where I am „active“ and I use the power of ESPEasy for my own LoRa- Gateway.
The PCB is designed to act as a client as well as a gateway. Both setups use the Atmega328P for sending and receiving.
The gateway also uses either a Wemos D1 mini (esp8266)…. „Use the ESP32 instead“ I hear the voice of TD-er in my head but I have a lot of them lying around and there are definitely up for the task. There is also the pin compatible version of the ESP32 that could be used instead.
The Atmega sends the received values to ESPEasy as a CSV and there the Serial Proxy Plugin (P087) receives it and creates an event for further rules processing.
For testing I used these rules combined with easyfetch for nicer visualization:
Code: Select all
On SerialProxyXX* Do
AsyncEvent,ValueParser=%eventvalue1%
Pulse,2,0,50 //pulse the internal led when a message is received
Endon
On ValueParser Do
// Expected values from serial input, 1 = Counter, 2 = Node, 3 = Voltage, 4 = Temp1
//5 = Temp2, 6 = Weight, 7 = RSSI, 8 = SNR
If %eventvalue2% = 1 //Node #1
//check if there was a packet lost
Let,1,[Node1#Count]+1
If %eventvalue1% > [var#1] and %eventvalue1% > 0
TaskValueSet,Lost_packets,1,[Lost_packets#Node1]+1
PostToHTTP,ntfy.envs.net,80,/FailedLoRa,'title:LoRa_1','We missed one on Node1 !!!!!!!'
Endif
TaskValueSet,Node1,Count,%eventvalue1%
TaskValueSet,Node1,Voltage,%eventvalue3%
TaskValueSet,Node1,RSSI,%eventvalue7%
TaskValueSet,Node1,SNR,%eventvalue8%
TaskValueSet,last_seen,1,%syshour%.%sysmin_0%%syssec_0%
Elseif %eventvalue2% = 2
//check if there was a packet lost
Let,2,[Node2#Count]+1
If %eventvalue1% > [var#2] and %eventvalue1% > 0
TaskValueSet,Lost_packets,2,[Lost_packets#Node2]+1
PostToHTTP,ntfy.envs.net,80,/FailedLoRa,'title:LoRa_1','We missed one on Node2 !!!!!!!'
endif
TaskValueSet,Node2,Count,%eventvalue1%
TaskValueSet,Node2,Voltage,%eventvalue3%
TaskValueSet,Node2,RSSI,%eventvalue7%
TaskValueSet,Node2,SNR,%eventvalue8%
TaskValueSet,last_seen,2,%syshour%.%sysmin_0%%syssec_0%
Endif
Endon
Software preparations and configuration:
1. Download the lora_2v2 folder from https://github.com/chromoxdor/LoRa-and-LoRaWAN
2. Put the libraries (/libs) into your Arduino library folder
3. Open the lora_2v2.ino sketch
The options to choose from in the „options“ section are mostly self-explanatory.
For simple LoRa communication you can also choose to use simple encryption (AES128) and a common phrase.
Make sure the password and the common phrase are the same for gateway and client!
The common phrase can be used to separate multiple gateway/node setups since the gateway only reacts if it has the same phrase than its clients.
Hardware:
…coming soon... KiCad files will be provided at the repository when I am back home
Future:
I am not sure if we have a future….
But next time I´ll probably us a Esp32 module as a replacement for the Atmega328P
Did I forget something?
Probably a lot! So, if interested please don’t hesitate to ask.