As the world continues to substantially warm, droughts and their unpleasant side-effects of wildfires, diminished water quality, and lack of crop irrigation will only increase in severity and frequency. In the US, ground-reaching precipitation and its accumulation in lakes/reservoirs are mostly tracked by governmental bodies or citizen scientist volunteers who take regular measurements and report it back to a central database for further analysis. This drought monitor, however, is meant for deployment anywhere and not only monitors water levels but also the presence of precipitation and several environmental datapoints.
Because of the emphasis on mobility and data gathering, this project relies on the Particle Monitor One and its suite of cellular and GPS connectivity. Environmental sensing occurs in several ways. First, a BME680 temperature/humidity/pressure sensor takes regular readings and reports it back to the Monitor One via I2C. Second, the ultrasonic distance sensor underneath the housing measures the distance from itself to the water's surface to detect changes in reservoir levels. And finally, since droughts and precipitation go hand-in-hand, there is a water detection board that alerts the Monitor One to the presence of precipitation.
The Monitor One supports swappable boards called Expansion Cards, and they allow for almost any pin to be exposed and easily prototyped with. In this case, the project replaces the existing I/O Card in favor of the Prototype Card which has much more space for soldering new components. The BME680 Environmental Click board sits on a header towards the front of the card and communicates with the Monitor One over I2C.
Because the HC-SR04 ultrasonic distance sensor and water detection module need to sit in an external enclosure, the 8-pin B8B-PH connector was wired as follows:
B8B-PH > Monitor One
8 > NC
7 > GND
6 > 3.3v
5 > NC
4 > A6 (WaterDetectPin)
3 > A5 (EchoPin)
2 > A4 (TrigPin)
1 > 5v
This lets the highly water-resistant M12 8-pin connector attach to the outside of the Monitor One without having to worry about water ingress. It should be noted that the HC-SR04 relies on a 5V input, so the incoming EchoPin
is first diverted to a voltage divider before being routed into A5
.
The drought monitor is meant to sit out in the field for long stretches of time before needing to be recharged, and could be left indefinitely if connected to a solar panel. Due to this constraint, the Monitor One was configured via the Particle Console to take a reading and report back the result once every 6 hours (set to once every 10 minutes in this example for demonstration purposes, however). When the location callback is triggered, the device will read the latest data from the BME680, HC-SR04, and the water detection sensor before storing it in a custom SensorData_t
struct. This data is then written as a JSON object and placed within the loc
event data payload that gets sent back in the form of a Particle Cloud Message.
Now that the Monitor One can consistently report environmental data, imagine there is a server endpoint which receives the data but only accepts CBOR-encoded payloads owing to their vastly more efficient memory usage when compared to plaintext JSON. Previously, the encoding would either need to be performed on the device itself or the server would still have to accept JSON, but the release of Particle Logic allows the Particle Cloud to execute this task.
The Logic script is based off the JSON transformation template and begins by attempting to parse the incoming event data as an object. Once successful, the cbor-x
vendor package encodes the object into a buffer that gets passed as a byte array to the Particle base64Encode
function. The now-plaintext value is lastly published under the drought-cbor
event name and with the same product ID as the Monitor One. All of these steps mean a webhook for the server that originally had to accept a JSON payload can now send a base64 CBOR string instead.
The 3D printed enclosure contains a small slot at one end for an 8mm threaded rod to attach and subsequently act as a stake in the ground next to a body of water. Once it had been firmly dug into the ground, the Monitor One was switched on and began taking measurements at a regular interval. The base64 output can also be seen in the Particle Console for the drought-cbor
event.
Comments
Please log in or sign up to comment.