RAK/Meshtastic Based Irrigation Monitor
by 406jem in Circuits > Microcontrollers
34 Views, 0 Favorites, 0 Comments
RAK/Meshtastic Based Irrigation Monitor

In the before times...
I had a need for an irrigation monitor system to support our efforts to turn water and sunshine into plants and save some trips to the fields to see if the water was ready to change over. So I built some out of Arduino feathers.. they were hinky, but they worked, pretty well actually. Just a simple 2 device build using lora to communicate between the monitors (I had several built) and a few receivers with some LEDs that lit up depending on the status of specific water monitors. They worked well... so guess what I'm not gonna tell ya how to build?
I discovered a better way? ... Nerdier anyways, but I think ultimately better, simpler.
Work Smarter Not Harder...
One day I discovered Meshtastic and decided it was pretty neat. I started ordering prebuilt 'componentized' devices and tried out some RAK hardware.. loved it.
I obviously wanted to build v2 of the irrigation monitors using Meshtastic and make it bigger and better... and more maintainable honestly so I attempted a hardware stack hoping it was supported. It was not... No problem.. I'm a dev right.. Meshtastic is open source, so I'll 'do computer' and get it sorted out. Ya.. it's been a while since I did anything with C++ and then there was the discovery of Platformio. Anyways, many months later and with some help from the moderators on the firmware contribution (thank you..); we have ALMOST arrived. It is not in the current beta software quite yet, but I wanted to put a pin in this one so badly that I'll happily come back and make a few edits once the pull request has been merged into the main project.
So the Good News...
The work has been done at this point and the code is making it's way into the main branch of the project! If you aren't sure what that means, it's good.. less work. :)
Our Use Case...
We have a couple river bends that we have a mixed irrigation solution on each riverbend. All our irrigation methods result in simple flood irrigation that spans from one side of the field to the other and is contained in between border dikes in what is commonly called a 'land'. So... we flood this area with water; when one is done we move to the next and so it goes. It's a little more complicated than all that as the goal is not to slowly do one land at a time, commonly it is a race against resource constraints in the area we farm so time is critical and wasted water is agonized over.
... anyways.. what the solution looks like. We have 2 riverbends, 3 fields on one 2 on the other. I made multiple H20 monitors and they can be used anywhere within the range of our Meshtastic devices.. Perfect. More range please.. So we add a repeater at each field with a big antennae and we in business! (kinda.. I was just there updating/testing last weekend after winter and while everything is .. basically awesome.. I want more range.. building another repeater.. carry on.)
TL;DR
- 2 Riverbends,
- 5 Fields between them,
- multiple 'lands' per Field (this is what we are actually monitoring the moisture on)
- 1 Repeater on each Riverbend
- built 5 Soil Monitors total, cause Meshtastic.. it doesn't really matter what 'land' they are currently on.
- basically we are trying to fully flood on 'land' at a time so we dump water in at one side and use the Amazing Meshtastic H2O Monitoring Bucket at the other end to let us know when the 'land' is fully covered with water.
- Couple Meshtastic devices we have for in our trucks or carrying around.. these are the ones we pair with our phones that allow us to check the status of the H2O Monitors.
- So.. We place monitors on the lands we are flood irrigating.. We carry around or stay close to a Meshtastic device that is paired with our phone.. The Monitor gets ... moist. We can see just how moist the monitor is on our phones. We can just efficiently go move the water and the H2O monitor to the next land and carry on with the day.
Below...
I will cover the build using the RAK WISBLOCK components I have used, but I'll just give a quick description of the amazing buckets I mounted the enclosure to.
Bonus Content: How to Destroy a Bucket (w/ purpose)
For a stable and functional platform to mount the irrigation monitors to I cut some slots into the bottom of five gallon bucket, zip tied a chunk of 2 inch(ish) plastic tube inside the bucket to hold the monitor vertical and protect it, and mounted the enclosure on the bucket lid so it would get lotsa sun. A few rocks in the bucket to keep it in place in the wind and such.
Supplies











