No data Recevied with MQTT IN

Hi, This is my first question to this forum. Sorry, If I make a mistake in question format.
I use ESP32 to send CAN protocol frames and I am able to get data using python paho succesfully. (python script is attached).
But I couldn't get data using node-red platform, it connects, but there is no data is received? Where is my mistake?


Welcome to the forum!

Can you show how you have configured the MQTT in node, this is the configuration node.
Looking at the node label of the MQTT node on the left it looks like you are trying to subscribe to #. In your Python node you subscribe to /CAN/#.

Hi @berkerali welcome to the forum.

Few things...

  1. I see in your 1st screenshot you subscribe PAHO to /CAN/# but in node-red you subscribe to #. Firstly: some brokers do not permit access to # (I am pretty sure EMQX is one of those). Also, since broker.emqx.io is a public broker there will probably be MILLIONS of payloads hitting that MQTT topic filter per second - not wise at all.

  2. You should not start a topic with a / e.g. can/device-id/status is a far better topic. Infact since broker.emqx.io is a public broker, you should either use a more distinct topic (e.g. berkarali-public-data/can/device-id/status) or change to a private cloud MQTT or your own broker (e.g. a local EMQX or MOSQUITO)

Hope that helps.

1 Like

Actually, I've tried much more possibility including CAN/#.
Screenshot 2022-05-31 123540

  1. I use /CAN/engine while sending data, # just for the the test at the start. Even though I've changed /CAN/engine topic I couldn't get data. Still I always get data in python script.
  2. First time I hear this information. Works in python too?

From MQTT Topics, Wildcards, & Best Practices – MQTT Essentials: Part 5 ...

MQTT Best practices

Never use a leading forward slash

A leading forward slash is permitted in MQTT. For example, /myhome/groundfloor/livingroom . However, the leading forward slash introduces an unnecessary topic level with a zero character at the front. The zero does not provide any benefit and often leads to confusion.

Works for me!
image

[{"id":"41fa41950c07ae96","type":"mqtt in","z":"55525a9d18c99b86","name":"","topic":"/CAN/#","qos":"2","datatype":"auto","broker":"dc811dae.05f5","nl":false,"rap":true,"rh":0,"inputs":0,"x":950,"y":628,"wires":[["39948fe0b7bc780f"]]},{"id":"39948fe0b7bc780f","type":"debug","z":"55525a9d18c99b86","name":"/CAN/#","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"msg","x":1160,"y":628,"wires":[]},{"id":"6095145b8b5e8c13","type":"inject","z":"55525a9d18c99b86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"/CAN/engine","payload":"works for me!","payloadType":"str","x":1010,"y":580,"wires":[["84389b84871e7032"]]},{"id":"84389b84871e7032","type":"mqtt out","z":"55525a9d18c99b86","name":"mqtt out","topic":"","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"dc811dae.05f5","x":1200,"y":580,"wires":[]},{"id":"dc811dae.05f5","type":"mqtt-broker","name":"","broker":"broker.emqx.io","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"5","keepalive":"50","cleansession":true,"birthTopic":"testing123/birth","birthQos":"0","birthPayload":"123","birthMsg":{"contentType":"text/plain","userProps":"{\"birthprop\":\"123\"}","respTopic":"testing123/birth-resp","correl":"birth-correl","expiry":"9999"},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"testing123/will","willQos":"0","willPayload":"123","willMsg":{"contentType":"application/json","userProps":"{\"willprop\":\"123\"}","respTopic":"testing123/will-resp","correl":"will-correl","expiry":"888","delay":"12"},"userProps":"","sessionExpiry":""}]

Well I can confirm that broker.emqx.io does not allow you to subscribe to # (No messages arrive at all)
But if one is foolish enough to subscribe to /# , a shedload of [other people's] messages show up!

why are you insulting? Foolish ? python worked and stayed that way. It can. We can also make mistakes.

What does it mean? Where is my wrong?

I think you might have misunderstood what @jbudd was saying. If you use a top level topic of # that says 'subscribe to everything that is published by anyone.' Now if you were to subscribe to CAN/# that says to subscribe to everything that gets published with CAN as the top level of the topic.`

@berkerali please dont read it wrong, JBudd is not calling you foolish (he is merely saying it would be foolish to subscribe to # because millions of payloads will travel over the internet to your computer)

Is someone insulting?

Did you try importing @Steve-Mcl's flow and see if it works for you?

Sorry, I dont understand what are you saying here?

Could you try to import the demo flow I provided - does it work for you?

If not, then tell us more about your node-red setup (does it have access to internet? what version of nodejs and node-red are you using? etc)

I think. No need to use foolish word. Others may have used it accidentally (especially beginners). This is not stupidity, it is a mistake.

ahhh it was me!

No, I was not insulting you, I was actually referring to the fact that when I subscribed to /#, my Node-red system was immediately overwhelmed.

I apologise for not making that clear.

1 Like

That is very telling - it means there are a LOT of people posting to /something - imagine EMQX actually allowed you to subscribe to # - :boom:

I see messages in my flow. Btw, how can I import your demo flow?

Copy the posted flow and use CTRL+i to import.

If you dont mind me saying, you might benefit from some tutorials? I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Then it is definitely working. Perhaps your device is not publishing values?