Reputation: 23
Background:
My questions:
Is there any suggestion for MQTT broker? I found mosquitto and moquette. Although the download link for the binary listener for the second is dead.
Sample implementation of using localhost for connection:
//publish
MqttClient client = new MqttClient("tcp://localhost:1883", MqttClient.generateClientId());
client.connect(); MqttMessage message = new MqttMessage();
message.setPayload(messageString.getBytes());
client.publish("iot_data", message);
System.out.println("\tMessage '"+ messageString +"' to 'iot_data'");
client.disconnect();
//subscribe
MqttClient client=new MqttClient("tcp://localhost:1883", MqttClient.generateClientId());
client.setCallback( new SimpleMqttCallBack() );
client.connect();
client.subscribe("iot_data");
Upvotes: 1
Views: 387
Reputation: 3941
by connecting the android device to the PC, your android device should get an IP. You may be used that IP address to connect the mqtt clients to the android device (mqtt broker)
Upvotes: 0