RAKWireless WisBlock Components (Hardware)
- Unify Enclosure IP67 (optional, but good.. if your smarter than me you can probably find one with the correct ports for the m8 connector to pass through and a spot to mount a better button).
- WisBlock Kit
- RAK19007 (Base Board)
- RAK4361 (Processor)
- RAK12035/12023 Soil Sensor(s)
- RAK12500 (GPS/GNSS) (optional)
- A Battery (i recommend at least 10k mAh, but really it depends on your environment and use case)
Tools
- Soldering Iron
- Lil' Screw Drivers
- Drill and a Half inch bit
- Wire Cutters
- Multimeter
- Computer w/ USB port
- (suggested) A usb c-type 90 degree female/male plug or a cable with a 90 on it to make it easier to attach to the usb-c when the RAK baseboard is mounted in the enclosure.
Cables & Connectors
Note: The goal here is to get a set of 6 pin m6 connectors that will allow you to pass the sensor cabling thru the enclosure.. Mix and match to achieve THIS -> an m6 MALE connector designed to mount into the enclosure and an m6 FEMALE connector that has pigtails. You can literally do the opposite and it will not matter.. The important thing is to get 6pin and make sure one of them is designed to pass work with the hole that is already in the encloser and the other plug should work with that one.
- A Water Proof (Latching) Button
- USB c-type DATA cable (you need a real data cable to interface w/ the RAK)
- m8 6-pin female connector w/ pigtails. (unfortunately I did not use these.. I grabbed a much more expensive option that ultimately resulted in more work for me and wasted material. Patience and planning folks.)
- waterproof m8 6-pin male connector w/ threading, nut and pigtails.
- some Male/Female RAK compatible battery cable connectors.
- some Male RAK compatible solar power connectors.
Meshtastic Firmware
Meshtastic Firmware Variant 4361 - Version (>= ???) (web flasher)- Stable Build of the Meshtastic Firmware from my GitHub Repo (for now).
- Meshtastic Client App available on your phone/device app store
I gave links above, but if you want to get almost all the hardware including enclosure from RAK Wireless you can check out their store here, or Rokland (the US distribution partner) for supplies.
Download the Meshtastic Client App & (optional) Pair a Meshtastic Device

So it is important to understand what Meshtastic actually is and how to use it before using it in a more complex scenario (like monitoring soil conditions). The use case here is not too complex, but Meshtastic itself is very powerful so it's important to understand the basics. I'm not here to write that tutorial so I'll reference the official getting started guild and go over the basics.
- Meshtastic is software
- we do two things to effectively 'use' Meshtastic...
- Install the client app on a device like a computer or a phone..
- Get this (Meshtastic app) from your app store and install it on your device or you can use their web client (client.meshtastic.org) on your computer's internet browser.
- Flash a Meshtastic compatible device (like a RAK 4361, Heltec v3, LilyGo, etc) with Meshtastic firmware..
- They make this very easy.. make sure your usb cable is a data transfer cable, go here (flasher.meshtastic.org) on your internet browser, select your device, follow the instructions.
- The most basic way to use Meshtastic is with at least 3 or 4 'devices'. 2 of these devices would be phones or computers that are paired with the Meshtastic devices. It is a weird statement and hard to put into words.. so picture.
- Meshtastic Devices communicate with one another each extending the network and work together to form a 'mesh' of interconnected nodes that propagate information to all nodes.
- Meshtastic is extendable
- Meshtastic is a very popular open source project so the sky is kinda the limit in terms of it's adaptability and extendibility. It is already very well established and thoughtfully designed so you can do a lot of stuff with it already.
- Meshtastic is for everybody.
- This statement kinda stands alone.. Please be respectful of the project and realize how much work went into this so far so EVERYONE can use it. These devices have limits so be careful how much data you are putting out there and that it is appropriate data.
OK.. enough about them.. more about ME! jk.. on with the project stuff.
I highly encourage you to have the Meshtastic phone app installed and a device such as a Heltek v3 that u can use as a Meshtastic Radio and pair it with your phone before moving on to the next steps.. Not required, but everything will make a lot more sense with a little preparation and understanding.
(Re)build the H2O Monitor Cable

