Large farm requires a lot of attention and monitorization on the soil. LoRaWAN devices are the perfect solution for this scenario due to the large range coverage that is lacking from a WIFI enabled IOT device. In this setup, we will be using a Dragino RS485-BL along with three Seeed soil moisture sensor to get a detail view of the soil moisture at different soil depths.
Wiring the Dragino RS485 to LoRaWAN Converter
1. Wire USB-TTL Cable
In order to communicate to the RS485-BL, we will use the TTL-234X cable. In our case it does not matter if we use the 5V or 3V3 version since we are not using the cable to power the chip. Once we finished configuring the RS480-BL, we will not need this cable during operation.
Connection paths for GND, RXD and TXD
TTL-234x Pin1 (BLACK) <------> RS485-BL JP6 (GND)
TTL-234x Pin4 (Orange) <-----> RS485-BL JP6 (UART_RXD)
TTL-234x Pin5 (Yellow) <-----> RS485-BL JP6 (UART_TXD)
2. Wire Soil Moisture Sensors
I am using different color wiring from the output of the soil moisture sensor (above) to the input of the RS485-BL (below). The mapping is as following:
VCC+ (Red) above <-----------------------> VCC+ (Blue) below
VCC- (Black) above <--------------------> GND (Black) below
RS485+/A/T+ (Yellow) above <-------> RS485-A (White) below
RS485-/B/T- (White) above <---------> RS485-B (Green) below
Configure the Dragino RS485 to LoRaWAN Converter
1. Setup PUTTY
Download and Start PUTTY. You should see the following screen when PUTTY is started
Select "Terminal" on the left column then select "Force on" for both "Local echo" and "Local line editing". Do NOT press "Open" at this point yet
Select "Session" on the left column. Set "Connection type" to "Serial" and "Speed" to "9600". Fill out the correct COM port under "Serial line" then press "Open".
2. Add Power On Command for Soil Moisture Sensors
The RS485-BL has a built-in 5V output that we can use to power our sensors. However, the 5V is disabled and will only turn on during sampling. In order to give the sensors enough time during startup before we take measurements, use the following command to give 10ms startup duration.
AT+5VT=10
3. Configure Modbus Address for Each Soil Moisture Sensors
By default, each moisture sensor comes with a preset Modbus address of 18 (0x12H). This poses a problem for us since we want each sensor to have a unique address in order for us to daisy chain them. To fix this, we will sequentially change each sensor to a unique address. NOTE: Make sure to only connect ONE sensor at at time and must swap out to another one before moving to the next command.
Attach the first sensor to RS485-BL then execute the following command:
AT+CFGDEV=12 10 02 00 00 01 02 00 01,1
Disconnect the first sensor. Connect the second sensor then execute the following command:
AT+CFGDEV=12 10 02 00 00 01 02 00 02,1
Disconnect the second sensor. Connect the third sensor then execute the following command:
AT+CFGDEV=12 10 02 00 00 01 02 00 03,1
After completing these steps, we will have three sensors with address 1, 2 and 3.
4. Add Sampling Command
RS485-BL can store up to 16 Modbus sampling commands. In order to request data from all three soil moisture sensors, add the following Modbus commands to RS485-BL. These commands must be entered exactly as shown into PUTTY for it to work correctly with the provided decoder.
Request Temperature, Volumetric Water Content, Electrical Conductivity, Salinity, Total Dissolved Solids and Dielectric constant of sensor with Modbus address 1
AT+COMMAND1=01 04 00 00 00 06,1
Request Temperature, Volumetric Water Content, Electrical Conductivity, Salinity, Total Dissolved Solids and Dielectric constant of sensor with Modbus address 2
AT+COMMAND2=02 04 00 00 00 06,1
Request Temperature, Volumetric Water Content, Electrical Conductivity, Salinity, Total Dissolved Solids and Dielectric constant of sensor with Modbus address 3
AT+COMMAND3=03 04 00 00 00 06,1
5. Add Processing Command
There are 16 “AT+DATACUTx” slots corresponding to 16 “AT+COMMANDx” above. These datacuts provide a mean to filter out the actual data from overhead. RS485-BL also uses datacuts to assemble the payload to send over LoRaWAN.
Send the following datacut commands to the RS-485 converter using PUTTY.
Receive Temperature, Volumetric Water Content, Electrical Conductivity, Salinity, Total Dissolved Solids and Dielectric constant of sensor with Modbus address 1
AT+DATACUT1=17,2,4~15
Receive Temperature, Volumetric Water Content, Electrical Conductivity, Salinity, Total Dissolved Solids and Dielectric constant of sensor with Modbus address 2
AT+DATACUT1=17,2,4~15
Receive Temperature, Volumetric Water Content, Electrical Conductivity, Salinity, Total Dissolved Solids and Dielectric constant of sensor with Modbus address 3
AT+DATACUT1=17,2,4~15
6. Split Payload Transmission Configuration
Since there are too many bytes for one transmission to handle, we have to enable split payload using the following command:
AT+DATAUP=1
7. Assembling Payload
The LoRaWAN payload is automatically assembled by the RS485-BL using all returned data from DATACUTx. Since we are using split payload, the payload has the following structure:
PAYVER + PAYLOAD INDEX[0] + DATACUT1 + DATACUT2
…
PAYVER + PAYLOAD INDEX[6] + DATACUTD + DATACUTE
PAYVER has a default value of 0x01 but it can go up to 0x0f to accommodate more RS485-BLon the network.
Adding the Dragino RS485 to LoRaWAN Converter to the Helium Network
1. Register for a Helium Console Account
We will be using the Helium Network as our LoRaWAN network provider because of their large network coverage and low fee. You can check out more about them here.
In order to receive data from the Helium LoRaWAN network, we will create a Helium Console account here. Once you created the account and logged in, you will see the following page:
2. Adding Data Credit
Every new Helium Console account comes with 10, 000 data credit which will provide about 6 months of data for the soil moisture sensors. However, if you want to add more, hover over the DC balance on the top right of your screen and click on "DC Balance" which will take you to the following screen. The minimum purchase with credit card is $10 which will give you plenty of data credit to use with the soil moisture sensor.
3. Adding theDragino RS485 to LoRaWAN Converter to the Helium Network
Select "Devices" on the left column, then "Add New Device". Every Dragino RS485 converter comes with a sheet containing the Dev EUI, App EUI, and the App Key. Enter a name for your device and populate the Dev EUI, APP EUI and App Key. Once completed, proceed to "Save Device".
4. Adding Payload Decoder
Select "Functions" on the left column, then "Add New Function". Set all fields the same as seen below.
Copy and paste the following function into the custom script box.
function Decoder(bytes, port) {
var payload_index = bytes[4];
var decoded_frame ={};
//Payload index of 0 contains soil temperature (C), Volumetric water content (%), Electrical Conductivity (us/cm) of probe 1
if (payload_index == 0)
{
decoded_frame.bat_v = (bytes[0]<<8 | bytes[1])/1000;
soil_temp_raw = ((bytes[5]<<8 | bytes[6])^1)+1;
if (soil_temp_raw > 32767)
{
decoded_frame.temp_1 = (soil_temp_raw - 65535 - 1)/100;
}
else
decoded_frame.temp_1 = soil_temp_raw/100;
decoded_frame.vwc_1 = (bytes[7]<<8 | bytes[8])/100;
decoded_frame.ec_1 = (bytes[9]<<8 | bytes[10]);
}
//Payload index of 1 contain salinity (mg/L), total dissolved solids (mg/L) and dielectric constant of probe 1
else if (payload_index == 1)
{
decoded_frame.bat_v = (bytes[0]<<8 | bytes[1])/1000;
decoded_frame.salinity_1 = (bytes[5]<<8 | bytes[6]);
decoded_frame.tds_1 = (bytes[7]<<8 | bytes[8])
decoded_frame.epsilon_1 = (bytes[9]<<8 | bytes[10]);
}
//Payload index of 2 contains soil temperature (C), Volumetric water content (%), Electrical Conductivity (us/cm) of probe 2
else if (payload_index == 2)
{
decoded_frame.bat_v = (bytes[0]<<8 | bytes[1])/1000;
soil_temp_raw = ((bytes[5]<<8 | bytes[6])^1)+1;
if (soil_temp_raw > 32767)
{
decoded_frame.temp_2 = (soil_temp_raw - 65535 - 1)/100;
}
else
decoded_frame.temp_2 = soil_temp_raw/100;
decoded_frame.vwc_2 = (bytes[7]<<8 | bytes[8])/100;
decoded_frame.ec_2 = (bytes[9]<<8 | bytes[10]);
}
//Payload index of 3 contain salinity (mg/L), total dissolved solids (mg/L) and dielectric constant of probe 2
else if (payload_index == 3)
{
decoded_frame.bat_v = (bytes[0]<<8 | bytes[1])/1000;
decoded_frame.salinity_2 = (bytes[5]<<8 | bytes[6]);
decoded_frame.tds_2 = (bytes[7]<<8 | bytes[8])
decoded_frame.epsilon_2 = (bytes[9]<<8 | bytes[10]);
}
//Payload index of 4 contains soil temperature (C), Volumetric water content (%), Electrical Conductivity (us/cm) of probe 3
else if (payload_index == 4)
{
decoded_frame.bat_v = (bytes[0]<<8 | bytes[1])/1000;
soil_temp_raw = ((bytes[5]<<8 | bytes[6])^1)+1;
if (soil_temp_raw > 32767)
{
decoded_frame.temp_3 = (soil_temp_raw - 65535 - 1)/100;
}
else
decoded_frame.temp_3 = soil_temp_raw/100;
decoded_frame.vwc_3 = (bytes[7]<<8 | bytes[8])/100;
decoded_frame.ec_3 = (bytes[9]<<8 | bytes[10]);
}
//Payload index of 5 contain salinity (mg/L), total dissolved solids (mg/L) and dielectric constant of probe 3
else if (payload_index == 5)
{
decoded_frame.bat_v = (bytes[0]<<8 | bytes[1])/1000;
decoded_frame.salinity_3 = (bytes[5]<<8 | bytes[6]);
decoded_frame.tds_3 = (bytes[7]<<8 | bytes[8])
decoded_frame.epsilon_3 = (bytes[9]<<8 | bytes[10]);
}
return decoded_frame;
}
We will continue setting up Helium Console after finishing the next section.
Setting Up Tago.IO for Data Visualization
1. Register for a Tago.IO Account
In this guide, we will use Tago to display all data coming from Helium. Register for a free account with Tago and once you are logged in, you will see the following screen.
2. Add New Device to Tago
Select "Devices" on the top left corner, then select "Add Device".
Select "LoRaWAN Helium", then select "Custom Helium" as shown below.
Once you selected "Custom Helium", the following screen will appear. Give your soil moisture sensor a name and set the "Data Storage Type" to "Device Data Optimized". For data retention, set your desirable timeframe that you want Tago to retain data. In this example, we will set it to one month. Fill in the EUI field with the Dev EUI that you used when adding the Dragino RS485 converter to Helium Console. Once done, press "Create My Device",
3. Add RS845-BL Soil Moisture Sensors Dashboard to Tago
Use the following link to automatically install the soil moisture sensor dashboard to your Tago account. Select "Install Template" when prompted as shown below.
Select the device name that you added earlier. In my case, I named the device as "RS485-BL Triple Soil Moisture Sensor" so I selected that option from the drop-down menu. Select "Confirm associations" once you are done.
4. Adding Tago Authorization to Helium Console
At this point, you will see the newly created dashboard on your homepage. However, the dashboard should be empty since you have not gotten any data yet due to the fact that we have not link the Tago account to our Helium Console account. To do this, select your profile name on the top right corner, then select "My account"
Select your profile name on the left, then click on "Token", set permission to "full", and to never expire, then "Generate Token". In order to copy your token, click on the copy symbol as show below.
Now log back into your Helium Console account, click on "Integrations" on the left column then add TagoIO.
Paste your newly created Tago token in the the Step 2 box below.
5. Flow Diagram
Finally, we are on the last step. This step will tie everything that we did previously together and allow you to see all your soil moisture sensors output on TagoIO.
While in Helium Console, click on "Flows", then add the following items and connect them together. In our case, we will add the soil moisture sensors and its decoder function and the TagoIO authorization.
TagoIO Dashboard Visualization
Congratulation, you are now done! Go back to your Tago dashboard and see all the data fields getting populated as more data come through!
Comments