MQTT Broker
MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.MQTT Broker for Android Mobile
After the long search I could not find any working android application for running MQTT broker in my mobile, so I decided to make it myself. In this post I am going to show you how the MQTT broker can be written for Android.Moquette for Android
Finally I found the Moquette based GitHub fork for the android application. I decided to create simple (very simple... Even there is no UI 😼 ) application on top of Moquette using the above GitHub project. Thanks to andsel (Contributor of this GitHub)
Steps
- Download the Project from GitHub
- Create the new Android project using Android Studio (The tutorial to create a new Android Project and setup the Android studio can be available here )
- Change the settings.gradle and add the dependent project module paths like below
include ':app', ':broker', ':netty_parser', 'parser_commons'
project(':broker').projectDir = new File(settingsDir, '../moquette/broker/')
project(':netty_parser').projectDir = new File(settingsDir, '../moquette/netty_parser/')
project(':parser_commons').projectDir = new File(settingsDir, '../moquette/parser_commons/')
- Create the object for Server and start the server. Add the below line in MainActivity.java
new Server().startServer();
- Enable the Read Write permission for external storage. It can be enabled via Manifest.xml entry, if we using the Android M or Higher version then we need to enable the run time permission (The detailed tutorial to request a permissions in android can be available here)
- That's all, we are ready to run the MQTT on android mobile. Now build and deploy the apk file.
- Start the application. The MQTT broker will be run on the default MQTT port 1883. Use the IP address of the mobile to access the broker.
Source Code and APK for MQTT Broker
The source code for the MQTT Broker application is available in the GitHub. The apk file can be downloaded from my Google Drive.
Comments
Post a Comment