Am trying with 4 DS18B20 and am able to collect data of 3 and send, but the problem is, the first data is wrong which should be 26.75 I get only 6.75. Code is as below.
sensors.requestTemperatures();
Serial.print("Temperature of 1st IC is: ");
tempC = sensors.getTempCByIndex(0);
temp = tempC * 100;
data[0] = temp >> 2;
data[1] = temp & 0xFF;
Serial.println(temp);
Serial.print("Temperature of 2nd IC is: ");
tempC = sensors.getTempCByIndex(1);
temp = tempC * 100;
data[2] = temp >> 4;
data[3] = temp & 0xFF;
Serial.println(temp);
Serial.print("Temperature of 3rd IC is: ");
tempC = sensors.getTempCByIndex(2);
temp = tempC * 100;
data[4] = temp >> 6;
data[5] = temp & 0xFF;
Serial.println(temp);
Serial.print("Temperature of 4th IC is: ");
tempC = sensors.getTempCByIndex(3);
temp = tempC * 100;
data[6] = temp >> 8;
data[7] = temp & 0xFF;
Serial.println(temp);
and after the decoding function at TTN
function Decoder(bytes, port) {
var temp0 = bytes[0] << 2|bytes[1];
var temp1 = bytes[2] << 4|bytes[3];
var temp2 = bytes[4] << 6|bytes[5];
var temp3 = bytes[6] << 8|bytes[7];
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
// if (port === 1) decoded.led = bytes[0];
return {
Temp0 : temp0/100,
Temp1 : temp1/100,
Temp2 : temp2/100,
Temp3 : temp3/100};
}
I get output as
{
“Temp0”: 7.27,
“Temp1”: 28,
“Temp2”: 28,
“Temp3”: 527.36
}