Trying to integrate with The Things Stack Community Edition

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
adafruitguy
 
Posts: 206
Joined: Sat Jun 07, 2014 7:52 am

Trying to integrate with The Things Stack Community Edition

Post by adafruitguy »

I've had a lot of success getting LoRa devices to talk to The Things Network (TTN) -> Maker Event -> IFTTT -> Adafruit IO. But, now that legacy TTN v.2 is read-only and new devices need to be added to the The Things Stack Community Edition, I need some advice.

Maker Event is not an option with The Things Stack, and I'm trying to integrate directly with Adafruit IO via Webhooks. I can write raw data and send notify messages (pings). Data from The Things Stack is not in the "value" key, so Adafruit IO is treating the /raw blob as plain text and not as usable data.

Has anyone had success integrating between Things Stack Community Edition and Adafruit IO?

I have setup a LoRa device with: QT Py, Seeeduino XIAO Expansion Board, SHT40, Grove - LoRa-E5, and a pair of DS18B20's.
Device Setup
Device Setup
IMG_3704.jpeg (135.79 KiB) Viewed 185 times
It's talking to the The Things Stack Community Edition successfully, and I've set up a Webhooks integration....
Webhooks integration with Adafruit IO
Webhooks integration with Adafruit IO
Screen Shot 2021-08-17 at 1.39.47 PM.png (426.72 KiB) Viewed 185 times
I am able to configure to connect to Adafruit IO and send /raw and /notify (pings)...
Sending pings to Adafruit IO
Sending pings to Adafruit IO
Screen Shot 2021-08-17 at 1.52.29 PM.jpeg (133.87 KiB) Viewed 185 times
(attachment limit reached, to be continued)

User avatar
adafruitguy
 
Posts: 206
Joined: Sat Jun 07, 2014 7:52 am

Re: Trying to integrate with The Things Stack Community Edit

Post by adafruitguy »

On the Adafruit IO Side I have set up a Webhooks receiver....
Adafruit IO Webhooks Receiver
Adafruit IO Webhooks Receiver
Screen Shot 2021-08-17 at 1.15.57 PM.png (334.2 KiB) Viewed 184 times
It is successfully receiving pings and raw data....
Receiving pings and raw data
Receiving pings and raw data
Screen Shot 2021-08-17 at 8.23.01 AM.png (166.11 KiB) Viewed 184 times
But the data is not in the "value" key, so it's treated as a text blob. You can see my data fields in the blob (in green)....
Data not in "value" key....
Data not in "value" key....
Screen Shot 2021-08-17 at 1.14.00 PM.png (920.81 KiB) Viewed 184 times
Any hints would be greatly appreciated!

User avatar
deneaux
 
Posts: 2
Joined: Sun Nov 13, 2016 9:09 am

Re: Trying to integrate with The Things Stack Community Edit

Post by deneaux »

hi,
I have the exact same problem. Even if I have a "value"-field in the json-object, adafruit is still not showing me the value.

This is my payload-formatter on ttn but as I said, it is not working on the adafruit.io side, sadly.

Code: Select all

  function decodeUplink(input) {
  var sensorData = [];
  var floatSize = 4 ;
  var buffer = new ArrayBuffer(input.bytes.length);
  var dataView = new DataView(buffer);
  input.bytes.forEach(function (value, index){
    dataView.setUint8(index,value);
  });
  
  //Convert the bytes back to float values
  sensorData.push(dataView.getFloat32(0, true));
  sensorData.push(dataView.getFloat32(4, true));
  sensorData.push(dataView.getFloat32(8, true));
  
  var data = {
    //bytes: input.bytes,
    
    //adafruit.io
    //value: sensorData[0], <- also not working
    value: { temp:sensorData[0], hum:sensorData[1] },
    
    //thingsspeak
    field1: sensorData[0],
    field2: sensorData[1],
    field3: sensorData[2]
  }
  
  return {
    data: data,
    warnings: [],
    errors: []
  };
}
Hope the will create a webhook template for ttn some day.

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Trying to integrate with The Things Stack Community Edit

Post by brubell »

