# MQTT Topic TTN

**URL:** <https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682>\
**Category:** Application Development\
**Created:** [December 6, 2021, 3:33pm UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682 "2021-12-06T15:33:13Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![kersing](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/kersing/32/44777_2.png) [@kersing](https://www.thethingsnetwork.org/forum/u/kersing)\
**Post date:** [December 11, 2021, 4:25pm UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/23 "2021-12-11T16:25:58Z")

</div>

I don’t think that is the decoder you are using as your message clearly contains a number with the additional “mm” and that is not added in this decoder.

To store the distance in a usable format I think you need just a number. That way you can use it for calculations and graphs, if you store it as a string (which would be required to store the mm) you can’t use it without transformation so no way to have the database calculate average, min, max etc. Or use a tool like grafana to create graphs.

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 13, 2021, 7:24am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/24 "2021-12-13T07:24:05Z")

</div>

> [@kersing](#):
>
> I don’t think that is the decoder you are using as your message clearly contains a number with the additional “mm” and that is not added in this decoder.

Yes I wasn’t using that decoder you are 100% right. but after your tip I changed the decoder. I copied the Dragino Decoder and deleted the “mm” now I’m getting the distance without the “mm”.

> [@kersing](#):
>
> To store the distance in a usable format I think you need just a number. That way you can use it for calculations and graphs, if you store it as a string (which would be required to store the mm) you can’t use it without transformation so no way to have the database calculate average, min, max etc. Or use a tool like Grafana to create graphs.

Okay, this makes a lot of sense… So it would be dump to store it with that because I want to store it to visualise it in Grafana

I will now have a look if I can get it to work but I also think there is an additional problem with my “Influxdb Node”.

But Thank you for your help and your tips!

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 13, 2021, 8:25am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/25 "2021-12-13T08:25:02Z")

</div>

Good morning.  
Now im getting my data as a “number” in the "  
msg.Distanz"  
 ![Screenshot (26)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/a/3/a3039deb403a4690387c818099441bb9b5013e4c.png)

I used a change node to write the Distance as a number into the msg.Distanz.  
I assume this is exactly the data type I need and I can write into the Db, right?  
Now I want to write the distant into the databank.  
But with the settings in my “influxdb out” node I’m getting an parsing error:

```auto
Error: A 400 Bad Request error occurred: {"error":"unable to parse 'distanzquelle

```

![Screenshot (29)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/2/e/2edd690d92edfe0b8a318f2ef949ff60db4b7292.png)  
 ![Screenshot (30)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/b/6/b69514538ca88a7d51f5b83c320a0b3ee6187fa9.png)  
 ![Screenshot (32)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/2/c/2cec0d871250f465c6470f550c6cbb8d33248082.png)

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 13, 2021, 9:22am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/26 "2021-12-13T09:22:56Z")

</div>

> [@0815](#):
>
> Now im getting my data as a “number” in the "  
> msg.Distanz"

How is your change node set up?

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 13, 2021, 9:40am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/27 "2021-12-13T09:40:53Z")

</div>

Good morning.  
its a basic setting where i just writing the distance into the msg.Distanz.  
I assume the “influxdb” Node is still getting the whole string?

Thank you very much in advance!  
 ![Screenshot (33)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/e/e/ee147d3ac8807df33d95d60f98984df1ce5ace47.png)

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 13, 2021, 10:24am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/28 "2021-12-13T10:24:09Z")

</div>

![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/c/5/c549f5aea34ba7f3e507e5503aaaadd8a768275a.png)  
Can’t see 1/2 a of the “msg.payload.uplink\_me…”

If you don’t answer the questions asked originally and following some guides and post1/2 information, nobody can guess or help you.

If you posted the correct information, could have helped you 6 day ago.

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 14, 2021, 8:16am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/29 "2021-12-14T08:16:59Z")

</div>

