How to put a fixed value in a payload

Hi,

I have a question as I do not understand payloads as it should be.

For a project (Samen Meten - Dataportaal) I need to sent the latidue and longitude as fixed value in my payload, but I do not a have any idea how to.

I mostly used payloads for de the device repository of TTN of from a vendor, but I am not that good in adding/changing payloads

So if anybody cloud help?

Best
Marc

You can add under the Console->Application->End Devises-> eui-xxxxxxx->Location

There you can set the actual location and it will form part of the JSON.

If that don’t work for the site to pick up the location, can you provide the doc to say how they want it to be provided.

If the location is a fixed value, I would simply not send it in the payload. It’s just a waste of payload size / airtime. If you really do want to send it, I would consider sending it as a separate message and use a different LoRaWAN port value (FPORT) to distinguish it from other measurement data.

You can then also make the position updates and sensor data messages relatively independent of each other. For example you can send it on a different time schedule (say only once per day for position) or with a different encoding.

Why do you want to send it if you can do this in the application, if you send it as a message it takes up air time, you don’t need to as it is fixed.

So ether the device setup, or the next step is to modify the decoder. The device setup is the simplest.

Let’s see what the actual use case is, can you explain @MarcVanBracht ? Is it really fixed, changing occassionally, etc?

Hi Johan, Bertrik,

the sensor is always on the exact samen place. It’s a particulate matter meter.

The project I want to join is from the RIVM, dutch National Institute for Health and Environment

The data will be sent bij MQTT. I set up an MQTT in TTN form the RIVM to they can pull the data (yes, I do not know how MQTT works…)

The ask something like this in the MQTT payload

  • [‘uplink_message’][‘decoded_payload’][‘PM25’]
  • [‘uplink_message’][‘decoded_payload’][‘T’]
  • [‘uplink_message’][‘decoded_payload’][‘RH’]
  • [‘uplink_message’][‘locations’][‘user’][‘latitude’]
  • [‘uplink_message’][‘locations’][‘user’][‘longitude’]
  • [‘end_device_ids’][‘device_id’]

I know what they need and want, but wrting a correct payload…
Maybe you know how I set the L&L as fixed string in my current payload

I will ask them aslo if the know someone that uses MQTT in combination with TTN.

Best
Marc

You just need to add the location as I described above. The format of the JSON will be correct. (Thai is if your decoder is correct for the air quality values)

You need to add the MQTT integration for the Application, give them the User name and API key. They then just need to subscribe.

Hi Johan,

below the payload I use. I really do not know how to get the Longitude and Latitude in there in JSON. Sorry. I put the L&L in the TTN console but do not see the value in the uplink.

Marc

function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.

var measurementTypes = ["Mass Concentration PM1.0", "Mass Concentration PM2.5", "Mass Concentration PM4.0", "Mass Concentration PM10", "Number Concentration PM0.5", "Number Concentration PM1.0", "Number Concentration PM2.5", "Number Concentration PM4.0", "Number Concentration PM10", "Typical Particle Size"];
var decoded = {};

if(port != 223)
{
	decoded.Battery = (bytes[0] & 0x0F)/10 + 2;
	// decoded.Battery = (bytes[0] & 0x0F)/10 + 2 + " V";
}

if (port == 1) {
var pmconfig = bytes[1] << 8 | bytes[2];
var estimatedsize = 3;
var index = 3;
for (var i = 9; i >= 0; i--) {
  bit = pmconfig & (1 << i);
  if(bit){
    decoded[measurementTypes[(9-i)]] = parseFloat(bytes[index] << 24 | bytes[index+1] << 16 | bytes[index+2] << 8 | bytes[index+3]);
    index +=4;
    estimatedsize +=4;
  }
}

if(estimatedsize < bytes.length){
  decoded.temperature = (bytes[bytes.length-4] << 8 | bytes[bytes.length-3]) / 100;
  decoded.humidity = (bytes[bytes.length-2] << 8 | bytes[bytes.length-1]) / 100;
}
}

function parseFloat(bits) {
	var sign = ((bits >>> 31) === 0) ? 1.0 : -1.0;
	var e = ((bits >>> 23) & 0xff);
	var m = (e === 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000;
	var f = sign * m * Math.pow(2, e - 150);

	return f;
}

return decoded;

}

1 Like

It is here you need to enter it.

image
This is from a temperature sensor so the decoded payload is different, but you can see the location properties. It also take a few uplinks before it will appear.

Hi @Johan_Scheepers

The RIVM used the MQTT user info and data is coming into their system.

And YES. the Geo location from the TTN console is in the MQTT feed tehy receive

Many many thanx

Marc

1 Like

Anybody know that can we change or alter the payload transmitted to things network.Like can we add or remove data from payload that reached in server.i need to change te payload in inside the things network interface.is there any way for it?

It all starts with the node as that is the origin point for any data and associated payload - be it single entity data or a concatonation of multiple sensor/data values… how much of that you take into your appliction is down to your own application configuration. You can drop any elements you dont need (more efficient not to sent in the first place as - with in certain limits - this will reduce on air time/improve battery life. Another area where you can ‘tinker’ with values is in the payload decoder. Best practice is take all your payload out of TTN to your own application server/database/presentation system, however, there is scope to run a payload decoder on the TTN servers, the main issues being these are run as a convenience and a nice to have with no gurantees and have no SLA; indeed if your decoder is too complex and runs too long or if the load on the servers generally - from other users as well as your own use case - is too high then the decoder might time out and terminate and so you will get incomplete data. As noted follow best practice.

If you are more specific on what you are using and what you are trying to do there are Forumites and contributors who will be much better placed than I to guide you on how to achieve your aims… details matter :wink: