MatsuzakaSteven
MatsuzakaSteven

Reputation: 317

Android app not connecting to local MQTT Broker

I am a very beginner at MQTT and Node Red

I have set up Node Red on my laptop and Mosquitto as the broker, and it seems that both are assigned to my localhost address

Now I have been trying to get subscribed on this android app on my phone connected to the same Wi-fi connection as the laptop is using an app called MQTT Client, but it seems that I can't connect even though I have set up the ip to localhost and the client-id to be matching.

Note that what I'm trying to do is to subscribe to a topic in the app, and receive a message that I inject through node red

Did I miss any step?

Upvotes: 0

Views: 1143

Answers (1)

hardillb
hardillb

Reputation: 59618

localhost always refers to the machine the application is actually running on.

In this case you have entered localhost into the app running on the android device, so the application will try and connect to a broker running on the phone. Which of course does not have a broker running on it.

If you want to connect to the broker running on the raspberry pi then you will have to enter the IP address of the pi on the local wifi network (This is normally something starting 192.168.x.x).

localhost works when you configured Node-RED's MQTT nodes, because it is also running on the raspberry pi.

You also mentioned having matching clientid's, this also will not work, each client connecting to the MQTT broker needs a unique client id, if you have 2 clients with the same clientid then when the second one tries to connect it will just kick the first one off. Normally clients are set to automatically reconnect if disconnected, so the now kicked off client will try and reconnect, which in turn will kick the other one off and you get into a loop where only one client is ever connected. If you leave the clientid field empty in Node-RED it will generate it's own random id.

Upvotes: 1

Related Questions