# Pass data between local & remote sites

**URL:** <https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165>\
**Category:** General\
**Created:** [26 October 2019 10:25 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165 "2019-10-26T10:25:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [26 October 2019 10:25 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/1 "2019-10-26T10:25:26Z")

</div>

I have a MQTT Mosquitto server running on a Raspberry Pi, and it receives local energy data every 5 seconds, along with other MQTT data - switches, environmental data etc.  
Currently, the same Pi processes the data in node-RED, and publishes it in a NR dashboard & Grafana.

However, I've also setup node-RED in a Oracle VM, and considering processing/displaying the data in the VM instance instead of my local Pi.

What would be the best way to securely/efficiently get the data to the VM from my local Pi, and get data back from the VM to my local Pi?

- MQTT using SSL/TLS
- MQTT over websockets
- Websockets
- Something else

I've no experience of doing any of the above, and I've a feeling that this is going to be a learning curve!!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [26 October 2019 12:10 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/2 "2019-10-26T12:10:16Z")

</div>

"Best" way is probably push MQTT over TLS.

"Easiest" way likely to be using Node-RED to replicate messages to the remote broker. You would also want TLS for that too though unless you are using a secure connection to the VPS (an SSH tunnel for example).

Best security is to ensure that you are only ever pushing data to the VPS & that the VPS has no way to send data back the other way.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [26 October 2019 13:36 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/3 "2019-10-26T13:36:31Z")

</div>

> [@TotallyInformation](#):
>
> "Best" way is probably push MQTT over TLS.

That leaves me with a bit of a problem because both sites are proxied by Cloudflare, and port 1883 is permenantly closed.  
I've read a number of previous posts about this, but not really seen a viable solution.

One suggestion made was to use MQTT over websockets, but I've found little information about this, let alone a NR example flow to work from. Also is this a resource hungry approach?

Another mentioned creating a sub-domain, and 'greying out' (removing) the cloudflare proxy from the sub-domain, so port 1883 would then be open for the sub-domain url.  
However, just tried that, and cloudflare reported that I was exposing my main domain, as proxied & non-proxied traffic was being directed to the same server IP.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [26 October 2019 17:11 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/4 "2019-10-26T17:11:07Z")

</div>

I believe that the "proper" way Cloudflare want you to use is their [Spectrum](https://developers.cloudflare.com/spectrum/getting-started/) tool which is part of their Enterprise plan so out of reach for most of us.

I think that you have to do one of the things you've mentioned. I'm not aware of any issues regarding performance mqtt over websockets though it is true that it does add an additional wrapper so the packets must be a little larger.

Not sure about the warning - that approach is recommended by Cloudflare themselves for allowing traffic to SSH for example.

Either way, make sure that you are only using TLS encrypted connections of course.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [26 October 2019 19:28 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/5 "2019-10-26T19:28:50Z")

</div>

Anyone got an example flow, or any pointers for setting up MQTT over Websockets?

I don't think it's covered in the node-RED guides or forum.  
Is it achieved by feeding the output from a MQTT 'in' node into a Websocket 'out' node, and vice-versa?  
No laughing now 😓

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [26 October 2019 19:46 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/6 "2019-10-26T19:46:09Z")

</div>

To configure the mqtt nodes to use websockets, set the broker URL to `ws://<broker-ip>/<path>` (or `wss://...` to use TLS)

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 November 2019 20:20 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/8 "2019-11-03T20:20:58Z")

</div>

I'm still failing miserably trying to get MQTT over websockets to work!  
I have 2 servers; `https://mysite.co.uk` & `https://nodered.mysite.co.uk`, one is on a local RP & the other a Oracle VM. Both have very simple flows;  
 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/94c67425766aa7c648b872b61d26d232bf4a20c0.jpeg)

I have not setup TLS security for the websocket connection yet, and therefore have set up the MQTT node server details like this;

![mqtt](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4d63045f12a9fdbbb0af95b622fb1aa5a55f13c8.jpeg)

I have setup the topic, no Retain, 0 QoS, and have used `ws://nodered.mysite.co.uk` in the `mysite.co.uk` site, and vice versa in the `nodered.mysite.co.uk` site, but they never connect, and the NR log shows `3 Nov 20:00:36 - [info] [mqtt-broker:bea3f71.9ee2608] Connection failed to broker: ws://nodered.mysite.co.uk`

I have searched here & google, but can't find a similar example to follow. Any advice please?

---

<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:** [3 November 2019 21:40 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/9 "2019-11-03T21:40:25Z")

</div>

Where are you running the mqtt broker?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 November 2019 21:44 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/10 "2019-11-03T21:44:40Z")

</div>

On `https://mysite.co.uk` but I can't see where the broker comes into play?

---

<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:** [3 November 2019 21:47 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/11 "2019-11-03T21:47:07Z")

</div>

The MQTT nodes have to connect to the same broker, but you seem to have configured the nodes to connect to brokers on the opposite machine.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 November 2019 21:48 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/12 "2019-11-03T21:48:48Z")

</div>

I thought that they were connected by websockets, not by the mqtt server?  
Sorry if I'm being a bit slow....

---

<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:** [3 November 2019 21:50 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/13 "2019-11-03T21:50:45Z")

</div>

Websockets is an option for how the mqtt nodes connect to the broker, at least that is how I understood it. The mqtt nodes don't talk directly to each other, each one talks to the broker.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [3 November 2019 21:51 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/14 "2019-11-03T21:51:07Z")

</div>

> [@Paul-Reed](#):
>
> 'm still failing miserably trying to get MQTT over websockets to work!

IIRC - you have to stick the port number in the server name for some reason  
try using ws://nodered.mysite.co.uk:9001 (or whatever port your broker is using for websockets)

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 November 2019 22:07 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/15 "2019-11-03T22:07:02Z")

</div>

> [@Colin](#):
>
> The mqtt nodes don't talk directly to each other, each one talks to the broker

Well if I set the server as `ws://mysite.co.uk` - which is the site containing the Mosquitto broker, it still does not connect.

> [@cymplecy](#):
>
> try using ws://nodered.mysite.co.uk:9001

I tried `ws://mysite.co.uk:1883` but it made no difference...

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [3 November 2019 22:09 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/16 "2019-11-03T22:09:08Z")

</div>

Your broker won't be using 1883 for websockets - default mosquitto is to use 9001 but in this example, the broker uses 8080

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8d06dbe1fbc88c1b4aac0940de89d4fdb30485ef.png)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [3 November 2019 22:10 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/17 "2019-11-03T22:10:44Z")

</div>

PS have you configured your broker to use websockets? They don't tend to be pre-configured for them out-of-the-box

---

<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:** [3 November 2019 22:13 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/18 "2019-11-03T22:13:31Z")

</div>

Also I would try getting it going with websockets using a broker on localhost first.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 November 2019 22:14 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/19 "2019-11-03T22:14:07Z")

</div>

> [@cymplecy](#):
>
> PS have you configured your broker to use websockets?

Erm, no!  
Is that in mosquitto.conf?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [3 November 2019 22:16 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/20 "2019-11-03T22:16:37Z")

</div>

Yes

From

[http://www.steves-internet-guide.com/mqtt-websockets/](http://www.steves-internet-guide.com/mqtt-websockets/)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/86674c2b7bcaa725f2a0eb2bab3e33d376847e1e.png)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [3 November 2019 22:20 UTC](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165/21 "2019-11-03T22:20:12Z")

</div>

Why not use ZeroTier and install it on both ends - it is essentially setting up a simple VPN for you

Craig

[Next page](https://discourse.nodered.org/t/pass-data-between-local-remote-sites/17165.md?page=2)
