# Publish NaN on MQTT

**URL:** <https://discourse.nodered.org/t/publish-nan-on-mqtt/31301>\
**Category:** General\
**Created:** [8 August 2020 04:18 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301 "2020-08-08T04:18:17Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![spidgrou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spidgrou/32/27005_2.png) [@spidgrou](https://discourse.nodered.org/u/spidgrou)\
**Post date:** [11 August 2020 10:44 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/22 "2020-08-11T10:44:40Z")

</div>

Andrew,  
ues Y2K is th name of my boat where I live.

I tried to change the MQTT IN to Json Object but in the debug I read "Failed to parse JSON string" because it cannot manage the "NaN".

I tried, right now again, with Flespi, my cloud MQTT, and everything works.

Thanks for your time.  
Max

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [11 August 2020 11:13 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/23 "2020-08-11T11:13:10Z")

</div>

Ok, I didn't get as far as the `NaN` bit...... But I'm a bit confused that it worked as is, but I don't have MQTT installed on the machine it is running.

Not sure if `lcoal-host` means it just _cheats_ or not.

 ![Screenshot from 2020-08-11 21-10-14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/0183dd046716a29ae0d79c901b99960966f8bb28.png)

You can't send the received message into a node that expects a `number`.

You need to take apart the message to get the numbers.

Though there will now be two messages, as there is Latitude and Longitude.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 August 2020 11:48 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/24 "2020-08-11T11:48:34Z")

</div>

Andrew, you are missing the point, which is that he publishes one message to mqtt and gets two back, the good one and a NaN.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [11 August 2020 11:52 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/25 "2020-08-11T11:52:07Z")

</div>

Sorry. Ok. I am not as quick as I would like, or usually am.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [11 August 2020 12:01 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/26 "2020-08-11T12:01:47Z")

</div>

Ok, I'm not fully up to speed with exactly what is happening.

Reading the whole thread again this is what I get:

1 - if you use your local machine as the MQTT broker, it (the MQTT part) sends two messages back in _reply_ to you sending a message.  
2 - if you use an external MQTT broker, it works.

Really going out on a limb:

Open the CLI (Terminal) on the Ras pi.  
Actually two.....

The _topic_ (channel?) of MQTT you are using is:  
`vessels/self/navigation/NewPositionTest`

In the CLI send a message to yourself.

In one type:  
`mosquitto_sub -h local-host -t vessels/self/navigation/NewPositionTest`

Then in the other CLI type:  
`mosquitto_pub -h local-host -t vessels/self/navigation/NewPositionTest -m "This is a test"`

See if you get two replies.

If not, expand on this and copy/paste the message payload and see what happens from the CLI.

I'm only throwing ideas in an attempt to find out where the problem is happening and why.

Another thing to try:

**IF** you get back two replies.......

`cd .node-red`  
`node-red-stop`

and try again.

I am only saying this to eliminate things one at a time and piece by piece.  
Otherwise there is not going to be much happening to rule things out as good or bad.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 August 2020 20:58 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/27 "2020-08-11T20:58:16Z")

</div>

The results from post 13 confirms that when you publish to that topic you are getting two results back. I can only think of two possibilities for how that could happen.

1. As you have suggested, a serious bug in the mqtt broker that somehow makes that happen. The reason I am resistant to that suggestion is that it would be a very odd bug. It could be that however.
2. That something else is also subscribed to that topic (or a wildcard version of it) and that when it sees the message from your publish it then publishes the NaN. To fit the fact that when you switch to a different broker it fixes the problem requires that this second client (or flow) does not publish to the different broker. Is that conceivable?  
One way to test that would be to change the topic in your test flow to "something/completely/different" for the publish and the subscribe and see what happens.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 August 2020 21:29 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/28 "2020-08-11T21:29:42Z")

</div>

What happens If you change the topic to something else in both the publish and subscribe nodes?

---

<div class="post-metadata">

**Author:** ![spidgrou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spidgrou/32/27005_2.png) [@spidgrou](https://discourse.nodered.org/u/spidgrou)\
**Post date:** [12 August 2020 00:46 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/29 "2020-08-12T00:46:36Z")

</div>

Guys,  
yes if I change the topic with something completly different string it works also on local MQTT Server.

 ![Immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/692037ed197c1ee10477ac0f7d8fe3220a06b013.jpeg)

That is very good.

Thanks again for your time.  
Max

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 August 2020 01:09 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/30 "2020-08-12T01:09:15Z")

</div>

I am still suspicious of the _local MQTT server_ part in all this.

What happens from a terminal/CLI as I suggested?

---

<div class="post-metadata">

**Author:** ![spidgrou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spidgrou/32/27005_2.png) [@spidgrou](https://discourse.nodered.org/u/spidgrou)\
**Post date:** [12 August 2020 02:54 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/31 "2020-08-12T02:54:39Z")

</div>

Andrew,  
I think that Mosquitto is not my MQTT server on my installation.  
The MQTT Server that I have comes with Openplotter image, so I cannot follow your instruction.

Max

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 August 2020 04:53 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/32 "2020-08-12T04:53:08Z")

</div>

Ok, that's no problem in that sense of things, but it (therefore) is a possible problem.

I have to agree with the line of thinking that:

If you remove all known things that what ever is left - despite what it is - has to be the problem.  
(Or words to that end)

