Code: Select all
username/feeds/topic/get
In iOS I can use this and got an iPhone app to work ok.
Code: Select all
- (void)newMessage:(MQTTSession *)session
data:(NSData *)data
onTopic:(NSString *)topic
qos:(MQTTQosLevel)qos
retained:(BOOL)retained
mid:(unsigned int)mid {
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"topic: %@", topic);
NSLog(@"data:%@", dataString);
if ([topic isEqualToString:self.temperature]){
T = [dataString intValue];
NSLog(@"T:%d", T);}
Code: Select all
import org.eclipse.paho.android.service.MqttAndroidClient
import org.eclipse.paho.client.mqttv3.*
on GITHUB I found this but don't know how to integrate it.
Code: Select all
@Override
public void onReceive(Context context, Intent intent) {
Bundle data = intent.getExtras();
String handleFromIntent = data
.getString(MqttServiceConstants.CALLBACK_CLIENT_HANDLE);
if ((handleFromIntent == null)
|| (!handleFromIntent.equals(clientHandle))) {
return;
}
String action = data.getString(MqttServiceConstants.CALLBACK_ACTION);
if (MqttServiceConstants.CONNECT_ACTION.equals(action)) {
connectAction(data);
}
else if (MqttServiceConstants.CONNECT_EXTENDED_ACTION.equals(action)){
connectExtendedAction(data);
}
else if (MqttServiceConstants.MESSAGE_ARRIVED_ACTION.equals(action)) {
messageArrivedAction(data);
}
else if (MqttServiceConstants.SUBSCRIBE_ACTION.equals(action)) {
subscribeAction(data);
}
else if (MqttServiceConstants.UNSUBSCRIBE_ACTION.equals(action)) {
unSubscribeAction(data);
}
else if (MqttServiceConstants.SEND_ACTION.equals(action)) {
sendAction(data);
}
else if (MqttServiceConstants.MESSAGE_DELIVERED_ACTION.equals(action)) {
messageDeliveredAction(data);
}
else if (MqttServiceConstants.ON_CONNECTION_LOST_ACTION
.equals(action)) {
connectionLostAction(data);
}
else if (MqttServiceConstants.DISCONNECT_ACTION.equals(action)) {
disconnected(data);
}
else if (MqttServiceConstants.TRACE_ACTION.equals(action)) {
traceAction(data);
}else{
mqttService.traceError(MqttService.TAG, "Callback action doesn't exist.");
}
}
I am just starting out with attempting Android Studio and could use all the help I can get. Thanks