Basic Steps for Using MQTT in android

I am new to Android and want to use MQTT as push notifier for Android from Server.
i have read about MQTT but does not understand well. if any one has used this library so plz tell me what i have to do to start using it..

i have a Java Server (Running on Windows) and lots of Client(android phones on which my app will be installed). My server will send message to all or some specific clients at any time.

what are my basic requirement ? i mean is there

  1. server requirement ?
  2. some sort of registration ?
  3. Library to include in android ?
  4. identifier for Android device ? (as C2DM require Google account for each device)

plz help me in this regard


Solution 1:

You need:

  1. an MQTT broker which runs on the server side. This could be something like the mosquitto broker which is Open Source.
  2. an MQTT client library which you include in your Android app, enabling your app to connect, subscribe, and publish messages. There are a number of Java options listed at http://mqtt.org/software
  3. to come up with a way of uniquely identifying users or devices, and then use that as a topic so that you can individually publish a message to one device.

Dale Lane has written a nice guide on this (http://www.dalelane.co.uk/blog/?p=1599) and there is also a good set of resources about MQTT (https://github.com/mqtt/mqtt.github.io/wiki)

Solution 2:

Basic Steps

  1. Install the WAMP server with PHP (the version should be upper than 5.1.0)
  2. As the WAMP server is installed, start the WAMP server(so that it can get default configuration).
  3. Open command prompt and change the directory to the PHP{version},

For Ex. Cd C:\wamp\bin\php\php5.3.0

[1] Install PEAR

  • Now we have to install the PHP PEAR (i.e. not installed by default) by running the command below.

    php -d phar.require_hash=0 ./PEAR/go-pear.phar

    OR

    php -d phar.require_hash=0 go-pear.phar

  • Now check the directory PEAR under C:\wamp\bin\php\php5.3.0\PEAR (Installed or Not).

  • Now in the Directory C:\wamp\bin\php\php5.3.0 there is PEAR_ENV.reg (Registry File) is create, so double click on that to change PHP.ini file with PEAR invironment

  • Now as pear is installed we have to run the following commands (Optional).

    pear upgrade

    pear install upgrade-channels

    So the PEAR setup is now completed

[2] Install SAM (Simple Asynchronous Messaging)

  • To install SAM we have to Run the Following Command

    Goto C:\wamp\bin\php\php5.3.0

    Pecl install –B SAM

[3] Choose and Run Mosquitto or RSBM

  • Really Small Message Broker (RSMB) is a simple MQTT broker also provided by IBM http://www.alphaworks.ibm.com/tech/rsmb. It runs on port 1883 by default. In our architecture it accepts messages from the server and passes them on to the right devices. RSMB can also be replaced by the Mosquitto server http://mosquitto.atchoo.org/
  • lets go with the RSMB.
  • Download and goto Windows folder in rsmb ( your version )
  • Start Broker.exe

NOW YOUR SERVER IS CONFIGURED. YOU CAN USE IT FOR PUSH NOTIFICATION.

Solution 3:

If you want to use MQTT for send push notification in android device then this demo will be best for you.

By using this example you can send push notification to your android device.

    https://github.com/tokudu/AndroidPushNotificationsDemo

If you want to create your own Push service like LEADBOLT,AIRPUSH,etc.. then you have to required the following things.

[1] Configure your own server for send push notification.(like tokudu worked in PHP,WAMP) For configure SERVER.. [A] Install PEAR [B] Install SAM [C] Configure SAM

[2] You need mosquitto or IMB's RSMB for selecting target Android device. [3] You need some android code for receiving notification,send keep alive signals to server,create connection with server,etc... (Which can be found in TOKUDU example).

If you have any problem then tell me , i will definitely help you.