Ubidots Community

Dragino LTC2 Temperature sensor

Hi All,

I successfully integrated my Dragino LTC2 Temperature sensor via TheThingsNetwork integration and the device appeared in Ubidots nicely. Now how do i obtain the temperature data from my sensor? I’m only getting SNR, RSSI and F-port…

I simply want to pull the value of “Temp_Channel1” into ubidots. Do you recommend how to accomplish this?

My payload in TheThingsNetwork looks like this:

"received_at": "2022-07-23T18:37:45.296352417Z",
"uplink_message": {
  "session_key_id": "AYIsWbmUiCHIQaOPePuzEA==",
  "f_port": 2,
  "f_cnt": 1,
  "frm_payload": "DmEBCZiAAWLcP/g=",
  "decoded_payload": {
    "BatV": 3.681,
    "Ext": 1,
    "Systimestamp": 1658601464,
    "Temp_Channel1": 24.56,
    "Temp_Channel2": -327.67
  },
  "rx_metadata": [
    {
      "gateway_ids": {
        "gateway_id": "farm-freezer-sj22",

Hey, nice to see you’re getting data flowing into Ubidots already! Can you confirm which Ubidots plugin you’re using for this, or if you’re using UbiFunctions?

Hello @whickey15,

I was able to check that you are using the TTS plugin. The good thing is that getting the “Temp_Channel1” data into your variable data is quite easy.

All you have to do is go to the Decoder tab of the Plugin and do a couple of changes. Lines 34 through 37 explain exactly what you need to do, however, since line 37 is commented it has no effect on the code.

  // If you're already decoding in TTS using payload formatters, 
  // then uncomment the following line to use "uplink_message.decoded_payload".
  // PROTIP: Make sure the incoming decoded payload is an Ubidots-compatible JSON (See https://ubidots.com/docs/hw/#sending-data)
  // var decoded_payload = args['uplink_message']['decoded_payload'];

If you erase the // that is in front of line 37, then the whole received payload will be included into the Ubidots Payload. However, if you only want the Temp_Channel1 reading, then you can do the following:

Within the code editor:

  1. Comment out lines 37, 41, 42, and 44
    //var decoded_payload = args['uplink_message']['decoded_payload'];
    //let bytes = Buffer.from(args['uplink_message']['frm_payload'], 'base64');
    //var decoded_payload = decodeUplink(bytes)['data'];
    //Object.assign(ubidots_payload, decoded_payload);

  2. Add the following line anywhere between lines 32 and 41:
    ubidots_payload['temp_channel1'] = args['uplink_message']['decoded_payload']['Temp_Channel1']

What this does is basically extract the Temp_Channel1 reading from the received data from TTS and adds it to the payload that will be sent to Ubidots.

I’ll be attentive in case you have any questions during the process.

Best regards,
Sebastián

Hi Sebastian!
Thank you so much for your detailed advice! I finally received my first “Temp_Channel1” datapoint in ubidots:

{
“success”: true,
“message”: {
“results”: [
{
“f_cnt”: [
{
“status_code”: 201
}
],
“f_port”: [
{
“status_code”: 201
}
],
“rssi-farm-freezer-sj22”: [
{
“status_code”: 201
}
],
“snr-farm-freezer-sj22”: [
{
“status_code”: 201
}
],
“temp_channel1”: [
{
“status_code”: 201
}
]
}
]
}
}

I actually got this code block from another post for someone’s “RAK1906 WisBlock Environmental Sensor”…I have a Dragino LTC2 sensor. Whats the best practice for integrating TTN to Ubidots for various products? Do most people write their own decoder? Or should I have contacted Dragino asking for their code? I plan to add more in the future

Hello there,

I’m glad that you now have temperature readings in your account.

If you are to have multiple types of devices, then the best practice would be to have the decoders completely in TTS, that is, have them take the sensor data and convert it to a human-readable payload (usually manufactureres provide a code for this or it can sometimes be found somewhere on the web). Then, also within the same TTS decoder, make sure that the payload is Ubidots compatible. This way the data that comes into Ubidots is agnostic of what type of device it was sent from and is immediately accepted.

For more information on what I mean by an Ubidots compatible payload, please visit our API docs.

If you’d like to test the full core of Ubidots for your project (by the way, I’d love to know more about it), and if you haven’t done so already, please feel free to open a Trial account here (select the “For Business” option).

As a final note, you could have downloaded the decoder for your LTC2 Sensor here (Sourced from Dragino’s website)

I’ll be attentive to any other question that you might have.

Thanks Sebastian, you’ve been extremely informative. I appreciate the time you took to educate me on this!

1 Like

Hey Sebastian, data has been flowing in! I feel sheepish asking cause I dont know javascript…Is it obvious to you i could edit my decoder code to convert celcius to fahrenheit? I use something like this in one of my home python script…looking to do the same in ubidots:

if data[“uplink_message”][“decoded_payload”].get(“Temp_Channel1”)==None:
print(“Temp Channel1 not found”)
else:
celsius = (data[“uplink_message”][“decoded_payload”][“Temp_Channel1”])
fahrenheit = “{:.2f}”.format((celsius * 1.8) + 32)
print(fahrenheit)