Payload formatter left shift problem

Hello Guys

I need some help decoding this payload, I did follow the below example but for the second item which is soil percentage i am not able to get it

Payload
01031C

010501B7005A004A000C00100028000000000000000000000000000088AC

As you can see I have commented others out while trying to work with the “soil_Moisture”.
The value is 01B7 which converted is 439. I am not able to get the value.

Could someone help me with the correct way of doing “left shift” please?

where

01 - sensor_address
03 - functional_code
1C – data_length

0105 -soil Temperature
01B7 – soil moisture
005A - EC
004A - PH
000C - N
0010 - P
0028 - K
0000000000000000000000000000 - empty bits
88AC - CRC

My code is as follows:-

function Decoder(bytes, port) {

//var soil_temperature = (bytes[4]) + bytes[5]*256;
var soil_Moisture = (bytes[6]<<8); + (bytes[7]);      I can't get the value of 439
//var ec = (bytes[8]) + bytes[9];
//var ph = (bytes[10]) + bytes[11];
//var N = (bytes[12]) + bytes[13];
//var P = (bytes[14]) + bytes[15];
//var K = (bytes[16]) + bytes[17];

//soil_temperature = soil_temperature; //display at Consol
//field2= soil_temperature; //display at ThinkSpeak IOT Cloud

//soil_Moisture = soil_Moisture/10 ;
//field3= soil_Moisture;

//ec=ec;
//field4=ec;

//ph=ph/10;
//field5=ph;

//N=N
//field6=N;

//P=K
//field7=N;

//K=K
//field8=N;

return{

  //field2,
  //soil_temperature,
  
  //field3,
  soil_Moisture,
  
  //field4,
  //ec,
  
  //field5,
  //ph,
  
  //field6,
  //N,
  
  //field7,
  //P,
  
  //field8,
  //K,
  
  };

}

The shift you have is fine.

JavaScript arrays are zero indexed ie the first byte is at position 0 - so you are off by one - you need bytes 5 & 6.

As a matter of form, always quote the whole minimum complete code - we can’t see what came before so I’m hoping there’s nothing ‘interesting’ going on before the first line provided.

As this is decoding, I moved it out of the decrypting topic it was in.

1 Like

As mentioned that is bytes[0], bytes[1], bytes[2],

So temperature starts at bytes[3] …

1 Like

dear @LoRaTracker and @descartes .

I worked for 2 days trying to find out where the error was and it took 2 of you 5 min to show me the error.
Thank you very much. I shifted the values 1 notched and it’s working perfectly. I am getting the correct value shown in RED.

A million thank you for the assistance and rescue :pray: :pray: :pray: :heart:

help

Regards
Subas

2 Likes

Dear @descartes and @LoRaTracker

Your assistants lead me to this and it’s working perfectly.

Thank you

Regards
Subas

2 Likes

Thank you for the thank you and the link to ThingSpeak - always nice to see a solution working all the way down to dashboard!

1 Like