LMIC ttn-abp DS18b20

I need an example to transmit data temperature in TTN with sensor DS18b20

I have the following code => ds18b20_ttgo-esp32_lora/lora_ds18b20.ino at master · Mangulomx/ds18b20_ttgo-esp32_lora · GitHub

In my TTN I received as payload the image below.

08

My payload is

function Decoder(bytes, port) {
var text = String.fromCharCode.apply(null, bytes);
return {
message: text
}
}

How can I show temperature correctly?

Your code encodes binary values, for efficiency it does not send readable text.

You need to decode a 16 bit big-endian integer, and an 8 bit one

This is likely something you can look up how to do, or perhaps someone with more familiarity with server side TTN decoders can chime in.

1 Like

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;
}

return {
Temp: temperature
};
}

Here are links to my Github pages:
Github to ABP code

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.

1 Like

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.

Ok sorry. I think It later that can be the time and put delay after

The code here => https://create.arduino.cc/editor/mangulo/abf0a4fa-3062-4bc8-a8ab-e61fe8eff14f/preview
I get the following error.
Node v0.2
Trigger Temps
Read Temps = 25.25
Read Temps = -127.00

Stack smashing protect failure!

abort() was called at PC 0x400da3e8 on core 1

Backtrace: 0x4008b8f4:0x3ffb1ea0 0x4008bb21:0x3ffb1ec0 0x400da3e8:0x3ffb1ee0 0x400d0f69:0x3ffb1f00 0x400d0f73:0x3ffb1f30 0x400d12d9:0x3ffb1f50 0x400d6897:0x3ffb1fb0 0x40087a71:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9344
load:0x40080400,len:6348
entry 0x400806a8
Node v0.2
Trigger Temps
Read Temps = 25.25
Read Temps = -127.00

Stack smashing protect failure!

abort() was called at PC 0x400da3e8 on core 1

Backtrace: 0x4008b8f4:0x3ffb1ea0 0x4008bb21:0x3ffb1ec0 0x400da3e8:0x3ffb1ee0 0x400d0f69:0x3ffb1f00 0x400d0f73:0x3ffb1f30 0x400d12d9:0x3ffb1f50 0x400d6897:0x3ffb1fb0 0x40087a71:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9344
load:0x40080400,len:6348
entry 0x400806a8
Node v0.2
Trigger Temps
Read Temps = -127.00

is that an observation, a question… what is this ?

  • I’ve asked you before to keep everything related to your temp sensor problem in one topic