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?
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.
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
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.
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"}
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…
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.
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.
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.
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?