Bachelor Project - Sensor Network for Smart Agriculture

Introduction

Picking the topic was mainly motivated by wanting to upgrade and evolve our LoRa-based home automation system. That in itself constitutes the LoRa part, but the “Smart Agriculture” part is the result of finding a supervisor, who himself suggested the topic of soil moisture sensing, which was an amazing coincidence given my long-standing Wireless soil moisture sensor project.

Naturally, with great excitement, I immediately set out to work on the practical part of the thesis. This project, just like the Prosthesis motor control and STM32 robot competition, allowed me to do my uni-related duties fueled by the passion I have for these personal endeavors.

Timeline

After locking in the topic with the supervisor, I started on October 2023 by getting myself up-to-date with the viability of using Rust for this project, since that was also on my wishlist for quite a while. We agreed on using an STM32 as the main MCU, so I was mostly interested in the matureness of the various frameworks, such as Embassy and RTIC.

This move to Rust was, for me, a risky one. Most of my experience stems from using the classical C tooling and “frameworks” for embedded, so I wanted to limit the amount of surprises that could arise going down this path. The thesis has a hard deadline at the end of May and I did not want to be caught up in a situation, where some crucial feature is missing and my only option is to implement it myself, which could be a huge setback considering my current experience with Rust.

After playing around with the Embassy examples, which are great by the way, written for the Nucleo-WL55JC board, I concluded that it is possible to continue. Though risky, the opportunity to learn something new and possibly help the community develop outweighed most downsides.

At the end of October, I sent my designs of the v0.1 LoRa module, based on the STM32WLE55 SoC, to PCBWay for manufacturing and assembly. All details about the various design choices can be found in the thesis in Chapter 3 and the design itself is hosted on GitHub. I prioritized the hardware design because I knew the lead times were long and could stretch longer unexpectedly.

While I was waiting for the prototypes to arrive, I worked on the firmware itself. Having tested the basic backbone stuff, such as radio settings, on the Nucleo dev board, I set up the firmware repo and split the code into “runtime” and “applications”. The split was done in anticipation of a lot of similarity between the “node” and the “gateway” code and is talked about in the thesis in more detail.

Finished prototypes arrived at the end of November. I immediately hit a snag, where the lora-rs library (previously part of the embassy project) only supported TCXO as the main system clock. Due to the way STM32WLE handles the clock, this caused an incompatibility with my hardware and I had to resort to swapping the on-module crystal oscillator with a TCXO to get the module up and running. However, the lora-rs project is in active development and this functionality was later added by a member of the community.

Implementation of the OTA update protocol was done during December and early January. In January a mid-project presentation was to take place, so I figured it would be interesting to demonstrate the OTA update functionality by transferring a screen buffer instead of the actual binary so that the self-correcting feature of the protocol could be seen in action. In the video it is apparent, that the stream of the frame buffer chunks goes out for a while, then one comes out of order and then the missing two pieces are filled in. In practice, this means that you can have an inferior connection, but all that will do is slow down the update process and not cause any corruption of data.

I did not have time to work on the thesis during the end of the winter semester due to all the exams. The soil moisture sensor concept and design work was done during March, it was sent off to PCBWay at the end of the month.

While I waited for the hardware to arrive, I started to work on the thesis itself. I started with one of the university LaTeX templates, which I ended up needing to modify to comply with the university guidelines. I could not help myself but also set up a simple CI/CD pipeline on GitHub, that built the thesis and uploaded it to this site. I knew I would need to share it quite often with other people and figured, that it would be great if I did not need to worry about keeping it up to date.

This also proved useful for fulfilling one particular curiosity: This was generated by a script, which walked the git commit history, one commit at a time, and since the thesis build process was set in stone by the pipeline, the script simply built every commit and then analyzed it using the pypdf library. But let’s not get ahead of ourselves.

The finished sensors came at the end of April, so I set out to bring up these boards as well, as can be seen on the “productivity graph” - I actually couldn’t take a break. The sensors turned out great. They ended up working much better than expected. Originally, I only really needed to detect a change in the moisture level, since this is just a proof-of-concept solution. Surprisingly, they can confidently measure relative soil moisture saturation, once properly calibrated.

The Raspberry Pi Pico at the bottom served as a data logger, measuring the voltage of the sensor’s battery. This was the only real letdown of the project since the battery life was pretty underwhelming. The sensor was not able to accumulate enough charge to last through the night, as can be seen in the soil moisture chart above. The poor battery performance was caused by a hardware problem on the communications module.

Final remarks

Throughout the project I needed to balance spending time on it, working around the relatively long lead times for manufacturing, and managing a team of developers at work. Initially, I may have wanted to spend a lot more time and effort on some of its aspects, but in the end prioritized what mattered the most - to deliver a finished and well-rounded solution with all the requisite testing and extensive documentation in the form of the thesis. I am glad this was positively reflected upon in the final opinions.

Documents

Live Demo (Decommissioned)

Soil moisture sensor

These are the live readings from the soil moisture sensor. The chart shows the relative moisture saturation, as measured by the sensor depicted on the right. Colors correspond to the depth of the capacitive sensing zone. The sensor communicates with the LoRa Nucleo board connected to a Raspberry Pi, which then forwards the data to this website.


Last updated on May 25, 2024