MQTT Topic TTN

Did you use the “Copy Path” button in node-red?

Yes, I did and it copied the path I posted before.
I will try to copy the application_id for identification. there’s only one Node in this application and there will be no other Node.
That should be okay to identify the device.

Are there a value in the “dev_eui”? As TTN always forwards this…

What happens if you decide you need a second device?

Screenshot (39)
Yes there is a value in the “dev_eui” row.

Then everything would be broken…
You are right… in two years or so I probably don’t know this anymore and would add another device…

But im not sure why this is happening… I meant there is a dev_eui so why is it saying its undefined?

What bugs me is that you getting two separate JSON, one for the “Distance” and “dev_eui” out of the change node, that all should be in the same JSON.

Well, I’m getting them in two because we are making two or am I wrong?
msg.payload and msg.dev_eui.

Copy and past your flow from node-red, then I can look.

Don’t worry Node-red leaves all the keys and passwords out.

[
    {
        "id": "153ff67d1f2c61b8",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8e52c3ed8907ee0c",
        "type": "mqtt in",
        "z": "153ff67d1f2c61b8",
        "name": "Füllstand Quelle",
        "topic": "v3/DEVICEID@ttn/devices/+/up",
        "qos": "2",
        "datatype": "json",
        "broker": "0a4f4fef6fee57c6",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 260,
        "y": 260,
        "wires": [
            [
                "059296a9a604036f",
                "1ae3c6d92610a908"
            ]
        ]
    },
    {
        "id": "059296a9a604036f",
        "type": "change",
        "z": "153ff67d1f2c61b8",
        "name": "change node",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.uplink_message.decoded_payload.Distance",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "dev_eui",
                "pt": "msg",
                "to": "payload.end_device_ids.dev_eui",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 470,
        "y": 260,
        "wires": [
            [
                "08529e03113c98e2",
                "c4aa3711222d1081"
            ]
        ]
    },
    {
        "id": "08529e03113c98e2",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 990,
        "y": 280,
        "wires": []
    },
    {
        "id": "1ae3c6d92610a908",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 430,
        "y": 180,
        "wires": []
    },
    {
        "id": "c4aa3711222d1081",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "dev_eui",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 990,
        "y": 240,
        "wires": []
    },
    {
        "id": "0a4f4fef6fee57c6",
        "type": "mqtt-broker",
        "name": "Füllstand Quelle",
        "broker": "eu1.cloud.thethings.network",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

Thats the flow

You have added a few thing that aided in the confusion.

You should rather keep your debug node set to as below.

image

This way you only get part of the JSON

image

I have corrected your flow, you will see there is a “Test Json”, if I hade you JSON I could have solved the problem faster.

You should be good now to inject the JSON into the Influx DB node and have the correct data in the DB.

[
    {
        "id": "153ff67d1f2c61b8",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8e52c3ed8907ee0c",
        "type": "mqtt in",
        "z": "153ff67d1f2c61b8",
        "name": "Füllstand Quelle",
        "topic": "v3/DEVICEID@ttn/devices/+/up",
        "qos": "2",
        "datatype": "json",
        "broker": "0a4f4fef6fee57c6",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 220,
        "y": 260,
        "wires": [
            [
                "059296a9a604036f"
            ]
        ]
    },
    {
        "id": "059296a9a604036f",
        "type": "change",
        "z": "153ff67d1f2c61b8",
        "name": "change node",
        "rules": [
            {
                "t": "set",
                "p": "Distance",
                "pt": "msg",
                "to": "payload.uplink_message.decoded_payload.Distance",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "dev_eui",
                "pt": "msg",
                "to": "payload.end_device_ids.device_id",
                "tot": "msg"
            },
            {
                "t": "delete",
                "p": "payload.uplink_message",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.correlation_ids",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "topic",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 510,
        "y": 260,
        "wires": [
            [
                "c4aa3711222d1081"
            ]
        ]
    },
    {
        "id": "1ae3c6d92610a908",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 360,
        "wires": []
    },
    {
        "id": "c4aa3711222d1081",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "dev_eui",
        "statusType": "auto",
        "x": 670,
        "y": 260,
        "wires": []
    },
    {
        "id": "60f39d916a35dd8b",
        "type": "inject",
        "z": "153ff67d1f2c61b8",
        "name": "Test Json",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"topic\":\"v3/compact-tracker-abeeway@ttn/devices/eui-20635f0161000093/up\",\"payload\":{\"end_device_ids\":{\"device_id\":\"eui-dhdfth\",\"application_ids\":{\"application_id\":\"fjdjdy\"},\"dev_eui\":\"hth3\",\"join_eui\":\"hrhxf\",\"dev_addr\":\"hhF\"},\"correlation_ids\":[\"as:up:01FPZ2ZC6PJQE0XQ68ECN239B7\",\"gs:conn:01FNXTS68EYM139F0J53QR5ZK0\",\"gs:up:host:01FNXTS699E4A2H7VSP45SZG62\",\"gs:uplink:01FPZ2ZC04E8WTWP10DHJX97S6\",\"ns:uplink:01FPZ2ZC0568ACBK2MBZQK4148\",\"rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FPZ2ZC052XX7N17EDTRCYW6D\",\"rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01FPZ2ZC6MRZ4WAM86KEJC7J6B\"],\"received_at\":\"2021-12-15T13:02:16.279389076Z\",\"uplink_message\":{\"session_key_id\":\"AX23nQJEOCVpz1fId9ugRw==\",\"f_port\":18,\"f_cnt\":182,\"frm_payload\":\"BSBhigAQAgAAAwIA\",\"decoded_payload\":{\"ack\":0,\"batteryPersentage\":97,\"bleFirmware\":\"bleFwVersion3.2.0\",\"data\":0,\"Distance\":512,\"debug\":{\"length\":12,\"payload\":\"0520618a0010gfhfg030200\",\"port\":18,\"server_time\":\"2021-12-15T13:02:16.283Z\"},\"lastResetCause\":\"lastResetCause: 16\",\"mcuFirmware\":\"fwVersion: 2.0.0\",\"status\":{\"mode\":{\"code\":1,\"description\":\"Motion tracking\"},\"moving\":false,\"on_demand\":false,\"periodic\":false,\"sos\":false,\"tracking\":false},\"temperature\":25.81,\"type\":\"HEARTBEAT\"},\"rx_metadata\":[{\"gateway_ids\":{\"gateway_id\":\"dhdth-mdhdfhfn-01-dbn\",\"eui\":\"3dhdfhdfgh0\"},\"time\":\"2021-12-15T13:02:15.958012Z\",\"timestamp\":534735231,\"rssi\":-109,\"channel_rssi\":-109,\"snr\":1.75,\"location\":{\"latitude\":-505059.885050571,\"longitude\":5050.905081617,\"altitude\":225,\"source\":\"SOURCE_REGISTRY\"},\"uplink_token\":\"CiIKIAoUdGVjaDUtbWFsdmVybi0wMS1kYm4SCDQ2MjgkAFAAEP/S/f4BGgsI2M7njQYQ1+/aICCYsNCFyP3/ASoMCNfO540GEOC06MgD\",\"channel_index\":4}],\"settings\":{\"data_rate\":{\"lora\":{\"bandwidth\":125000,\"spreading_factor\":7}},\"coding_rate\":\"4/5\",\"frequency\":\"867300000\",\"timestamp\":534735231,\"time\":\"2021-12-15T13:02:15.958012Z\"},\"received_at\":\"2021-12-15T13:02:16.069864716Z\",\"consumed_airtime\":\"0.061696s\",\"locations\":{\"frm-payload\":{\"latitude\":-29.8889728,\"longitude\":30.916608,\"source\":\"SOURCE_GPS\"}},\"network_ids\":{\"net_id\":\"000013\",\"tenant_id\":\"ttn\",\"cluster_id\":\"ttn-eu1\"}}},\"qos\":0,\"retain\":false,\"_msgid\":\"d38de075552048d0\"}",
        "payloadType": "json",
        "x": 230,
        "y": 360,
        "wires": [
            [
                "99997bbb40d80fb0"
            ]
        ]
    },
    {
        "id": "99997bbb40d80fb0",
        "type": "change",
        "z": "153ff67d1f2c61b8",
        "name": "Test Json",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 360,
        "y": 360,
        "wires": [
            [
                "059296a9a604036f",
                "1ae3c6d92610a908"
            ]
        ]
    },
    {
        "id": "3f4efbddb8220f44",
        "type": "comment",
        "z": "153ff67d1f2c61b8",
        "name": "For Testing",
        "info": "",
        "x": 210,
        "y": 320,
        "wires": []
    },
    {
        "id": "0a4f4fef6fee57c6",
        "type": "mqtt-broker",
        "name": "Füllstand Quelle",
        "broker": "eu1.cloud.thethings.network",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

image

Thank you very much!
I like the solution and I’m very thankful for your very useful tips!
I also like the testing via the inject node. I did not know this trick… I just waited for the next payload from the LoraNode.

Okay first of all you are writing the distance and the deveui into msg.Distance and msg.deveui and then you are deleting everything from the stream we don’t want to save into the DB. Do I understand that correctly?

!The question is obsolete! I’ve found a solution!

Now I have an additional question. Now the “Distance” stands for the distance between an ultrasonic sensor and a water level.
Now I want to have the height of the water. The mathematical solution for this is to subtract"2300" from the measurement and multiply it by “-1”.
I’m pretty sure you would do this with a function node but I’m having trouble taking the msg.Distance and calculate with the number.

There is a “Copy Value” Button.

dwJ9uLCIM0

and past in inject node, press the … and delete what ever is in the window and past your JSON, hit “Done”, Done" and “Deploy”

Now you can inject your JSON into the flow.

image

Some math in the function node, or you can save DB space and do it when you display the data, if you use Grafana or the likes easy to do there.

I don’t like extra long JSON, only the necessities.

Save the electrons from flowing :smiling_imp:

[
    {
        "id": "153ff67d1f2c61b8",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8e52c3ed8907ee0c",
        "type": "mqtt in",
        "z": "153ff67d1f2c61b8",
        "name": "Füllstand Quelle",
        "topic": "v3/DEVICEID@ttn/devices/+/up",
        "qos": "2",
        "datatype": "json",
        "broker": "0a4f4fef6fee57c6",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 220,
        "y": 260,
        "wires": [
            [
                "059296a9a604036f"
            ]
        ]
    },
    {
        "id": "059296a9a604036f",
        "type": "change",
        "z": "153ff67d1f2c61b8",
        "name": "change node",
        "rules": [
            {
                "t": "set",
                "p": "Distance",
                "pt": "msg",
                "to": "payload.uplink_message.decoded_payload.Distance",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "dev_eui",
                "pt": "msg",
                "to": "payload.end_device_ids.device_id",
                "tot": "msg"
            },
            {
                "t": "delete",
                "p": "payload.uplink_message",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.correlation_ids",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "topic",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 510,
        "y": 260,
        "wires": [
            [
                "a99ae555ccc4abb5"
            ]
        ]
    },
    {
        "id": "1ae3c6d92610a908",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 360,
        "wires": []
    },
    {
        "id": "c4aa3711222d1081",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "dev_eui",
        "statusType": "auto",
        "x": 870,
        "y": 260,
        "wires": []
    },
    {
        "id": "60f39d916a35dd8b",
        "type": "inject",
        "z": "153ff67d1f2c61b8",
        "name": "Test Json",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"topic\":\"v3/compact-tracker-abeeway@ttn/devices/eui-20635f0161000093/up\",\"payload\":{\"end_device_ids\":{\"device_id\":\"eui-dhdfth\",\"application_ids\":{\"application_id\":\"fjdjdy\"},\"dev_eui\":\"hth3\",\"join_eui\":\"hrhxf\",\"dev_addr\":\"hhF\"},\"correlation_ids\":[\"as:up:01FPZ2ZC6PJQE0XQ68ECN239B7\",\"gs:conn:01FNXTS68EYM139F0J53QR5ZK0\",\"gs:up:host:01FNXTS699E4A2H7VSP45SZG62\",\"gs:uplink:01FPZ2ZC04E8WTWP10DHJX97S6\",\"ns:uplink:01FPZ2ZC0568ACBK2MBZQK4148\",\"rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FPZ2ZC052XX7N17EDTRCYW6D\",\"rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01FPZ2ZC6MRZ4WAM86KEJC7J6B\"],\"received_at\":\"2021-12-15T13:02:16.279389076Z\",\"uplink_message\":{\"session_key_id\":\"AX23nQJEOCVpz1fId9ugRw==\",\"f_port\":18,\"f_cnt\":182,\"frm_payload\":\"BSBhigAQAgAAAwIA\",\"decoded_payload\":{\"ack\":0,\"batteryPersentage\":97,\"bleFirmware\":\"bleFwVersion3.2.0\",\"data\":0,\"Distance\":512,\"debug\":{\"length\":12,\"payload\":\"0520618a0010gfhfg030200\",\"port\":18,\"server_time\":\"2021-12-15T13:02:16.283Z\"},\"lastResetCause\":\"lastResetCause: 16\",\"mcuFirmware\":\"fwVersion: 2.0.0\",\"status\":{\"mode\":{\"code\":1,\"description\":\"Motion tracking\"},\"moving\":false,\"on_demand\":false,\"periodic\":false,\"sos\":false,\"tracking\":false},\"temperature\":25.81,\"type\":\"HEARTBEAT\"},\"rx_metadata\":[{\"gateway_ids\":{\"gateway_id\":\"dhdth-mdhdfhfn-01-dbn\",\"eui\":\"3dhdfhdfgh0\"},\"time\":\"2021-12-15T13:02:15.958012Z\",\"timestamp\":534735231,\"rssi\":-109,\"channel_rssi\":-109,\"snr\":1.75,\"location\":{\"latitude\":-505059.885050571,\"longitude\":5050.905081617,\"altitude\":225,\"source\":\"SOURCE_REGISTRY\"},\"uplink_token\":\"CiIKIAoUdGVjaDUtbWFsdmVybi0wMS1kYm4SCDQ2MjgkAFAAEP/S/f4BGgsI2M7njQYQ1+/aICCYsNCFyP3/ASoMCNfO540GEOC06MgD\",\"channel_index\":4}],\"settings\":{\"data_rate\":{\"lora\":{\"bandwidth\":125000,\"spreading_factor\":7}},\"coding_rate\":\"4/5\",\"frequency\":\"867300000\",\"timestamp\":534735231,\"time\":\"2021-12-15T13:02:15.958012Z\"},\"received_at\":\"2021-12-15T13:02:16.069864716Z\",\"consumed_airtime\":\"0.061696s\",\"locations\":{\"frm-payload\":{\"latitude\":-29.8889728,\"longitude\":30.916608,\"source\":\"SOURCE_GPS\"}},\"network_ids\":{\"net_id\":\"000013\",\"tenant_id\":\"ttn\",\"cluster_id\":\"ttn-eu1\"}}},\"qos\":0,\"retain\":false,\"_msgid\":\"d38de075552048d0\"}",
        "payloadType": "json",
        "x": 230,
        "y": 360,
        "wires": [
            [
                "99997bbb40d80fb0"
            ]
        ]
    },
    {
        "id": "99997bbb40d80fb0",
        "type": "change",
        "z": "153ff67d1f2c61b8",
        "name": "Test Json",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 360,
        "y": 360,
        "wires": [
            [
                "059296a9a604036f",
                "1ae3c6d92610a908"
            ]
        ]
    },
    {
        "id": "3f4efbddb8220f44",
        "type": "comment",
        "z": "153ff67d1f2c61b8",
        "name": "For Testing",
        "info": "",
        "x": 210,
        "y": 320,
        "wires": []
    },
    {
        "id": "a99ae555ccc4abb5",
        "type": "function",
        "z": "153ff67d1f2c61b8",
        "name": "level",
        "func": "msg.level =  msg.Distance - 2300\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 700,
        "y": 260,
        "wires": [
            [
                "c4aa3711222d1081"
            ]
        ]
    },
    {
        "id": "0a4f4fef6fee57c6",
        "type": "mqtt-broker",
        "name": "Füllstand Quelle",
        "broker": "eu1.cloud.thethings.network",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

Very cool!

Okay that’s as i expected another approach to this “problem”.
I installed a calculator Plugin and did it with this.

[
    {
        "id": "dec69ff8f39faf70",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "9c6d69e06c2386f7",
        "type": "change",
        "z": "dec69ff8f39faf70",
        "name": "change node",
        "rules": [
            {
                "t": "set",
                "p": "Distance",
                "pt": "msg",
                "to": "payload.uplink_message.decoded_payload.Distance",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "dev_eui",
                "pt": "msg",
                "to": "payload.end_device_ids.device_id",
                "tot": "msg"
            },
            {
                "t": "delete",
                "p": "payload.uplink_message",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.correlation_ids",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "topic",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 430,
        "y": 240,
        "wires": [
            [
                "c7fe070daa6649a2"
            ]
        ]
    },
    {
        "id": "9a2ef07e29a54a89",
        "type": "debug",
        "z": "dec69ff8f39faf70",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "dev_eui",
        "statusType": "auto",
        "x": 950,
        "y": 60,
        "wires": []
    },
    {
        "id": "c7fe070daa6649a2",
        "type": "calculator",
        "z": "dec69ff8f39faf70",
        "name": "-2300",
        "inputMsgField": "Distance",
        "outputMsgField": "Distance",
        "operation": "sub",
        "constant": "2300",
        "round": true,
        "decimals": "2",
        "x": 550,
        "y": 180,
        "wires": [
            [
                "dc8fb232d449aaa2"
            ]
        ]
    },
    {
        "id": "dc8fb232d449aaa2",
        "type": "calculator",
        "z": "dec69ff8f39faf70",
        "name": "x-1",
        "inputMsgField": "Distance",
        "outputMsgField": "Distance",
        "operation": "mult",
        "constant": "-1",
        "round": true,
        "decimals": "2",
        "x": 670,
        "y": 140,
        "wires": [
            [
                "11f0bf4bb0abba44"
            ]
        ]
    },
    {
        "id": "11f0bf4bb0abba44",
        "type": "calculator",
        "z": "dec69ff8f39faf70",
        "name": "x1,64x1,417",
        "inputMsgField": "Distance",
        "outputMsgField": "Füllmenge",
        "operation": "mult",
        "constant": "2.32388",
        "round": true,
        "decimals": "0",
        "x": 810,
        "y": 100,
        "wires": [
            [
                "9a2ef07e29a54a89",
                "ba2599eea969d74a"
            ]
        ]
    },
    {
        "id": "ba2599eea969d74a",
        "type": "influxdb out",
        "z": "dec69ff8f39faf70",
        "influxdb": "9f2a7e530ba069af",
        "name": "Influxdb fuellstandquelle",
        "measurement": "distanz",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 1010,
        "y": 140,
        "wires": []
    },
    {
        "id": "06f471c9d70fc21f",
        "type": "mqtt in",
        "z": "dec69ff8f39faf70",
        "name": "Füllstand Quelle",
        "topic": "v3/fuellstandquelle@ttn/devices/+/up",
        "qos": "2",
        "datatype": "json",
        "broker": "0a4f4fef6fee57c6",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 240,
        "wires": [
            [
                "9c6d69e06c2386f7",
                "4962ee966ff9499e"
            ]
        ]
    },
    {
        "id": "4962ee966ff9499e",
        "type": "debug",
        "z": "dec69ff8f39faf70",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 310,
        "y": 160,
        "wires": []
    },
    {
        "id": "9f2a7e530ba069af",
        "type": "influxdb",
        "hostname": "localhost",
        "port": "8086",
        "protocol": "http",
        "database": "fuellstandquelle",
        "name": "Influx DB fuellstandquelle",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://localhost:8086",
        "rejectUnauthorized": true
    },
    {
        "id": "0a4f4fef6fee57c6",
        "type": "mqtt-broker",
        "name": "Füllstand Quelle",
        "broker": "eu1.cloud.thethings.network",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

That is my approach and it’s working and I’m fine with that…
Thats the calculator if you need it.

But I can’t save the result into my db.

Screenshot (42)
Screenshot (44)
Screenshot (43)

I have another question.
Is there a reason you are not deleting the “_msgid”?

The “_msgid” does not matter, used in node-red to ID the JSON packet.

This is a setting in your Influx DB, read there documentation on retention policies.
image

Far to many nodes needed.

Look at this flow.

[
    {
        "id": "153ff67d1f2c61b8",
        "type": "tab",
        "label": "Flow 2sddsdvv",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8e52c3ed8907ee0c",
        "type": "mqtt in",
        "z": "153ff67d1f2c61b8",
        "name": "Füllstand Quelle",
        "topic": "v3/DEVICEID@ttn/devices/+/up",
        "qos": "2",
        "datatype": "json",
        "broker": "0a4f4fef6fee57c6",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 220,
        "y": 260,
        "wires": [
            [
                "059296a9a604036f"
            ]
        ]
    },
    {
        "id": "059296a9a604036f",
        "type": "change",
        "z": "153ff67d1f2c61b8",
        "name": "change node",
        "rules": [
            {
                "t": "set",
                "p": "payload.Distance",
                "pt": "msg",
                "to": "payload.uplink_message.decoded_payload.Distance",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload.dev_eui",
                "pt": "msg",
                "to": "payload.end_device_ids.dev_eui",
                "tot": "msg"
            },
            {
                "t": "delete",
                "p": "payload.uplink_message",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.correlation_ids",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "topic",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 510,
        "y": 260,
        "wires": [
            [
                "a99ae555ccc4abb5",
                "c4aa3711222d1081"
            ]
        ]
    },
    {
        "id": "1ae3c6d92610a908",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 360,
        "wires": []
    },
    {
        "id": "c4aa3711222d1081",
        "type": "debug",
        "z": "153ff67d1f2c61b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "dev_eui",
        "statusType": "auto",
        "x": 850,
        "y": 360,
        "wires": []
    },
    {
        "id": "60f39d916a35dd8b",
        "type": "inject",
        "z": "153ff67d1f2c61b8",
        "name": "Test Json",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"topic\":\"v3/compact-tracker-abeeway@ttn/devices/eui-20635f0161000093/up\",\"payload\":{\"end_device_ids\":{\"device_id\":\"eui-dhdfth\",\"application_ids\":{\"application_id\":\"fjdjdy\"},\"dev_eui\":\"hth3\",\"join_eui\":\"hrhxf\",\"dev_addr\":\"hhF\"},\"correlation_ids\":[\"as:up:01FPZ2ZC6PJQE0XQ68ECN239B7\",\"gs:conn:01FNXTS68EYM139F0J53QR5ZK0\",\"gs:up:host:01FNXTS699E4A2H7VSP45SZG62\",\"gs:uplink:01FPZ2ZC04E8WTWP10DHJX97S6\",\"ns:uplink:01FPZ2ZC0568ACBK2MBZQK4148\",\"rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FPZ2ZC052XX7N17EDTRCYW6D\",\"rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01FPZ2ZC6MRZ4WAM86KEJC7J6B\"],\"received_at\":\"2021-12-15T13:02:16.279389076Z\",\"uplink_message\":{\"session_key_id\":\"AX23nQJEOCVpz1fId9ugRw==\",\"f_port\":18,\"f_cnt\":182,\"frm_payload\":\"BSBhigAQAgAAAwIA\",\"decoded_payload\":{\"ack\":0,\"batteryPersentage\":97,\"bleFirmware\":\"bleFwVersion3.2.0\",\"data\":0,\"Distance\":512,\"debug\":{\"length\":12,\"payload\":\"0520618a0010gfhfg030200\",\"port\":18,\"server_time\":\"2021-12-15T13:02:16.283Z\"},\"lastResetCause\":\"lastResetCause: 16\",\"mcuFirmware\":\"fwVersion: 2.0.0\",\"status\":{\"mode\":{\"code\":1,\"description\":\"Motion tracking\"},\"moving\":false,\"on_demand\":false,\"periodic\":false,\"sos\":false,\"tracking\":false},\"temperature\":25.81,\"type\":\"HEARTBEAT\"},\"rx_metadata\":[{\"gateway_ids\":{\"gateway_id\":\"dhdth-mdhdfhfn-01-dbn\",\"eui\":\"3dhdfhdfgh0\"},\"time\":\"2021-12-15T13:02:15.958012Z\",\"timestamp\":534735231,\"rssi\":-109,\"channel_rssi\":-109,\"snr\":1.75,\"location\":{\"latitude\":-505059.885050571,\"longitude\":5050.905081617,\"altitude\":225,\"source\":\"SOURCE_REGISTRY\"},\"uplink_token\":\"CiIKIAoUdGVjaDUtbWFsdmVybi0wMS1kYm4SCDQ2MjgkAFAAEP/S/f4BGgsI2M7njQYQ1+/aICCYsNCFyP3/ASoMCNfO540GEOC06MgD\",\"channel_index\":4}],\"settings\":{\"data_rate\":{\"lora\":{\"bandwidth\":125000,\"spreading_factor\":7}},\"coding_rate\":\"4/5\",\"frequency\":\"867300000\",\"timestamp\":534735231,\"time\":\"2021-12-15T13:02:15.958012Z\"},\"received_at\":\"2021-12-15T13:02:16.069864716Z\",\"consumed_airtime\":\"0.061696s\",\"locations\":{\"frm-payload\":{\"latitude\":-29.8889728,\"longitude\":30.916608,\"source\":\"SOURCE_GPS\"}},\"network_ids\":{\"net_id\":\"000013\",\"tenant_id\":\"ttn\",\"cluster_id\":\"ttn-eu1\"}}},\"qos\":0,\"retain\":false,\"_msgid\":\"d38de075552048d0\"}",
        "payloadType": "json",
        "x": 230,
        "y": 360,
        "wires": [
            [
                "99997bbb40d80fb0"
            ]
        ]
    },
    {
        "id": "99997bbb40d80fb0",
        "type": "change",
        "z": "153ff67d1f2c61b8",
        "name": "Test Json",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 360,
        "y": 360,
        "wires": [
            [
                "059296a9a604036f",
                "1ae3c6d92610a908"
            ]
        ]
    },
    {
        "id": "3f4efbddb8220f44",
        "type": "comment",
        "z": "153ff67d1f2c61b8",
        "name": "For Testing",
        "info": "",
        "x": 210,
        "y": 320,
        "wires": []
    },
    {
        "id": "a99ae555ccc4abb5",
        "type": "function",
        "z": "153ff67d1f2c61b8",
        "name": "level",
        "func": "msg.payload.Füllmenge =  (2300 - msg.payload.Distance)*2.32388\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 700,
        "y": 260,
        "wires": [
            [
                "c4aa3711222d1081"
            ]
        ]
    },
    {
        "id": "0a4f4fef6fee57c6",
        "type": "mqtt-broker",
        "name": "Füllstand Quelle",
        "broker": "eu1.cloud.thethings.network",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

Well, when I’m looking at the two rows of code I’m feeling stupid… :smiley:
Thank you for showing me this solution.

Then there is only the problem with the DB left…
I’m very confused about the error.

I don’t mean the problem with the retention of the data…

I am here to learn, there are no stupid questions.

Try that flow, I had to brush up on Influxdb, not my 1st choice for a DB.

Yes, that’s true but sometimes I’m feeling stupid. even if I’m learning a lot of things by trying things iv never done before…

Error: A 400 Bad Request error occurred: {"error":"unable to parse 'distanz Distance=510,Füllmenge=4159.7452,dev_eui=\"\",end_device_ids=[object Object],received_at=\"2021-12-15T20:10:26.405479754Z\"': invalid boolean"}

There’s still the same error with the DB…
I would say that’s a problem with the “Measurement” in the DB Node

Because we did not delete ‘msg.payload.end_device_ids’ from the JSON

[
    {
        "id": "059296a9a604036f",
        "type": "change",
        "z": "454b7c0d2cc14647",
        "name": "change node",
        "rules": [
            {
                "t": "set",
                "p": "payload.Distance",
                "pt": "msg",
                "to": "payload.uplink_message.decoded_payload.Distance",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload.dev_eui",
                "pt": "msg",
                "to": "payload.end_device_ids.dev_eui",
                "tot": "msg"
            },
            {
                "t": "delete",
                "p": "payload.uplink_message",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.correlation_ids",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "topic",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.end_device_ids",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 450,
        "y": 1020,
        "wires": [
            [
                "a99ae555ccc4abb5",
                "c4aa3711222d1081"
            ]
        ]
    },
    {
        "id": "1ae3c6d92610a908",
        "type": "debug",
        "z": "454b7c0d2cc14647",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 470,
        "y": 1120,
        "wires": []
    },
    {
        "id": "c4aa3711222d1081",
        "type": "debug",
        "z": "454b7c0d2cc14647",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "dev_eui",
        "statusType": "auto",
        "x": 790,
        "y": 1120,
        "wires": []
    },
    {
        "id": "60f39d916a35dd8b",
        "type": "inject",
        "z": "454b7c0d2cc14647",
        "name": "Test Json",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"topic\":\"v3/compact-tracker-abeeway@ttn/devices/eui-20635f0161000093/up\",\"payload\":{\"end_device_ids\":{\"device_id\":\"eui-dhdfth\",\"application_ids\":{\"application_id\":\"fjdjdy\"},\"dev_eui\":\"hth3\",\"join_eui\":\"hrhxf\",\"dev_addr\":\"hhF\"},\"correlation_ids\":[\"as:up:01FPZ2ZC6PJQE0XQ68ECN239B7\",\"gs:conn:01FNXTS68EYM139F0J53QR5ZK0\",\"gs:up:host:01FNXTS699E4A2H7VSP45SZG62\",\"gs:uplink:01FPZ2ZC04E8WTWP10DHJX97S6\",\"ns:uplink:01FPZ2ZC0568ACBK2MBZQK4148\",\"rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FPZ2ZC052XX7N17EDTRCYW6D\",\"rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01FPZ2ZC6MRZ4WAM86KEJC7J6B\"],\"received_at\":\"2021-12-15T13:02:16.279389076Z\",\"uplink_message\":{\"session_key_id\":\"AX23nQJEOCVpz1fId9ugRw==\",\"f_port\":18,\"f_cnt\":182,\"frm_payload\":\"BSBhigAQAgAAAwIA\",\"decoded_payload\":{\"ack\":0,\"batteryPersentage\":97,\"bleFirmware\":\"bleFwVersion3.2.0\",\"data\":0,\"Distance\":512,\"debug\":{\"length\":12,\"payload\":\"0520618a0010gfhfg030200\",\"port\":18,\"server_time\":\"2021-12-15T13:02:16.283Z\"},\"lastResetCause\":\"lastResetCause: 16\",\"mcuFirmware\":\"fwVersion: 2.0.0\",\"status\":{\"mode\":{\"code\":1,\"description\":\"Motion tracking\"},\"moving\":false,\"on_demand\":false,\"periodic\":false,\"sos\":false,\"tracking\":false},\"temperature\":25.81,\"type\":\"HEARTBEAT\"},\"rx_metadata\":[{\"gateway_ids\":{\"gateway_id\":\"dhdth-mdhdfhfn-01-dbn\",\"eui\":\"3dhdfhdfgh0\"},\"time\":\"2021-12-15T13:02:15.958012Z\",\"timestamp\":534735231,\"rssi\":-109,\"channel_rssi\":-109,\"snr\":1.75,\"location\":{\"latitude\":-505059.885050571,\"longitude\":5050.905081617,\"altitude\":225,\"source\":\"SOURCE_REGISTRY\"},\"uplink_token\":\"CiIKIAoUdGVjaDUtbWFsdmVybi0wMS1kYm4SCDQ2MjgkAFAAEP/S/f4BGgsI2M7njQYQ1+/aICCYsNCFyP3/ASoMCNfO540GEOC06MgD\",\"channel_index\":4}],\"settings\":{\"data_rate\":{\"lora\":{\"bandwidth\":125000,\"spreading_factor\":7}},\"coding_rate\":\"4/5\",\"frequency\":\"867300000\",\"timestamp\":534735231,\"time\":\"2021-12-15T13:02:15.958012Z\"},\"received_at\":\"2021-12-15T13:02:16.069864716Z\",\"consumed_airtime\":\"0.061696s\",\"locations\":{\"frm-payload\":{\"latitude\":-29.8889728,\"longitude\":30.916608,\"source\":\"SOURCE_GPS\"}},\"network_ids\":{\"net_id\":\"000013\",\"tenant_id\":\"ttn\",\"cluster_id\":\"ttn-eu1\"}}},\"qos\":0,\"retain\":false,\"_msgid\":\"d38de075552048d0\"}",
        "payloadType": "json",
        "x": 170,
        "y": 1120,
        "wires": [
            [
                "99997bbb40d80fb0"
            ]
        ]
    },
    {
        "id": "99997bbb40d80fb0",
        "type": "change",
        "z": "454b7c0d2cc14647",
        "name": "Test Json",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 300,
        "y": 1120,
        "wires": [
            [
                "059296a9a604036f",
                "1ae3c6d92610a908"
            ]
        ]
    },
    {
        "id": "3f4efbddb8220f44",
        "type": "comment",
        "z": "454b7c0d2cc14647",
        "name": "For Testing",
        "info": "",
        "x": 150,
        "y": 1080,
        "wires": []
    },
    {
        "id": "a99ae555ccc4abb5",
        "type": "function",
        "z": "454b7c0d2cc14647",
        "name": "level",
        "func": "msg.payload.Füllmenge =  (2300 - msg.payload.Distance)*2.32388\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 640,
        "y": 1020,
        "wires": [
            [
                "c4aa3711222d1081",
                "ac3964d106fdecc3"
            ]
        ]
    },
    {
        "id": "ac3964d106fdecc3",
        "type": "influxdb out",
        "z": "454b7c0d2cc14647",
        "influxdb": "bb5dec3a1b53afc0",
        "name": "nodemap in",
        "measurement": "distanz",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 950,
        "y": 1040,
        "wires": []
    },
    {
        "id": "bb5dec3a1b53afc0",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "distanz",
        "name": "",
        "usetls": false,
        "tls": "7f61ad963cfa96fb",
        "influxdbVersion": "1.x",
        "url": "http://localhost:8086",
        "rejectUnauthorized": true
    },
    {
        "id": "7f61ad963cfa96fb",
        "type": "tls-config",
        "name": "",
        "cert": "",
        "key": "",
        "ca": "",
        "certname": "",
        "keyname": "",
        "caname": "",
        "servername": "",
        "verifyservercert": true,
        "alpnprotocol": ""
    }
]

image

image

1 Like