eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.04k stars 2.39k forks source link

Why mosquitto bridge not working on Termux? #1878

Open AnkurJagani opened 3 years ago

AnkurJagani commented 3 years ago

Hi There,

I am using mosquitto broker for inter-communicating with my multiple android apps using termux application. all is working fine with default mosquitto.conf file.

Now, What I am trying to do is mqtt bridge via termux application. I am doing same configuration for bridge which I am able to perform successfully on my mac machine with the same mosquitto version (i.e. 1.6.11) . But, mqtt-bridge is not working when I do via termux application via my android phone device. Is some other configuration required when I am via termux application?

Is this right place to raise this question or Should I go to termux community (Although, it's already done)?

Thanks in advance!

ptjm commented 3 years ago

It's probably not the right place to ask. When you do ask a question like this, you need to try and put together a minimal configuration that you think should work, and include that with the question.

I just set up a minimal configuration with a bridge, and it seems to work OK. I'm on Android 6 and termux has stopped building for it, so I'm using version 1.6.8. I have these two config files. this.conf:

bind_address localhost
port 1883
connection that
address localhost:1884
topic thisthat both
local_clientid this.that
remote_clientid that.this

and that.conf:

bind_address localhost
port 1884

I started a couple of brokers, then connected mosquitto sub to "this":

$ mosquitto -c that.conf -d; mosquitto -c that.conf -d
$ mosquitto_sub -v -t thisthat

then I flipped to a different session and started a different mosquitto_sub, connecting to "that":

$ mosquitto_sub -v -p 1884 -t thisthat

and finally I flipped to a third session and ran mosquitto_pub against both brokers:

$ mosquitto_pub -t thisthat -m 'message 1'
$ mosquitto_pub -t thisthat -p 1884 -m 'message 2'

On both mosquitto_sub instances, I see

thisthat message 1
thisthat message 2

That's just on the android machine, but it shows the bridge working both ways. I tried the same thing with the bridge target on my desktop machine with mosquitto 1.6.12. that2.conf:

bind_address 192.168.2.110
port 1883
listener 1883 localhost

and this configuration on the android machine (this2.conf):

bind_address localhost
port 1883
connection that
address 192.168.2.110:1883
topic thisthat both
local_clientid this.that
remote_clientid that.this

This worked both ways in the same fashion.

I've found mosquitto configuration issues can be challenging to debug when you start mixing bridges, ACLs, and user authentication. The log messages around bridge connection make it clear if the connection has been made, and if not, why not. If that's working and the messages aren't showing up where you expect, it's time to start stripping down and building up from a minimal configuration.

AnkurJagani commented 3 years ago

@ptjm That's very clean flow you have guided. I am working on that. unfortunately, it doesn't work when I checking with remote broker test.mosquitto.org:1883. Below is my steps I am doing to achieve the results.

  1. open termux application on android oreo device, with termux 1.6.12 installed.
  2. nano test.conf.
  3. Saving test.conf file with below configurations.
    bind_address localhost
    port 1883
    connection bridge-test
    address test.mosquitto.org:1883
    topic # out 0 ""  ""
    topic # in 0 "" ""
    local_clientid local-mqtt-client
    remote_clientid remote-mqtt-client
  4. mosquitto -c test.conf -d
  5. mosquitto_pub -t ankur/test/mqtt -m "FIRST HELLO"

So now, it should start publish on the remote broker and any subscribed local client. this same configuration is working on my desktop mac machine.

I hope I am not mistaking anything in steps above.

ptjm commented 3 years ago

I don't have any further suggestions. I agree the bridge from termux doesn't appear to work in the inbound direction when run against test.mosquitto.org.

I tried your configuration with just the client IDs changed to keep them unique and found the outbound bridge worked, but the inbound one didn't. That is, with a client listening at test.mosquitto.org and another publishing on the android broker, the message went through, but with a client listening at the android broker and another publishing on test.mosquitto.org, it didn't. I tried the same config (apart from the client IDs) on my desktop machine and a raspberry pi that happened to have version 1.6.9 and they both appeared to work in both directions. So, publishing to test.mosquitto.org, the message would come through to those two machines, but not to the android machine.

I'll note that moquitto_pub and mosquitto_sub from termux do seem to work correctly against test.mosquitto.org, and the bridge works both ways when connected to my desktop machine, which is on the same LAN.