MinhVBryan Bui-Tuong
Published

Seeed Soil Moisture Sensors w/ Dragino RS485 LoRaWAN Module

Measure soil temperature and moisture level at different soil depths using three Modbus RS485 soil moisture sensors.

IntermediateFull instructions provided4 hours1,727
Seeed Soil Moisture Sensors w/ Dragino RS485 LoRaWAN Module

Things used in this project

Hardware components

RS485-BL -- LoRaWAN RS485/UART Converter -- WaterProof Battery Powered
×1
Seeed Studio Industrial Soil Moisture & Temperature & EC Sensor MODBUS-RTU RS485 (S-Soil MTEC-02B)
×3
Seeed Studio Industrial IP68 Modbus RS485 1-to-4 Splitter/Hub
×1

Software apps and online services

Putty
helium Console
TagoIO

Story

Read more

Code

Helium Payload Decoder

C/C++
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;
}

Credits

MinhV

MinhV

2 projects • 3 followers
IOT Engineer at Parley Labs. I love traveling, exploring new places, learning other cultures and trying out all the food.
Bryan Bui-Tuong

Bryan Bui-Tuong

3 projects • 7 followers
I like to build things. Father, Electrical Engineer, Real Estate investor, corporate rentals, Crypto Enthusiast.

Comments