I would seriously dig into what it is doing.

Can you understand why I am saying this?

I have no bias to any part of the system. I am simply trying to find the cause by testing parts.

That if you change the topic and it doesn't give the _two replies per message_ is also indicative that there is something going on _behind the scenes_ which could be causing this to happen.

So what happens in the CLI when you type `mqtt_sub......`?  
`command not found` is probably what I am guessing with your reply.

That too is _worrying_ as there should be some mechanism for _MQTT_ to send messages.  
The bare bones is (I'm guessing) that.  
If it isn't that means (implies - probably better) that the whole thing (MQTT) has been changed.

Hope to hear back.

---

<div class="post-metadata">

**Author:** ![spidgrou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spidgrou/32/27005_2.png) [@spidgrou](https://discourse.nodered.org/u/spidgrou)\
**Post date:** [12 August 2020 05:42 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/33 "2020-08-12T05:42:51Z")

</div>

Andrew,  
I understand your point of view so if I can help you, here I am.  
I tried to type some mqqt command, but the answer is: "Commando non trovato" (command not found in Italian)

 ![Immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0d04e1f4fa767ad88c418ebd5308d1d503e69440.jpeg)

Let me know how can I help you.  
I can try to write in the forum of OpenMarine, who develop OpenPlotter, but I don't know exactly what ask them, or may be you can enter in contact directly at [https://forum.openmarine.net/index.php](https://forum.openmarine.net/index.php) or again I can do it for you if you write me what I have to ask.

Let me know.  
Thanks  
Max

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 August 2020 05:47 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/34 "2020-08-12T05:47:54Z")

</div>

Ah! It is written in Italian.

I think you need to show them what is happening and get them to explain why you are getting two _replies_ to one message.

Ideally MQTT is only a message handling system. You send a message in and you get it out.

That you send one message in and you get two is alarm bells - for me.

This anomaly needs to be resolved - by them.  
Then you can see what happens from there.

Good luck.

But at this point you (we) have established that other than that is working.  
If you change the **topic** to something else it doesn't send back this `NaN` error.

So when it is set to that **topic** you get the error.

What is happening really needs to be explained - by them.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 August 2020 06:28 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/35 "2020-08-12T06:28:36Z")

</div>

Have you got any other flows subscribed to that topic, or possibly a different application, maybe on a different machine, subscribing to it?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 August 2020 08:33 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/36 "2020-08-12T08:33:26Z")

</div>

from the CLI please enter `mosquitto -v` and that will tell us the version of mosquitto if it is running on your pi.

Also, could you open one of the `mqtt` nodes and then show the server you are using.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 August 2020 09:26 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/37 "2020-08-12T09:26:23Z")

</div>

@spidgrou you have marked the thread as solved, does that mean you have found the underlying problem?

---

<div class="post-metadata">

**Author:** ![spidgrou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spidgrou/32/27005_2.png) [@spidgrou](https://discourse.nodered.org/u/spidgrou)\
**Post date:** [12 August 2020 10:09 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/38 "2020-08-12T10:09:29Z")

</div>

Colin,  
No, I've market solved because you found a solution changing the topic, but later Andrew wrote again.  
I remove the flag.  
Tomorrow morning I will write to the openplotter team.

Max

---

<div class="post-metadata">

**Author:** ![spidgrou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spidgrou/32/27005_2.png) [@spidgrou](https://discourse.nodered.org/u/spidgrou)\
**Post date:** [12 August 2020 10:11 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/39 "2020-08-12T10:11:24Z")

</div>

Hi,  
Unfortunately it is not Mosquitto server on my raspberry. I'm using an version call Openplotter that has his mqqt server already installed and it seem that is impossible to send any publish.

Max

---

<div class="post-metadata">

**Author:** ![spidgrou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spidgrou/32/27005_2.png) [@spidgrou](https://discourse.nodered.org/u/spidgrou)\
**Post date:** [12 August 2020 10:13 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/40 "2020-08-12T10:13:49Z")

</div>

> [@Colin](#):
>
> Have you got any other flows subscribed to that topic, or possibly a different application, maybe on a different machine, subscribing to it?

Colin  
Tomorrow morning I will try, now I'm tired and I need to sleep 😴😴😴😴  
Max

---

<div class="post-metadata">

**Author:** ![spidgrou](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spidgrou/32/27005_2.png) [@spidgrou](https://discourse.nodered.org/u/spidgrou)\
**Post date:** [13 August 2020 03:09 UTC](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301/42 "2020-08-13T03:09:54Z")

</div>

> [@Colin](#):
>
> Have you got any other flows subscribed to that topic, or possibly a different application, maybe on a different machine, subscribing to it?

Colin,  
I've just tried to publish to the same topic "vessels/self/xxx" with a esp8266 with tasmota firmware and i have the same result.

 ![Immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b68c7c1b9a6a43e948e1f19f42b09cf745b50dad.jpeg)

If I publish to the topic "vessels/xxxx" everything works well.  
So it seems that only under "xxx/self/" I have a problem, that is the place where all the messages come from SignalK.

What do you think?  
Max

[Previous page](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301.md?page=1)

[Next page](https://discourse.nodered.org/t/publish-nan-on-mqtt/31301.md?page=3)
