Where to configure the formatter to upload data to Thingspeak

Hi There!
Im setting up my new device (Elsys CO2 thru Dragino LPS8 gw)
My end goal is to get this information on ThingSpeak
I already created a webhook->Thingspeak, and provided the channel ID and Write API KEY
Only thing Im missing (I believe) is creating the payload formatter
I see two possible places for this to be and Im unsire which one should have it:

  1. Applications->App1->Payload Formatters->Uplink->Custom Javascript formatter
  2. Applications->App1->End Devices->Dev1->Payload Formatters

My idea is to assign a var to each field Im reading from the Elsys CO2 monitor, and “return” each of these as a variable to the ThingSpeak fields.

Which place to chose? Or am I misunderstanding the whole thing…?

Thanks!

Also, I wanted to add another question. All samples of formatters I can find for ThingSpeak are in the format of

function Decoder(b, port) {
var var1 = b[0];
var var2 = b[1];

return {
field1: var1,
field2: var2,

}
}

BUT in both places I find formatters in TTN the function starts with
function decodeUplink(input) {…

Why? Are we talking about the same?

Thanks!

This is the application formatter and will be used for any device that does not have it’s own PF.

This would be a PF for the Dev1 device only - no other devices would access it

That is EXACTLY what a payload formatter is for.

That is the v2 format of The Things Stack - it does work but isn’t optimal.

You may benefit from reading the documentation on payload formatters - both in the device & the reference section.

And maybe look on the Elsys site for a PF? And ask Thingspeak about their out of date documentation?

Ok, understood.
So this is what I did.
I firstly selected the “Use Device repository formatters”. This looks like a sample decoder script for the specific device Im using, but not specifically aimed at ThingSpeak
From this file I took the initial variables and all the functions to assemble multibyte data, and then put this specific section at the end

function decodeUplink(input) {

return {
    
	field1:TYPE_CO2,
	field2:TYPE_TEMP,
	field3:TYPE_RH,
	field4:TYPE_LIGHT,
	field5:TYPE_MOTION,
}

}

Anyway I can’t check the forwarding yet as my device is not operational yet but I will be able the test it shortly

Thanks!

Ok I realized that my formatter wouldnt work, I wasn’t understanding what every line would do.
Now it looks like this:

function decodeUplink(input) {
  var data = {}
  var b = input.bytes;
  var temp=(b[0] << 8) | b[1];
  var hum=b[2];
  var luz=(((b[6] << 8) | b[7]) <<8 )|b[8];
  var mov=b[9];
  var co2=(b[10] << 8) | b[11];
  
  
  data.field1 = co2;
  data.field2 = temp;
  data.field3 = hum;
  data.field4 = luz;
  data.field5 = mov;
  
  return {
    data: data
  };
}

When my device is ready I will keep you posted

Along your journey, please be aware that we can only mark homework that is properly formatted - </> is not your friend, it is your gateway to making friends.

Edited, sorry