Axy
Axy

Reputation: 23

Connect an android device to PC (usbc-ethernet) using MQTT

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.

  1. Is there any sample project that uses USBC -> ethernet for MQTT client and MQTT broker? (more preferably in Java as this should be used on Android device)
  2. All examples i found online uses a URL for subscribing and publishing topics, which I assume they rely on internet/network connection. I was wondering how would be the process if the components are supposed to be connected through usbc-ethernet? Is any wrapper needed on to be used the following example in which a local host url is used for communicating between a MQTT broker and MQTT clients (borrowed the following example from this git-repository).

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

Answers (1)

Ashkanxy
Ashkanxy

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

Related Questions