Monitoring Our Hay Storage with Edge Connect and Machine Learning
What do hay storage, Akamai’s Edge Connect solution, and machine learning have in common? We use the serverless machine learning system to keep our hay storage safe and secure.
Loading, stacking, and storing enough hay to feed the horses at Blue Water Farm for a year is an arduous project. With new additions to our herd, we have more mouths to feed this year than ever before! This required us to stack more than 1,200 hay bales, each weighing approximately 50 pounds each. Every bale is handled at least twice: loaded onto the trailer, then unloaded into our stack. Since our crew consists only of my wife and me, we’ve each handled 30 tons of hay since June. Thankfully, we are finally done for this season and have enough hay in storage to last us until next summer.
These hay stores need to be protected after our vast investment of time and money. So, our other massive summer project was to build a 1,300-square-foot barn, completed 100% with our own hands. We hope the barn will provide good protection for the hay (and our boat) over the winter. Unfortunately, in terms of my carpentry skills, I’m a pretty good IT guy. The building is serviceable, but not perfect, and we needed some assurance that the building would protect the hay from moisture and mold.
Luckily, as a carpenter, I’m a pretty good IoT guy. I wanted to build a resilient system so the moisture level and temperature of the haystacks could be monitored. Hay bales are notoriously sensitive to moisture, and even a small amount can cause mold. More alarmingly, moisture can also lead to composting, which can in turn increase temperatures to the point of combustion and cause a fire! We needed a system that could alert us in real time if thresholds exceeded these values and could also collect data over time for later analysis.
There were many constraints and challenges to consider. The building has a steel frame, steel walls, and a steel roof. You couldn’t build a better Faraday cage if you tried, but this also means that wireless signals will not easily penetrate the building footprint. The building also has no electrical service or climate control, so any components within the barn must be battery powered and hardened for outdoor use. Finally, I wanted to spend as little money as possible and reuse things I already had in the parts bin.
The solution
Connecting the physical with the digital
I started with an existing indoor/outdoor hygrometer/thermometer that I already owned, consisting of a remote sensor and a separate display unit. The sensor is made to mount outdoors in all-weather conditions, and can run for months on standard batteries. The wireless connection between the sensor and display uses 433 mhz frequency, so it has a longer range and a better chance to penetrate the impregnable Wi-Fi barn fortress. It was the answer to the power, climate, wireless, and cost challenges, but there was one big problem: It's not a smart device, and it has no interface besides the display to indicate readings.
How to make a dumb device smart-ish
By adding a camera sensor to an existing Raspberry Pi that I already owned,I was able to write a flow that would take periodic photos of the hygrometer display, perform optical character recognition (OCR) on the photo, and send the digital values of temperature and humidity to Edge Connect. I made my first and only purchase for this project—a $9 RPi camera sensor—and set up a shadow box with the camera trained on the display.
Edge vs. cloud, personified in hay stack monitoring
My initial plan was to edge process these images using a JS port of Tesseract, an OCR package managed by Google. The first tests taught me a few things about OCR, namely that segmented characters found in LCD displays don’t mix well with it. Luckily, by sending the image via MQTT to Edge Connect, I can make it available for any cloud or server to process. Edge Connect can support binary payloads up to 256 MB, so sending the image is a lightweight step, very well suited for running on a Raspberry Pi. Because Edge Connect data is globally consistent, I can easily use different OCR providers to process the data and return a numerical value. Currently, I use a service called Impira that utilizes machine learning to perfect character recognition specific to my photos.
Node-RED for a simple flow
With the OCR processing moved off the device edge, my node-RED flow on the Raspberry Pi is straightforward. Simplicity of the device edge is important, whether one is monitoring a fleet of millions of devices or a single item. Avoiding service calls and visits to the edge saves both money and time, and the simplistic process on the Raspberry Pi should support that effort well. A commercial-grade solution might outweigh the benefits of edge vs. centralized processing and move workloads to the edge where it makes more sense. For now, I have a supportable solution that I can expand in many ways without ever having to access the device edge.
Using the data to make hay
As I’d originally hoped, I make use of the data in two ways. First, a simple threshold monitor can push a notification to my phone if humidity and temperature values are exceeded for a real-time view. I then export the historical data to a Google Sheet, allowing me to monitor these values over time and identify trends.
Solution summary
Below is a diagram of all the pieces working together, along with the node-RED flows that I use for both device edge and server.
Happy horses
We are very lucky to have access to wonderful, locally grown hay, and the horses confirm this with their good health and weight. Although my project was very small scale, the components and solution could ramp up to commercial grade with few changes, if any. IoT projects at the largest companies need to deal with the same challenges, by taking into account physical aspects, the environment, and the edge vs. cloud question. It’s useful to understand the various challenges associated with these trade-offs, in order to grasp the best solution for the problem.