Sub-pub MQTT between two VM (Virtual Box - Ubuntu 18.04)

Hi all,

I'm newbie on Node-Red and MQTT paradigm. My setup is host PC Windows 10 with two VMs on Virtual Box running Ubuntu 18.04. I've installed mosquitto and node-red in both VMs.

I've successfully publish and subscribe in one of the VMs in the same flow. However, I want to subscribe in one VMs and publish in the other one. One VMs has the IP (publisher) and the other one (subscriber). I've tried the following:

  • Configure server in publisher with .99 and the subscriber with .45
  • Configure server both in publisher and subscriber with .45
  • Configure server both in publisher and subscriber with public IP 79.158.X.X

Unfortunately, non of the above configurations worked.

How should I do it?

Thanks in advanced

Do you have an MQTT broker ? Both VMs should connect to the same MQTT broker.

Install Mosquito on one of your VMs (or another VM)

You are right @Steve-Mcl. I've figured it out after publishing this post. However, after removing MQTT Broker from one of the VMs (leaving just for the subscriber), it still doesn't work. I send you the scheme.

from can you ping

What doesnt work?

What topic are you publishing to?
What topic are you subscribing to?

Yes, I can ping both sides @zenofmud.

@Steve-Mcl, it doesn't show the message published at the subscriber. Basically, I click on the left square from sensor1. It should show the work "Open" at the debug in sub.

Any clue?

You could start by answering my questions? :man_shrugging:

Or you could export your flow so we can have a look and more of an idea instead of poking around in the dark taking wild guesses? :thinking: :grinning:

Here the JSON code:


[{"id":"baacb768.a1efe","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"fa314afa.1b2aa8","type":"inject","z":"baacb768.a1efe","name":"sensor1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensors/sensor1","payload":"Open","payloadType":"str","x":90,"y":180,"wires":[["82813fd5.ef765"]]},{"id":"82813fd5.ef765","type":"mqtt out","z":"baacb768.a1efe","name":"","topic":"","qos":"","retain":"","broker":"c7358196.cbe0b","x":230,"y":180,"wires":[]},{"id":"c7358196.cbe0b","type":"mqtt-broker","z":"","name":"Publisher","broker":"","port":"1883","tls":"","clientid":"test-client","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]


[{"id":"25e1678d.b34f5","type":"mqtt in","z":"bbd66e8f.f71058","name":"","topic":"sensors","qos":"0","datatype":"auto","broker":"65e42425.efa29c","x":70,"y":160,"wires":[["584f9446.6d4e54"]]},{"id":"65e42425.efa29c","type":"mqtt-broker","z":"","name":"Subscriber","broker":"","port":"1883","tls":"","clientid":"Id 2","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"CAM","birthQos":"0","birthPayload":"Hello","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"CAM","willQos":"0","willPayload":"Hi"}]


You publish to sensors/sensor1

You subscribe to sensors

That wont work. I think you would do well to read up on MQTT.

Try subscribing to the same topic or use a wildcard topic.

You are right, I just solve it using same topic.

@rparada - I'd suggest reading thru the blog posts here:

It is a great reference for using MQTT especially the section on topics.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.