Do you know if there is a default expected template for TTN payloads? I know TTN (on their side) has a formatter.

I'd like to assist in bridging these platforms.

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: Trying to integrate with The Things Stack Community Edit

Post by jwcooper »

Here is our documentation on how to utilize the webhooks:
https://io.adafruit.com/api/docs/#webhooks

We currently don't offer any post processing of data as it comes in. That means we need it posted as the `value` field or you'll end up getting the json if you append the '/raw' flag. The json is useful if you want to post a lot of data to a single feed, then process it elsewhere. If you want to chart the data in IO or use it with triggers, it's definitely not as useful.

Code: Select all

value: { temp:sensorData[0], hum:sensorData[1] },
That won't work, as it's posting to multiple feeds on a single feeds' webhook. You would need to split that out to multiple webhook endpoints, and something like this:

Code: Select all

{ value: sensorData[0] }
All that being said, we do have ideas in the future that we would like to utilize for post-processing of data, but no timeline for release on that.

User avatar
adafruitguy
 
Posts: 206
Joined: Sat Jun 07, 2014 7:52 am

Re: Trying to integrate with The Things Stack Community Edit

Post by adafruitguy »

I have successfully stitched together a rewrite of the JSON with Node-RED in the middle of my feeds....

The Things Stack Community Edition (mqtt) -> Node-RED -> Adafruit IO (Webhooks)

It's my first time using Node-RED, so it's not pretty. Essentially I have an mqtt feed from The Things Stack to Node-RED where I "Set", "Move", and "Delete" so the JSON looks more inline with what Adafruit IO is expecting, and then feed the output to an Adafruit IO Webhook....
Node-RED Plumbing, Rules, and POST to Adafruit IO Webhook
Node-RED Plumbing, Rules, and POST to Adafruit IO Webhook
NodeRED.png (316.15 KiB) Viewed 146 times
After the re-write rules the JSON looks like this in Node-RED Debug Console...
Rewritten JSON in Node-RED before sending to Adafruit IO
Rewritten JSON in Node-RED before sending to Adafruit IO
Screen Shot 2021-08-19 at 2.22.00 PM.png (80.87 KiB) Viewed 146 times
After that it's fed to Adafruit IO via a Webhook and everything appears happy...
Adafruit IO is happy again
Adafruit IO is happy again
Screen Shot 2021-08-19 at 2.22.47 PM.png (148.25 KiB) Viewed 146 times
Now I need to explore cloud-delivered Node-RED services that don't cost a fortune.

User avatar
adafruitguy
 
Posts: 206
Joined: Sat Jun 07, 2014 7:52 am

Re: Trying to integrate with The Things Stack Community Edit

Post by adafruitguy »

@brubell

The Things Network Community v3 sends along A LOT of data in the Uplink Messages. This includes: device, application, gateway, location, and LoRa performance data.

https://www.thethingsindustries.com/doc ... k-messages

TTN sends the "frame payload" (the bytes as transmitted on TTN) which only becomes useful when user decoded. And, there is a place for user defined (decoded) payload objects under: payload.uplink_message.decoded_payload.

Here are my personally decoded objects defined for my example app...
Here are the specific objects I defined for my app
Here are the specific objects I defined for my app
Screen Shot 2021-08-19 at 3.39.06 PM.png (38.43 KiB) Viewed 139 times
If the Webhooks integration allowed a simple mapping from my chosen names to "value" we'd likely be in business.

For example, if I wanted the Temperature in my Utility Room, I could map: payload.uplink_message.decoded_payload.tempUtilityRm to value to pass that feed. Of course that means a Webhook for each item in my app, but that's how Adafruit IO is already handling feeds today.

User avatar
axelmagnus
 
Posts: 23
Joined: Thu Oct 20, 2016 5:20 pm

Re: Trying to integrate with The Things Stack Community Edit

Post by axelmagnus »

brubell wrote:Do you know if there is a default expected template for TTN payloads? I know TTN (on their side) has a formatter.

I'd like to assist in bridging these platforms.
YES please do! We are many who wants this bridging b/w TTN & AIO.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”