This is just one of those things that is not super fun.. In order to pass the H2O monitor cable through the enclosure we need to modify it. Basically we just need to put the m8 connectors in line so we can pass through the existing hole in the enclosure with the male m8 connector and connect to it using the female m8 connector. The part that makes it not so fun is there are quite a few wires and the connectors on the RAK12035 sensors are already shrink wrapped so it's either test, label, cut or get rid of the waterproofing shrink wrap. also don't forget to get your tiny shrink wrap.. for the tiny wires.. ugh.
I don't really have any images of me soldering the wire cables together, but the easiest way to avoid 'getting your wires crossed' is to just cut and then solder them one at a time. If you plug the m8 connectors into one another the wire color pattern is the same for both so you can cut a wire then solder the lose ends to that color on each side and you will get them soldered correctly with minimal overthinking. :) Don't forget to put shrink wrap on for each wire, each side, and one big piece each side to cover the entire job; this need to all be very waterproof. So.. take your time with this and test your cable as well as you can once it's completed (or as you are cutting label very well).
If you destroyed the waterproofing around the actual monitoring stick then replace it with.. something very waterproof. :) Lacquer will work.. for a while; I suggest something a lot more permanent though, waterproof shrink wrap and electroseal (spray on rubber waterproofing) perhaps.
Calibrating the RAK12035 Sensors
This is not required because I setup default values for sensors that have not been configured, but it's highly recommended as it will GREATLY increase the accuracy of your sensors.
I'm not sure if it actually matters, but I waited until after I modified the cables to actually calibrate the RAK12035s .. I did calibrated each sensor by using the Arduino IDE and following the code for the 'configuration' example here. If you need additional guidance setting up the Arduino IDE and flashing the code this may be helpful. You can just use one Arduino device (you can use the RAK we just put together if you want) with the calibration software to calibrate all your RAK12035s one at a time. 0nce done you can flash the Meshtastic firmware on your device again or just set everything aside and move to the next step. The sensors store their calibration values so once you calibrate them they don't need to be recalibrated.
Assemble the Hardware





I really recommend assembling and testing the WIS Block components first outside of the case...
- RAK baseboard (19007),
- RAK 4631 module in CPU SLOT,
- ATTACH A BLUETOOTH ANTENNA TO THE 4631,
- ATTACH A LORA ANTENNA TO THE 4631,
- RAK 12023/12035 (soil sensor) module in IO SLOT,
- RAK 12500 GNSS GPS module in SLOT A,
- leave the battery unplugged for now.
You can now connect your RAK to your computer and go to flasher.meshtastic.org/ on your computer's internet browser and flash the device with the most recent firmware. This is really just to test the device and pair with your phone app if you like. We will put put modified firmware on it in the next step.
Once flashed...
- Can you pair your phone with it using the app?
- Can you get into the configuration screen?
If so you can unplug the usb and set the assembled RAK device aside for a moment and grab your case. We don't want to shove things into the case immediately, we actually want to deconstruct the case as much as possible to begin the process. This is probably already the situation, but if you find that somehow things magically attached themselves to one another.. undo that. :)
- Drill a single 1/2 inch hole (or whatever size is appropriate for you to mount the latching button in your enclosure) and mount it,
- Make a power button 'harness' for your battery by basically placing the button inline on the positive lead, assemble battery/power button harness. and test it with the voltmeter.
- Disconnect the battery and install the button.
- (optional) Attach the usb-c type 90 degree adapter to the RAK.. This will make it WAY easier to connect the usb cable to it once it's mounted in the enclosure.
- I recommend you stop short of installing the device in the enclosure. It's just easier to work with and troubleshoot if you leave it out.
Flash the RAK WISBLOCK Device (yes, Again) You Just Assembled

This time we are going to put the firmware that works with the Soil Monitor on the device. Don't follow the instructions that are crossed out, follow the directions at the bottom of this step for now.
Time to flash the device with the RAK firmware.. any version greater than ???.
Note: The power button does not need to be on/battery does not need to be connected when the use is plugged in.
Another Note: Make sure your antennas are all plugged in EVERY TIME you power up the device... the LORA transmitter is especially prone to burning out if it doesn't have the resistance the antenna provides.
Plug your RAK into the usb with your data cable if it isn't already and navigate to flasher.meshtastic.org,Click the 'Select Target Device' Button and select 'RAK WisBlock 4631'When the page changes back to the original viewensure that the selected firmware version is >= ???, if not then click the dropdown list and look under 'Alpha' to select an appropriate firmware version.Click the 'Flash' Button and read the instructions on the following screen.TL;DR.. As you proceed it's gonnadownload a file,expect you to 'mount' the device as a usb by invoking 'DFU' mode (there's a button for this and if that doesn't work double click the user button on the RAK),and finally copy the file you downloaded into the device window (basically drag and drop it like you would putting a file on a usb drive).Do the thing.. once the file is completely downloaded to the RAK the device will restart and now you are ready to grab your phone and open up the Meshtastic app so you can pair to the device using Bluetooth.
All that's for the future, for now you can go to a repo I created here with the modified firmware and instructions to flash your device. At some point in the future the code for the RAK12035 will be a part of the main firmware and the instructions above will be valid.
(Optional) View RAK Serial Output on Console


