I have done basically the same as what you did for ABP. Here I have encoded the values in 2 bytes. I even have a small issue that I have two different implementations with different encodings of the temperature. I solved it by letting the one device send it to port 1 and the second device as port 2. In my decoder function I then look at the incoming port number and decide from there how to decode it. I don’t want to go into too much detail on the source and I will leave you a link to my code for the ABP device.
The function I created in TTN:
function Decoder(bytes, port) {
// Sign-extend 16 bits to 32 bits
// Fewer parentheses needed when using bitwise OR rather than addition
var celciusInt = bytes[0] | (bytes[1] << 8);
switch (port) {
case 1:
if (celciusInt & 0x8000) celciusInt = (celciusInt & 0x7fff) * -1;
temperature = celciusInt / 100;
break;
case 2:
temperature = celciusInt * 0.0078125;
break;
}
I made it a bit complicated in the first try by multiplying the temperature with 100 and then set the top bit if it is negative. I did a better job of this in the OTAA code.
That would be a question about your sensor and the code to run it, not a TTN question.
Two likely possibilities are flakey wiring and counterfeit parts; in particular fake DS18B20’s seem to generally be slower than real ones, and not complete a measurement within the time specified by the data sheet.
Likely you want to add some logic to only transmit reading that seem valid. But again, that is a sensor question, not a TTN issue.