Skip to content

Commit

Permalink
-Added crude exception handling for malformed MQTT endpoints
Browse files Browse the repository at this point in the history
-Updated topics to support old json style download as well as new protobuf style
  • Loading branch information
ktind committed Sep 23, 2014
1 parent fcb5f2b commit b0d7a0c
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .idea/libraries/acra_4_5_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/gson_2_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/guava_14_0_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/mongo_java_driver_2_12_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/org_eclipse_paho_client_mqttv3_1_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/play_services_wearable_5_0_77.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/protobuf_java_2_5_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/support_annotations_20_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/support_v13_20_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/support_v4_20_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/wearable_1_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void run() {
mqttMgr.initConnect(url);
Log.d(TAG, "Subscribe start");
// mqttMgr.subscribe("/entries/sgv", "/uploader");
mqttMgr.subscribe("/entries/sgv","/protobuf/test2");
mqttMgr.subscribe("/entries/sgv","/downloads/protobuf");
Log.d(TAG,"Connect ended");
}
}).start();
Expand Down Expand Up @@ -127,7 +127,7 @@ public void onMessage(String topic, MqttMessage msg) {
setLastDownloadObject(ddo);
onDownload(ddo);
}
if (topic.equals("/protobuf/test2")){
if (topic.equals("/downloads/protobuf")){
try {
SGV.ProposedCookieMonsterG4Download protoBufDownload=SGV.ProposedCookieMonsterG4Download.parseFrom(msg.getPayload());
Log.d("XXX", "SGV Download status: "+protoBufDownload.getDownloadStatus().name());
Expand All @@ -149,6 +149,8 @@ public void onMessage(String topic, MqttMessage msg) {
.setEgvRecords(egvRecords)
.setRemoteDevice(false)
.setDeviceName("dexcom")
.setDeviceBattery(protoBufDownload.getReceiverBattery())
.setUploaderBattery(protoBufDownload.getUploaderBattery())
.setUnit(GlucoseUnit.values()[protoBufDownload.getUnits().getNumber()])
.setDeviceID("device_1")
.setLastReadingDate(egvRecords.get(egvRecords.size()-1).getDate())
Expand Down
9 changes: 3 additions & 6 deletions mobile/src/main/java/com/ktind/cgm/bgscout/mqtt/MQTTMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ public void connect(String url, String lwt) {
Log.e(TAG, "User and/or password is null. Please verify arguments to the constructor");
return;
}
// setupNetworkNotifications();
// mClient=null;
stats.addConnect();
setupOpts(lwt);
// Save the URL for later re-connections
Expand All @@ -149,12 +147,13 @@ public void connect(String url, String lwt) {
mClient = new MqttClient(url, mDeviceId, mDataStore);
mClient.connect(mOpts);
StaticAlertMessages.removeMessage(MQTTDISCONNECT);
// NotifHelper.clearMessage(context,"Disconnected from MQTT");
// connected=true;
setNextKeepAlive();
state=State.CONNECTED;
} catch (MqttException e) {
Log.e(TAG, "Error while connecting: ", e);
} catch (IllegalArgumentException e) {
// TODO: here to catch malformed endpoints. Need to add more robust handling later
Log.e(TAG, "Error while connecting: ", e);
}
}

Expand Down Expand Up @@ -305,8 +304,6 @@ public void connectionLost(Throwable throwable) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RemoteCGM "+deviceIDStr);
wl.acquire();
// connected=false;
// if (isOnline())
reconnectDelayed();
wl.release();
} else {
Expand Down

0 comments on commit b0d7a0c

Please sign in to comment.