MQTT Topic TTN

Hi,
I’m trying to import the distance measurement from my LDDS75 ultrasonic sensor into Node-red via MQTT.
It is working but I want to specify which measurements are being imported into Node-red in the first place.
I found a article about this but with ttnV2 and I thought maybe its working with ttnV3
So I tried to change the “Topic”.
The topic which worked was: “v3/DEVid@ttn/devices/+/up/” but with that topic, I have every measurement.
Then I tried “v3/DEVICEid@ttn/devices/+/up/Distance”/ and now I don’t get any data from ttn.
I tried to change it from “distance” to “Distance” because I wasn’t sure which one is meant when they say I need to fill in the measurement name from the Payloaddecoder.

Why is it not working? Is this not working anymore in ttnV3?

Thank you very much in advance

Screenshot (16)

Screenshot (18)

You need to process the json after the MQTT to select the “Distance” value.

What do you want to do with the value? Store in DB, show on chart…?

What do you mean by processing it after the node?
I have a debug node behind the MQTT node and I don’t get any data from MQTT after changing the topic.

I want to store it in a DB but I’m struggling with filtering the payload.
So I thought I could just import the one measurement I want to store in the DB.

The old V2 method where you could subscribe on a single value of an uplink did not scale and is not available in V3.

1 Like

First make you topic “v3/+/devices/+/up”, this will catch all your LDDS75 data that is configured in your application for your LLDS75, yes you can have multiple device connected to one application in TTN.

Post your json you receive from TTN - MQTT node to Debug node

image

You will need to extract the device ID - time stamp - measurement out of the json (I have at lease minimum of these 3 fields in my DB).

Then you will need to prepare the query to for the DB to wright to data to the DB.

image

What DB are you using?

Thank you. That’s unfortunate

You can do it with a function or change node.

Post the json the I can assist, all the other values in your first post looks to me like int and floats.

Copy and post between 3 ` (back ticks)
image

copy payload

Yes, I got it to work after my comment. now I have a string with the distance “521 mm” and now I want to write this into the DB.
But that’s something I cant get to work either…
As I said I have a String(6) with “521 mm” and I have an “influxdb out” Node.
The node is configured with my Influx dB Server “localhost:8086” with the database “fuellstandquelle” which I created before.
As the “Measurement” I configured “distance”.
So far so good but I’m getting an error:

Error: A 400 Bad Request error occurred: {"error":"unable to parse 'distanz correlation_ids=!(I deleted some things because i dont know if they are confidential)! are ,end_device_ids=[object Object],received_at=\"2021-12-07T16:28:59.976920433Z\",uplink_message=[object Object]': invalid boolean"}

Screenshot (20)

Please do not delete posts under those circumstances - document the fix if you can, but don’t leave the topic hanging.

Ah yes you are right…

Oh, I’m just realising that the problem could be that I’m saving the distance to “msg.Distanz” but I’m sending the whole string to the “influxdb out” Node…
But I’m not sure how to resolve this problem…

First change the MQTT node - Output needs to be “a prased JSON object”

image

Delete the “edit jsone node”

Change you “debug node” to

image

Now look at the json object.

Yes, i did that. Okay kind of i did it with a “json” Node

Least amount of steps or process, I am lazy, so less is better.

Ok, so what is the json now? (straight form the output of the 'mqtt node")

Yes, I agree with you. But it’s actually not working by changing the output from the MQTT Node to “Json object”. if I’m doing this I’m getting a String. So I need to do it with the “Json” Node to get it to work.

But now to your question:
I now have my flow built like that. so you can see every node and what it is doing.
Screenshot (21)
Screenshot (23)

And as I said after the “change” Node I have a String(6) with “521 mm” and I want to save that String to de database. But I’m getting this error I mentioned before and I dong know how I can fix that.

Thank you very much in advance!

What decoder are you using? Because that is probably where the space and “mm” gets added. Because of that the value is a string which makes your life a bit more difficult later on.

Is from your decoder.

So change your decoder.

Break it up on small steps then you can find the fault.

Or you can split the string at " " and parseFloat()

the decoder from Dragino.

function Decoder(bytes, port) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.
  var value=(bytes[0]<<8 | bytes[1]) & 0x3FFF;
  var batV=value/1000;//Battery,units:V
   
  value=bytes[2]<<8 | bytes[3];
  var distance=(value);//distance,units:mm

  var i_flag = bytes[4]; 
  
  value=bytes[5]<<8 | bytes[6];
  if(bytes[5] & 0x80)
  {value |= 0xFFFF0000;}
  var temp_DS18B20=(value/10).toFixed(2);//DS18B20,temperature  
  
  var s_flag = bytes[7];	
  return {
       Bat:batV +" V",
       Distance:distance,
	   Interrupt_flag:i_flag,
	   TempC_DS18B20:temp_DS18B20+" °C",
	   Sensor_flag:s_flag,
  };
}

well I actually thing I don’t know in what format I need my data to store it in a database…
I thought a string as I get after my Node-red nodes would work…
in what format do I need the distance? is the “mm” a problem?