# Mosquitto listening on two ports (inside/outside LAN)

**URL:** <https://discourse.nodered.org/t/mosquitto-listening-on-two-ports-inside-outside-lan/27635>\
**Category:** Share Your Projects\
**Created:** [1 June 2020 16:15 UTC](https://discourse.nodered.org/t/mosquitto-listening-on-two-ports-inside-outside-lan/27635 "2020-06-01T16:15:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [1 June 2020 16:15 UTC](https://discourse.nodered.org/t/mosquitto-listening-on-two-ports-inside-outside-lan/27635/1 "2020-06-01T16:15:52Z")

</div>

I have not found a way to initiate a command from my smartphone from outside my WLAN to Node-RED. I tried Telegram (chats arrive at the bot, but do not initiate anything in Node-RED, because they arrive from the wrong direction) and e-mail (polling interval too long). Other push solutions seem to cost some amount and maybe they only send push information TO the phone (?).

So I started playing with Tasker and the MQTT publisher plugin. It works flawlessly within my WLAN. I did not use any user login to mosquitto so far and don't want to change all devices inside the LAN.

Then I started a second mosquitto call with the configuration file:

```auto
[...]
port 1888
allow_anonymous false
password_file /etc/mosquitto/mosquitto.pw

```

and redirected a port xxxx from outside to the port 1888. Surely an extra ssl option would have been useful, but until now I do not see a requirement for that.  
The user credentials in the mosquitto.pw file are created with the command `mosquitto_passwd`.

I could have transferred all desired topics manually from one broker to the other or I could have used the bridge option of Mosquitto.  
But then I realised the concept "listener" within Mosquitto, which can define another instance of the first mosquitto listening to another port with different settings.

This is my current configuration: I created the following file

`/etc/mosquitto/conf.d/mosquitto2.conf`

```auto
per_listener_settings true

port 1883 # maybe not required here
allow_anonymous true

listener 1888
allow_anonymous false
password_file /etc/mosquitto/mosquitto2.pw
mount_point external/

```

With the mount\_point option clients from outside only have access to topics starting with "external/", but do not see this extra topic. Mosquitto will add the prefix automatically for all communications via this port.

subcribe to Mosquitto port 1883 (without login): `external/phone/start`  
publish something to Mosquitto port 1888 (with the user credentials from the password file): `phone/start`  
and vice versa.  
If you omit the mount\_point option the clients from outside have access to all topics (which may be useful for other people). You could also play with ACL rights for certain topics.

Feedback welcome! 😀 🧐

---

<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:** [2 June 2020 00:18 UTC](https://discourse.nodered.org/t/mosquitto-listening-on-two-ports-inside-outside-lan/27635/2 "2020-06-02T00:18:21Z")

</div>

> [@stefan24](#):
>
> I tried Telegram (chats arrive at the bot, but do not initiate anything in Node-RED, because they arrive from the wrong direction)

Not quite sure what you mean there. I have both command-based and conversation-based controls available on my bots. I can easily control lights for example and query the state of lighting and heating.

> [@stefan24](#):
>
> Surely an extra ssl option would have been useful, but until now I do not see a requirement for that.

Lack of SSL/TLS means that you are sending everything - including your ID and Password in clear text over the Internet. Not really the smartest of approaches.

> [@stefan24](#):
>
> Feedback welcome!

A reasonable approach - apart from the lack of TLS. Of course, there is always some risk when exposing anything to the Internet. Using a non-standard MQTT port helps with that somewhat as does using id/pw so the risk is quite low.

The advantage of Telegram is that all of the security complexities are dealt with for you and you have a ready-made interface with simple buttons (keyboards as Telegram call them) and conversational interfaces. You also get sound, video and location msg types too along with a common client across multiple platforms. But perhaps the main benefit is that you don't need to allow any inbound connections from the Internet.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [4 June 2020 19:07 UTC](https://discourse.nodered.org/t/mosquitto-listening-on-two-ports-inside-outside-lan/27635/3 "2020-06-04T19:07:55Z")

</div>

> [@TotallyInformation](#):
>
> > [@stefan24](#):
> >
> > I tried Telegram (chats arrive at the bot, but do not initiate anything in Node-RED, because they arrive from the wrong direction)
> 
> Not quite sure what you mean there. I have both command-based and conversation-based controls available on my bots. I can easily control lights for example and query the state of lighting and heating.

I can send messages via Telegram/Android to the bot and let him reply or send messages from the bot from Node-RED to my user id.

I tried to use Telegram from Tasker (Android) via [api.telegram.org](http://api.telegram.org). But I can send only a chat message as bot and not TO the bot.

`https://api.telegram.org/botnumber/sendMessage?chat_id=mychatid@botname&text=Test`

That means I cannot send automated (!) messages from my phone to Node-RED via Telegram for example with Tasker!

---

<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:** [4 June 2020 19:46 UTC](https://discourse.nodered.org/t/mosquitto-listening-on-two-ports-inside-outside-lan/27635/4 "2020-06-04T19:46:08Z")

</div>

> [@stefan24](#):
>
> That means I cannot send automated (!) messages from my phone to Node-RED via Telegram for example with Tasker!

Can't tasker create a new Telegram msg in a channel? e.g. simulate a user?

Certainly, you cannot have two bots talking to each other because that is a recipe for disaster! That is a deliberate design choice by Telegram.

---

<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:** [31 July 2020 16:15 UTC](https://discourse.nodered.org/t/mosquitto-listening-on-two-ports-inside-outside-lan/27635/5 "2020-07-31T16:15:55Z")

</div>

Closed on 31 July 2020 16:15 UTC

This topic was automatically closed after 60 days. New replies are no longer allowed.
