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

**URL:** <https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666>\
**Category:** General\
**Created:** [2 October 2020 10:21 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666 "2020-10-02T10:21:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rparada](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rparada](https://discourse.nodered.org/u/rparada)\
**Post date:** [2 October 2020 10:21 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/1 "2020-10-02T10:21:04Z")

</div>

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 192.168.1.45 (publisher) and the other one 192.168.1.99 (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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 October 2020 10:38 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/2 "2020-10-02T10:38:04Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![rparada](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rparada](https://discourse.nodered.org/u/rparada)\
**Post date:** [2 October 2020 10:52 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/3 "2020-10-02T10:52:05Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/01a6619afeb3bb9e48762f5c8eb9861488815114.png)

---

<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:** [2 October 2020 11:25 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/4 "2020-10-02T11:25:52Z")

</div>

from 192.168.1.99 can you ping 192.168.1.45?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 October 2020 11:42 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/5 "2020-10-02T11:42:05Z")

</div>

> [@rparada](#):
>
> it still doesn't work

What doesnt work?

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

---

<div class="post-metadata">

**Author:** ![rparada](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rparada](https://discourse.nodered.org/u/rparada)\
**Post date:** [2 October 2020 12:36 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/6 "2020-10-02T12:36:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 October 2020 12:48 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/7 "2020-10-02T12:48:24Z")

</div>

You could start by answering my questions? 🤷‍♂️

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? 🤔 😀

---

<div class="post-metadata">

**Author:** ![rparada](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rparada](https://discourse.nodered.org/u/rparada)\
**Post date:** [2 October 2020 13:03 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/8 "2020-10-02T13:03:33Z")

</div>

Here the JSON code:

PUB

```auto
[{"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":"192.168.1.45","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":""}]

```

SUB

```auto
[{"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":"192.168.1.45","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"}]

```

Thanks.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 October 2020 13:28 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/9 "2020-10-02T13:28:18Z")

</div>

You publish to `sensors/sensor1`  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d068d3c6c8f9c4e5109f8de1e100da2299a07cb9.png)

You subscribe to `sensors`  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/48c8da59f523ee96d3db43ca567a6fac5fc894eb.png)

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.

---

<div class="post-metadata">

**Author:** ![rparada](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rparada](https://discourse.nodered.org/u/rparada)\
**Post date:** [2 October 2020 13:35 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/10 "2020-10-02T13:35:52Z")

</div>

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

---

<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:** [2 October 2020 14:40 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/11 "2020-10-02T14:40:39Z")

</div>

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

> **[MQTT Essentials](https://www.hivemq.com/tags/mqtt-essentials/)**

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 October 2020 14:40 UTC](https://discourse.nodered.org/t/sub-pub-mqtt-between-two-vm-virtual-box-ubuntu-18-04/33666/12 "2020-10-16T14:40:43Z")

</div>

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