> [@Johan\_Scheepers](#):
>
> Can’t see 1/2 a of the “msg.payload.uplink\_me…”

Oh yes, you are right..completely forgot… I wanted to send the msg…  
I’m sorry for this..

```auto
payload.uplink_message.decoded_payload.Distance

```

> [@Johan\_Scheepers](#):
>
> If you don’t answer the questions asked originally and following some guides and post1/2 information, nobody can guess or help you.

I’m very sorry for being that complicated about this and I want to apologise for this and also want to thank you for your time and nerves about this.  
But I did my best to give you guys everything you want.

> [@Johan\_Scheepers](#):
>
> If you posted the correct information, could have helped you 6 day ago.

Which information you are referring to right now?  
Well as I said before I’m sorry for this but I was trying my best…

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 14, 2021, 8:40am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/30 "2021-12-14T08:40:24Z")

</div>

> [@Johan\_Scheepers](#):
>
> Ok, so what is the json now? (straight form the output of the 'mqtt node")

Post this so we can make sure the decoder is working correctly.

Then we can give attention to the change node and last to make sure the data is correct in the DB.

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 14, 2021, 8:55am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/31 "2021-12-14T08:55:15Z")

</div>

Good morning.  
In the screenshot below you can see the payload directly after the “MQTT node” as requested.  
 ![Screenshot (36)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/8/3/83bb87a9ff756c404599d43c32e6edb804005291.jpeg)  
As you can see the payload is decoded as a Java object payload and the distance is printed without the mm.

Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 14, 2021, 9:33am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/32 "2021-12-14T09:33:27Z")

</div>

Ok.

Now make sure your change node does it’s job correctly. For the two highlighted fields I will copy and past from the JSON, as typos are easy to be made.

There is a button on the right of the debug window that does this job.  
 ![85R6RbPvqs](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/0/f/0fa12b181e378241c084f5f43626bf6f58d8c86d.gif)

I will wright the EUI and the sensor value to the DB, if I were you.

![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/a/e/ae57710c0ead5683407b93ac5228d1d319e05d49.png)

Now check the JSON form the change node and see if that is correct.

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 14, 2021, 9:42am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/33 "2021-12-14T09:42:04Z")

</div>

Thank you for your reply as well in this topic!

> [@Johan\_Scheepers](#):
>
> I will wright the EUI and the sensor value to the DB, if I were you.

Im saving both of them so I now exactly which device made this measurement?

> [@Johan\_Scheepers](#):
>
> Now check the JSON form the change node and see if that is correct.

You mean I need to check what I’m getting after the change node?  
As far as I understand what you want me to know I made to debug nodes. One with the “msg.payload” and one with the “msg.dev\_eui”.  
is this what you meant?

 ![Screenshot (37)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/1/2/1281ad27c867fe87a2e88ff0b18287b462f72053.png)

Thank you very much in advance!

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 14, 2021, 9:45am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/34 "2021-12-14T09:45:29Z")

</div>

> [@0815](#):
>
> Im saving both of them so I now exactly which device made this measurement?

Yes, as you can use the same DB for all your sensors.

> [@0815](#):
>
> You mean I need to check what I’m getting after the change node?

Put the debug node and post the JSON

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 15, 2021, 8:35am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/35 "2021-12-15T08:35:55Z")

</div>

Thank you for your reply!

> [@Johan\_Scheepers](#):
>
> Put the debug node and post the JSON

 ![Screenshot (38)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/9/9/99cbe9dabcf311a10cb069dcaa30e45a9df241b9.jpeg)  
As you can see I’m having some trouble with the change node or to be more precise with the “dev\_eui”.  
I configured the change node as I posted in the picture before but I’m getting the message that the “msg.dev\_eui” is undefined.

I’m not sure why…

> [@Johan\_Scheepers](#):
>
> Yes, as you can use the same DB for all your sensors.

Cool!

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 15, 2021, 9:13am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/36 "2021-12-15T09:13:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 15, 2021, 9:16am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/37 "2021-12-15T09:16:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 15, 2021, 9:20am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/38 "2021-12-15T09:20:35Z")

</div>

Are there a value in the “dev\_eui”? As TTN always forwards this…

> [@0815](#):
>
> application\_id for identification

What happens if you decide you need a second device?

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 15, 2021, 9:26am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/39 "2021-12-15T09:26:49Z")

</div>

> [@Johan\_Scheepers](#):
>
> dev\_eui”?

 ![Screenshot (39)](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/4/7/474c33e81454470dc26d2ded38c5a2bcbbe9e00b.jpeg)  
Yes there is a value in the “dev\_eui” row.

> [@Johan\_Scheepers](#):
>
> What happens if you decide you need a second device?

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?

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 15, 2021, 10:13am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/40 "2021-12-15T10:13:27Z")

</div>

> [@0815](#):
>
> As you can see I’m having some trouble with the change node or to be more precise with the “dev\_eui”.  
> I configured the change node as I posted in the picture before but I’m getting the message that the “msg.dev\_eui” is 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.

---

<div class="post-metadata">

**Author:** ![0815](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/0815/32/35697_2.png) [@0815](https://www.thethingsnetwork.org/forum/u/0815)\
**Post date:** [December 15, 2021, 11:01am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/41 "2021-12-15T11:01:10Z")

</div>

> [@Johan\_Scheepers](#):
>
> I will wright the EUI and the sensor value to the DB, if I were you.

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

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [December 15, 2021, 11:46am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682/42 "2021-12-15T11:46:51Z")

</div>

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

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

[Previous page](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682.md?page=1)

[Next page](https://www.thethingsnetwork.org/forum/t/mqtt-topic-ttn/53682.md?page=3)
