Does anyone know of an MQTT broker that runs on an Android smartphone? I tried to Google and found nothing, and on the app store there seems to be only one app with just 10 downloads, so I'm not sure how well it works.
-
Why would you like to run a MQTT broker on Android? – Christian Götz Feb 20 '15 at 08:08
-
I'm working on a project that may require that multiple clients on the phone talk to each other using MQTT. The same type of clients talk to each other from one device to another using an external MQTT broker, so from the reuse point of view and the requirement that they talk via MQTT, I (think I) really need an MQTT broker. – Branex Feb 20 '15 at 08:28
4 Answers
Add these dependencies to the gradle
dependencies{
compile 'io.moquette:moquette-netty-parser:0.8.1'
compile 'io.moquette:moquette-broker:0.8.1'
compile 'io.moquette:moquette-parser-commons:0.8.1'
}
And use
io.moquette.server.Server server = new io.moquette.server.Server();
server.startServer();
to start broker server. the default URI is tcp://localhost:1883
For me server.startServer();
gave me exception as it is unable to create a file BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME
.
So, I changed the destination of the BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME
using this code below code and it worked for me.
try {
MemoryConfig memoryConfig = new MemoryConfig(new Properties());
memoryConfig.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME);
server.startServer(memoryConfig);
// server.startServer();//is not working due to DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
Log.d(TAG,"Server Started");
}
catch (IOException e) { e.printStackTrace(); }
catch (Exception e){ e.printStackTrace(); }
And Use Paho libraries for android
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
To create a client and connect to tcp://localhost:1883
and subscribe for a topic and start publishing and receiving messages.

- 564
- 4
- 10
-
1I have tried this,but this keeps on crashing my app without showing any errors.could you help me with this? – Dhruv Marwha Jul 19 '17 at 08:11
-
Now it does not crash the app but instead cannot connect to the server.How do i start the server at tcp://localhost:1883? – Dhruv Marwha Jul 19 '17 at 09:30
-
1use `io.moquette.server.Server server = new io.moquette.server.Server(); server.startServer();` to start service run this code in service or a thread. – Tej Oct 03 '17 at 17:27
-
@DhruvMarwha access it here - https://play.google.com/store/apps/details?id=server.com.mqtt – anshulkatta Oct 09 '17 at 05:49
-
@anshulkatta Thank You.I'll check it out surely.When did you make this app? – Dhruv Marwha Oct 09 '17 at 06:29
-
Hello @Tej i mean it is working fine though but i am unable to access My Android broker from outside of Android app, i am able to create client within broker app, weather i access it with localhost or with manual ip of device it does work, but from out side of Android device if i try to access connection refused, or connection time out i am facing, could you please enlighten? – umer sufyan Feb 22 '19 at 07:21
-
getting error : Caused by: java.lang.NoSuchMethodException:
[] W/System.err: at java.lang.Class.getConstructor0 at server.startServer(memoryConfig); – RBK Dec 10 '19 at 18:18 -
-
Is there any workaround for missing distribution tar file for moquette? when i try to download, it redirects me to a dead link with "Forbidden!" message. https://github.com/technocreatives/moquette#1-minute-set-up – Ashkanxy May 24 '21 at 15:45
I have developed an App specifically for this , please download here -
It has inbuilt broker and client too..all for free , connect your devices to android phone via hotspot or wifi.
https://play.google.com/store/apps/details?id=server.com.mqtt

- 2,044
- 22
- 30
-
1why is this answer downvoted? Because he did the app himself? IMHO this answers the original question perfectly.. And I'm giving a try to this app right now – javirs Apr 23 '18 at 06:31
-
1Can you share the code in github and make it open source it will be very useful. Thank you. – RaghavPai Apr 26 '18 at 10:02
-
1+1 on open sourcing the code. This is really a cool app. Thanks for building it. If there is no internet, then the IP address is 0.0.0.0:1883. I think this makes sense but if I have other devices connected to a phone over the hotspot, then I would want the IP address to be 192.168.43.1:1883 where 192.168.43.1 is the default IP address for the hotspot. This IP address may have been changed by mobile phone manufacturer sometimes. – ranganath111 Mar 19 '19 at 23:11
You can run the mosquitto mqtt broker within the Termux terminal.
- Install Termux using e.g. F-Droid
- Open/run the Termux Terminal emulator
Install mosquitto
pkg install mosquitto
Start mosquitto within the terminal
mosquitto
That's it. The server will listen on the default port 1883. Configuration see at mosquitto.

- 369
- 1
- 10
-
The question makes it super clear that it's about an MQTT broker "runs on an Android smartphone" – Cassio Landim Jan 25 '22 at 07:48
Here is an MQTT broker library I have adapted to Android: https://github.com/interaktionsbyran/moquette You'll have to make your own Android app though, it is just a library.

- 799
- 1
- 6
- 13