I'm not gonna get too deep into this, but if you like it is possible to view the output from the device when it is plugged into your computer. If there are issues and you need to debug this is very handy. I'll simply say that I use VSCode and the platformio plugin for VSCode to do this. See setting up Platformio w/ VSCode.
Another useful utility for troubleshooting and interacting with your Meshtastic Device is the Meshtastic Web Client that basically takes the place of a phone or other device you would 'pair' with your device using bluetooth.
Finish Assembly


Note: Yours isn't gonna look exactly like mine.. I put an extra button in there I intend to make use of down the line.
- Mount the RAK 19007 (and everything on it) to the plastic plate making sure nothing is stressed twisted or crushed.. if it doesn't fit now.. your doing it wrong. ;)
- Plug in the button harness to the RAK, ensure the button is in the 'off' position, plug the battery into the other side of the button harness, ensure the antennae are properly attached to ALL connectors (EVERY antenna connector on the board SHOULD be connected to an antenna), attach the solar panel if you have one, power on the device using the button, physically watch the device come online, check voltages, attach to a serial console if you like, check your phone app,etc.
- Don't get too excite if you are not seeing sensor data yet.. there is some configuration to do before that happens.
Setup a Channel for Your H2O Monitors OR Copy Channels From Another Monitor

So this is a Meshtastic thing... If you want your telemetry data to propagate properly over the network and be private you need a private channel. This will do a few things for you..
- Allow your encrypted data to flow freely to your device restricting it to the private channel,
- Allow private communications (text) between node across the channel (anyone that is a member of the channel can message anyone else on the channel securely),
- and finally if GPS is enabled on the device (and allowed on the channel) it can be securely requested and received by other devices on the channel.
If this is your first device we need to do a few extra steps.. Unless you want to blast the public 'long fast' channel with all your data (you don't) you NEED a private channel. Once you have the list of channels you want your devices to have things become a lot simpler. You can find more info about Channels and their associated settings here.
First time only steps...
- In your Meshtastic app (or on the web client) with the Meshtastic RAK Sensor selected and paired...
- Go to the 'Channels' tab,
- Click 'Edit',
- Click 'Add',
- Name your new Channel and select 'Position enabled' so the Channel will allow for the sharing of accurate location info (the other two options have to do with forwarding and receiving messages from the internet and can be turned on later if you like),
- Click Save.
- The device will restart itself.
- Now That you have a Channel created we want to make it the Primary Channel. The devices only broadcast and receive telemetry data on the primary channel.
- Once the device restarts we are going to navigate to the device's configuration area in the phone app, directions for doing this with the web client will not be included here.
- This is the basic Process to navigate to the config page.. I will only describe it here.. Select the 'Users' tab, click the 'short name' of your device, click 'More details' in the popup, scroll to the bottom of the page and select 'Remote Administration'.
- In the 'Radio Configuration' section click 'Channels',
- Drag & Drop your new channel to the top of the list and hit 'Send' to send the new Channel order to your device.
- We now have a private Primary Channel created with the correct permissions and it's own encryption. You can create as many private channels as you like, but you can only have ONE primary and that is the ONLY place telemetry data can live.
If you already have your Channel(s) setup...
- Make sure your device that already has the Channels configured is paired
- Select the Channels Tab,
- Copy the URL,
- Connect to the new device you are setting up (in the phone app use the gear icon to pair with the device that doesn't have the correct Channel(s) on it),
- Replace (paste) the URL from the first device into the URL field of this device,
- Click 'Done' and follow the prompts to 'Replace' (not Add) the Channels,
- Make sure and Select 'Send'.
- At this point I like to manually restart the device (using the restart option on the device's config page in the app).
- Now you have just added the Channels to the new device.. to setup the Channels on many more devices just rinse, wash, repeat.. All you are doing is copying the url from a device that already has the Channel setup completed and putting that url on the new device and overwriting it's current Channel setup by saving (hitting the 'Send' button) the config.
As more nodes are added to the channel you will begin seeing them populate in the app. Nodes will populate (appear in the app) when the Meshtastic device you are currently connected to becomes aware of them (gets a message or data packet from them).
Configure the RAK WISBLOCK Device As a H2O Monitoring Device

More Meshtasctic configuration.. You know how to change between devices, you know how to get to the configuration screen.. Probably a bunch of other stuff about the app now too so I'll just give ya the config area and settings I have and expect you fully know you can do whatever you want at this point.
Soil Monitor Meshtastic Config - all below is in context of being on the device config (Remote Administration) page in the app
- 'User'
- Give your monitor a fitting name
- Click Send. (It will restart)
- 'Device'
- Role: SENSOR
- You can change 'Rebroadcast mode' to whatever you feel appropriate too.. I left mine as is (ALL)
- Click Send. (It will restart)
- 'Position'
- if you installed a GPS module...
- ensure it is ENABLE
- Click Send if you needed to make a change.
- if no GPS module installed...
- ensure it is set to NOT PRESENT
- Click Send if you needed to make a change.
- 'Bluetooth'
- I set mine to FIX and am using the same passcode for all my devices to keep things simple. Dynamic with a screen would be better imo, but no screen on this build.. this is what works.
- Click Send. (It will restart)
- 'Security'
- If you want to be able to do 'Remote Administration' through a connect with another Meshtastic radio device (as opposed to being directly connected) then you will want to add the public key of the 'Master' device in the 'Admin Key' Section. You can read more about this here.
- Click Send. (It will restart)
- 'Telemetry'
- Note: The most critical thing here is turning on the 'Environmental module enabled' setting, this is what tells the device to send the environmental data including the soil sensor data to the mesh. The other thing I did here was to stager the 'update intervals' between different devices so they were not all broadcasting at the same regular interval.. I did this in order to not oversaturate the lora Channel.
- Set your Device update interval to something appropriate or leave as default,
- Set your Environmental update interval to something appropriate or leave as default,
- Set your Power Metrics update interval to something appropriate or leave as default,
- turn ON...
- Enviromental metrics module enabled
- Environmental metrics on-screen enabled
- Enviromental metrics use Fahrenheit
- Power metrics module enabled
- Power metrics on screen enabled
- Click Send. (It will restart)
Of course as far as the configuration of your device goes it is up to you.. again, the most important thing to note here is you MUST enable Environmental module in the config to get ANY data from the Soil Sensor on your app.
Field Test & Enjoy


So now that you have soil sensor monitors.. You will want at least one Meshtastic device to act as a 'CLIENT'. This is the one you will carry around or have in your truck and have paired to your phone. It will be responsible for receiving environmental data from your sensors and giving that data to your phone app so you can see what is going on. It also just is your basic Meshtastic Radio device for sending and receiving messages from other Meshtastic users (both on your Channel and on the Public (pre configured Long-Fast) Channel.
Pair your Meshtastic Radio Device with your phone.. fire up one of your sensors.. do things. I suggest having a hose handy or at least a wet washcloth or paper towel. but you should be able to manipulate the state of the sensor and see it update in your phone app. Things are happening in real time, but they are not magically instant. Keep in mind your intervals you set on the sensor as well as allow time for data propagating from device to device when testing.
Optional, But Highly Recommended.. Build Meshtastic Repeaters for Your Network!

If you are needing to cover any significant amount of distance it is wise to plan for it. While a pair of Meshtastic nodes can connect over an impressive distance, this is very much dependent on your transmission power (which is legally limited) and the antenna dbi rating (again legally limited) and positioning (the higher the better). A number of environmental factors go into the decision making around what antenna and where to mount it as well so it is worth a little research and consideration before selecting these items (antenna, cable (if needed), booster, mounting hardware). What I'm getting at here is you are not gonna want to pack around the type of antenna you really need to optimize range... we just want our carry radios to work.. get the data.
Easiest way to make sure we are in the coverage area is increase the coverage area by adding a few Repeater or Router type Meshtastic nodes. We can power these with solar, house them in waterproof cases, give them big boy antennas and position them as we choose. I added two and one later for my purposes but it was worth a little explanation at least. Here is an Instructable describing how to build a repeater node with a pretty creative solution for a case.
Good stuff, only notes..
- you can go up to a ten dbi antenna if you like, look into the broadcast profiles of the different antennas and even the directional options before selecting. Your environment is the biggest thing to consider here, but you will see how that applies as you understand the broadcast profiles of the different options.
- this could just as easily be configured as a Repeater if you had a reason, there are slight differences some resulting in more efficient power use.
- there are probably better options for cases (nicer than the one I cobbled together from random parts I had laying around), but it is an all in one solution w/ appropriate solar panel. :)