title: Local broker (MQTT) based Publish mechanism from Android Application
body: <p>With the reference to question <a href="https://stackoverflow.com/questions/41431163/local-broker-mqtt-based-publish-subscribe-using-android-application">Local broker (MQTT) based Publish/Subscribe using Android Application</a>. In my current project, I would like to <strong>send data from Android application to Node.js using local broker based MQTT implementation</strong>.</p>
  
  <p>As per the solution provided in the above mentioned question, I am using the same solution to send data from Android application (<code>tcp://192.168.0.105</code>Android API for local broker) to Node.js app <code>mqtt://192.168.0.105</code> (Node.js side API for with the ip of local broker), but I could not able to send data from Android to Node.js app. Here <code>192.168.0.105</code> is the IP address of the local broker. If I use <code>mqtt://test.mosquitto.org:1883</code> API on Node.js side and <code>tcp://test.mosquitto.org:1883</code> API on client side than it works perfectly. </p>
  
  <p><strong>Using the local broker-based API, the entire project doesn't display any error.</strong> Sharing the log of the android project for the better clarity. It also prints the tempValue using the following log (line 1 in the log). </p>
  
  <pre><code>01-12 22:00:07.348: I/System.out(23135): tempValue is41.0in Android Smart Home App
  01-12 22:00:07.349: W/System.err(23135): Client is not connected (32104)
  01-12 22:00:07.349: W/System.err(23135):    at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:27)
  01-12 22:00:07.349: W/System.err(23135):    at org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:101)
  01-12 22:00:07.349: W/System.err(23135):    at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:119)
  01-12 22:00:07.349: W/System.err(23135):    at org.eclipse.paho.client.mqttv3.MqttTopic.publish(MqttTopic.java:62)
  01-12 22:00:07.350: W/System.err(23135):    at iotsuite.pubsubmiddleware.MQTTPublisher.publish(MQTTPublisher.java:34)
  01-12 22:00:07.350: W/System.err(23135):    at iotsuite.pubsubmiddleware.PubSubMiddleware.publish(PubSubMiddleware.java:89)
  01-12 22:00:07.350: W/System.err(23135):    at framework.SmartHomeApp.SetTempFromGUI(SmartHomeApp.java:40)
  01-12 22:00:07.350: W/System.err(23135):    at logic.LogicSmartHomeApp$1.onNewSetTempCommand(LogicSmartHomeApp.java:56)
  01-12 22:00:07.350: W/System.err(23135):    at deviceImpl.AndroidSmartHomeApp.onClick(AndroidSmartHomeApp.java:77)
  01-12 22:00:07.350: W/System.err(23135):    at android.view.View.performClick(View.java:5207)
  01-12 22:00:07.350: W/System.err(23135):    at android.view.View$PerformClick.run(View.java:21168)
  01-12 22:00:07.350: W/System.err(23135):    at android.os.Handler.handleCallback(Handler.java:746)
  01-12 22:00:07.350: W/System.err(23135):    at android.os.Handler.dispatchMessage(Handler.java:95)
  01-12 22:00:07.350: W/System.err(23135):    at android.os.Looper.loop(Looper.java:148)
  01-12 22:00:07.350: W/System.err(23135):    at android.app.ActivityThread.main(ActivityThread.java:5443)
  01-12 22:00:07.350: W/System.err(23135):    at java.lang.reflect.Method.invoke(Native Method)
  01-12 22:00:07.350: W/System.err(23135):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
  01-12 22:00:07.350: W/System.err(23135):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  01-12 22:00:07.350: I/System.out(23135): Publishing data in Smart Home App
  01-12 22:00:23.332: W/System(24876): ClassLoader referenced unknown path: /system/priv-app/Settings/lib/arm
  01-12 22:01:45.401: W/System(24934): ClassLoader referenced unknown path: /data/app/com.goibibo-1/lib/arm
  01-12 22:01:45.634: W/System(24934): ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000011/n/armeabi-v7a
  01-12 22:01:45.635: W/System(24934): ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000011/n/armeabi
  </code></pre>
  
  <p>The <code>tcp://192.168.0.105</code>,<code>mqtt://192.168.0.105</code>, and <code>http://192.168.0.105</code> APIs work with Node.js local broker based implementation.<strong>The Node.js code of the application as shown below:</strong></p>
  
  <pre><code>    var mqtt = require('mqtt');
  var client = mqtt.connect('http://192.168.0.105');
  client.subscribe('tempMeasurement'); 
  console.log("waiting for tempValue");
  client.on('message', function(topic, payload) {     
          if (topic.toString() == "tempMeasurement") {  
              console.log("Mesage Received "+ payload.toString());
          }           
  });  
  </code></pre>
  
  <p>The code of Android application is the same that I have posted in the above mentioned question. Am I missing in the solution provided by Hardillb in this implementation?</p>