MQTT node with blank topic name - only posts first time

100 views
Skip to first unread message

Eric

unread,
Oct 21, 2016, 12:06:42 AM10/21/16
to Node-RED
Hello,
I have a microcontroller outputting UART to a raspberry pi.  The strings from the UART look like this:

50C51C570B00 40
50C51C570B00 41
50C51C570B00 42

The intention is that these are MQTT message, the topic is 50C51C570B00, then there's a space, and the payload is 40.  Then 41 is posted to the same topic.  Follow by 42.  So node red is reading the serial string, splitting it up at the " " character, and then posting it to MQTT as topic and payload.  I left the MQTT node topic blank so that the first set of characters left of the " " is the topic, so the topics name are dynamically define by the UART string.

I'm running into an issue where when I first deploy the node red flow, the UART string gets posted to MQTT broker fine.  But the subsequent UART strings do not get posted on MQTT.  If I wiggle the node and then re-deploy, the first MQTT message again gets posted fine, but subsequent UART strings do not posted to mosquitto.

The UART from the microcontroller looks good (see bottom putty window).  The debug window for the serial node output also looks good, the strings are what they're suppose to be.  I've narrowed the problem down to the MQTT node.  It seems when I leave the topic name blank, I get this "first and only post" issue.  If I fill in the topic name field with something, I'll start seeing the MQTT topic posting new data, but now it's statically define to that topic name.

Any ideas on how I might fix this issue?  Here's the screen shots below:


Split function "return dynamic topic"



Dynamic MQTT topic node:




If I put the debug output on the output of the function, get debug output that I expect.  The payloads are right, and the topics are right.






Colin Law

unread,
Oct 21, 2016, 4:10:27 AM10/21/16
to node...@googlegroups.com
It would have been better to have copied/pasted the function code so I could more easily suggest improvements to make it simper, however what you have looks as if it aught to work.

Put a debug node on the output of the function node and set it to display the full message. Also put a debug node on the mqtt input node. Then run it and show us the results.

Colin

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/67452779-e78f-4f52-b447-d03f469e97dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

steve rickus

unread,
Oct 21, 2016, 5:23:13 PM10/21/16
to Node-RED

One thing I noticed that may or may not matter...

In the first screen shot, the debug output shows that the first msg.payload length = 16, while subsequent msg.payload lengths = 17
I am suspecting the messages that don't work have a hidden character somewhere that is messing up your topic string or your split function logic.

As Colin suggests, check the full msg object after the function node to see if the first one is created differently than the others. You might want to use the trim() function before the split, or even use a regex to pull the topic and value strings out of whatever string you read from the serial port.
--
Steve


On Friday, October 21, 2016 at 12:06:42 AM UTC-4, Eric wrote:
Hello,
I have a microcontroller outputting UART to a raspberry pi.  The strings from the UART look like this:

50C51C570B00 40
50C51C570B00 41
50C51C570B00 42

--snip --
 

 <== check debug output lengths

 

Dave C-J

unread,
Oct 21, 2016, 5:24:37 PM10/21/16
to node...@googlegroups.com
maybe use  .trim()  to remove any whitespace...
Reply all
Reply to author
Forward
0 new messages