public void publish(String topicName,int qos,byte[] payload) throws MqttException {
  log("Connecting to " + brokerUrl + " with client ID "+ client.getClientId());
  IMqttToken conToken=client.connect(conOpt,null,null);
  conToken.waitForCompletion();
  log("Connected");
  log("Publishing at: " + System.currentTimeMillis() + " to topic \""+ topicName+ "\" qos "+ qos);
  MqttMessage message=new MqttMessage(payload);
  message.setQos(qos);
  IMqttDeliveryToken pubToken=client.publish(topicName,message,null,null);
  pubToken.waitForCompletion();
  log("Published");
  log("Disconnecting");
  IMqttToken discToken=client.disconnect(null,null);
  discToken.waitForCompletion();
  log("Disconnected");
}

public void publish ( String topicName , int qos , byte [ ] payload ) throws MqttException { log ( "Connecting to " + brokerUrl + " with client ID " + client . getClientId ( ) ) ; IMqttToken conToken = client . connect ( conOpt , null , null ) ; conToken . waitForCompletion ( ) ; log ( "Connected" ) ; log ( "Publishing at: " + System . currentTimeMillis ( ) + " to topic \"" + topicName + "\" qos " + qos ) ; MqttMessage message = new MqttMessage ( payload ) ; message . setQos ( qos ) ; IMqttDeliveryToken pubToken = client . publish ( topicName , message , null , null ) ; pubToken . waitForCompletion ( ) ; log ( "Published" ) ; log ( "Disconnecting" ) ; IMqttToken discToken = client . disconnect ( null , null ) ; discToken . waitForCompletion ( ) ; log ( "Disconnected" ) ; }
publish / send a message to an mqtt server
