Close

Up and Running

A project log for Soil moisture monitoring in a flower garden

When do your flowers have enough water, and how do you know?

joseph-eoffJoseph Eoff 03/28/2021 at 19:240 Comments

I got out in the yard Friday afternoon, late, and set out the sensors.

I used a long tape measure and a yard stick to put them in something resembling a regular grid.

Thereafter followed the better part of two days of cursing and pulling of hair.

The control nodes simply would not work properly.

Sometimes they'd read some sensors and quit.  Sometimes they'd read some sensors, reboot, and start over again.  Maddening.

The worst part was that they only misbehaved when actually out in the yard.  The control nodes can't "see" my yard from the work room, so they'd just time out trying to connect to the sensors.  The errors were happening after the connection was made.  I couldn't debug the problem because I couldn't reproduce it when the nodes were connected to my computer for debugging.

I tried several things blindly - correcting things that could be mistakes then trying them  out.

In the end it was something I didn't do that was the problem, and something I accidentally did while troubleshooting that kept me from finding it.

You have to call "delete" on the Arduino Bluetooth client (BLEClient from the BLEDevice library) after you call "disconnect" on the BLEClient.

It wasn't that hard to figure that out, but while doing other things I managed to accidentally paste a line of code in the wrong place.  I wanted to return a nullptr at a particular spot when the Bluetooth service connect failed, and put it in the wrong spot - it always returned a nullptr, even when it worked properly.

I spent much of today trying to figure out how a delete and a try/catch could cause all connection attempts to fail. It can't, of course.  I didn't find the mistake until I tried a nearly line by line eyeball comparison of the version on GitHub and the version I was working on.

At any rate, I got it running (the updated software is in the control node repository.) 

The first complete run showed that the front yard needed two control nodes rather than just one.  The sensors furthest from the control node took forever to connect. 

The control node software reports back how many connect attempts it took to reach each sensor. The sensors furthest from the control node hit the maximum (4 tries) and timed out.

I have two nodes out there now.  They've gathered data for all 16 sensors on each run every time they've gone through.

While I was trying to fix the problems, I changed the software so that the control nodes can only read a maximum of 30 sensors.  From all of the errors, I found that it could easily take an hour to read 30 sensors if every one of them timed out.  Since I want to read from the sensors every hour, there's not much point in trying to read more than you can handle (worst case) in an hour.  When it all works properly, a node can read 15 sensors in just a few minutes.

The nodes now read all the sensorIDs from the server and put them in an array before reading the sensors.  That reduces WiFi traffic while the Bluetooth stuff is going on.  It also reduces fragmentation of the memory somewhat.

From a quick look at the raw data, I found a couple of interesting things:

  1. I'm going to have to buy batteries for the sensors much sooner than expected.  Half of the "brand new" batteries in the sensors are reading less than 50% capacity right out of the gate.  About 1/3 of the sensors show 100%.
  2. There's a noticeable temperature gradient across the yard.  Something like 3 degrees celsius between warmest and coolest.
  3. The nutrient content is much more even than I expected - around 200 microsiemens per centimeter conductivity, with a single sensor showing over 300.
  4. The soil moisture (which is what this project is all about) varies considerably.  It ranges from 18% to 51% from different sensors.

Now that I've got good data coming in, I'll get started on the analysis section this week.

--------

I may order some more parts and make a fourth control node.  I wanted one in the front yard, one beside the house for the potted roses, and one in the back yard for the wild flowers and the other flowers along the back border.  I had to put two in the front yard, leaving me one control node short for the back yard.

Discussions