Skip to content

Commit

Permalink
Merge branch 'release/0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Calabrese committed Sep 11, 2014
2 parents e04d629 + 42d7300 commit 54338c1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ android:
licenses:
- android-sdk-license-5be876d5
- ".*intel.+"
script: TERM=dumb ./gradlew assembleDebug
deploy:
provider: releases
file: "./app/build/outputs/apk/app-release-unsigned.apk"
file: "./app/build/outputs/apk/app-debug.apk"
skip_cleanup: true
api_key:
secure: Yv7qc91hNpvFZVjnl1fjA53SfH5kXyJPCabR6IIz2SbExDpstxStSQiUZydIgwrwtXtxliG8irhBdQSfYoYrHREbIZBCX0RkY1QxFpI7r3eLwIUW3SDjfvmbU7HwtYqHqG5gpr1qe81PEj5gFi49YsJYODw9WyaYiRqgE3JFUTs=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import com.nightscout.android.R;
import com.nightscout.android.settings.SettingsActivity;

import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.os.BatteryManager;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
Expand All @@ -38,6 +42,8 @@ public class DexcomG4Activity extends Activity {
private TextView mTitleTextView;
private TextView mDumpTextView;
private Button b1;
public static int batLevel = 0;
BatteryReceiver mArrow;


//All I'm really doing here is creating a simple activity to launch and maintain the service
Expand All @@ -62,10 +68,28 @@ public void run() {
mDumpTextView.setTextColor(Color.WHITE);
mDumpTextView.setText("\n" + record.displayTime + "\n" + record.bGValue + "\n" + record.trendArrow + "\n");
}
mArrow = new BatteryReceiver();
IntentFilter mIntentFilter = new IntentFilter();
mIntentFilter.addAction(Intent.ACTION_BATTERY_LOW);
mIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
mIntentFilter.addAction(Intent.ACTION_BATTERY_OKAY);
Intent batteryIntent=registerReceiver(mArrow,mIntentFilter);

mHandler.postDelayed(updateDataView, 30000);
}
};

private class BatteryReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
if (arg1.getAction().equalsIgnoreCase(Intent.ACTION_BATTERY_LOW)
|| arg1.getAction().equalsIgnoreCase(Intent.ACTION_BATTERY_CHANGED)
|| arg1.getAction().equalsIgnoreCase(Intent.ACTION_BATTERY_OKAY)) {
batLevel = arg1.getIntExtra("level", 0);
}
}
}

//Look for and launch the service, display status to user
@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.util.Log;

import com.mongodb.*;
import com.nightscout.android.dexcom.DexcomG4Activity;
import com.nightscout.android.dexcom.EGVRecord;

import org.apache.http.client.ResponseHandler;
Expand All @@ -18,6 +19,7 @@
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import org.json.JSONException;
import org.json.JSONObject;

import java.security.MessageDigest;
Expand Down Expand Up @@ -170,11 +172,32 @@ private void doRESTUploadTo(String baseURI, EGVRecord[] records) {
Log.w(TAG, "Unable to post data to: '" + post.getURI().toString() + "'", e);
}
}

postDeviceStatus(baseURL, httpclient);

} catch (Exception e) {
Log.e(TAG, "Unable to post data", e);
}
}

private void postDeviceStatus(String baseURL, DefaultHttpClient httpclient) throws Exception {
String devicestatusURL = baseURL + "devicestatus";
Log.i(TAG, "devicestatusURL: " + devicestatusURL);

JSONObject json = new JSONObject();
json.put("uploaderBattery", DexcomG4Activity.batLevel);
String jsonString = json.toString();

HttpPost post = new HttpPost(devicestatusURL);
StringEntity se = new StringEntity(jsonString);
post.setEntity(se);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");

ResponseHandler responseHandler = new BasicResponseHandler();
httpclient.execute(post, responseHandler);
}

private void populateV1APIEntry(JSONObject json, EGVRecord record) throws Exception {
Date date = DATE_FORMAT.parse(record.displayTime);
json.put("device", "dexcom");
Expand All @@ -194,7 +217,8 @@ private void populateLegacyAPIEntry(JSONObject json, EGVRecord record) throws Ex
private void doMongoUpload(SharedPreferences prefs, EGVRecord... records) {

String dbURI = prefs.getString("MongoDB URI", null);
String collectionName = prefs.getString("Collection Name", null);
String collectionName = prefs.getString("Collection Name", "entries");
String dsCollectionName = prefs.getString("DeviceStatus Collection Name", "devicestatus");

if (dbURI != null && collectionName != null) {
try {
Expand All @@ -220,6 +244,14 @@ private void doMongoUpload(SharedPreferences prefs, EGVRecord... records) {
testData.put("direction", record.trend);
dexcomData.update(testData, testData, true, false, WriteConcern.UNACKNOWLEDGED);
}

DBCollection dsCollection = db.getCollection(dsCollectionName);
//Uploading devicestatus
BasicDBObject devicestatus = new BasicDBObject();
devicestatus.put("uploaderBattery", DexcomG4Activity.batLevel);
devicestatus.put("created_at", new Date());
dsCollection.insert(devicestatus, WriteConcern.UNACKNOWLEDGED);

client.close();
} catch (Exception e) {
Log.e(TAG, "Unable to upload data to mongo", e);
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
android:title="API Base URL"
android:key="API Base URL"
android:dialogTitle="Enter Base API URL"
android:defaultValue="http://{YOUR-API-SERVER}/api"
android:dialogMessage="This only the base URL, the uploader will automatically append /entries for the POST">
android:defaultValue="yourpassphrase@https://{YOUR-SITE}.azurewebsites.net/api/v1"
android:dialogMessage="This only the base URL, the uploader will automatically append /entries for the POST. API_SECRET on the server should match yourpassphrase in this setting.">
</EditTextPreference>
<SwitchPreference
android:dependency="IUNDERSTAND"
Expand All @@ -43,7 +43,16 @@
android:title="Collection Name"
android:key="Collection Name"
android:dialogTitle="Enter Collection Name"
android:dialogMessage="This is the name of the collection where the CGM data will be stored">
android:dialogMessage="This is the name of the collection where the CGM data will be stored"
android:defaultValue="entries">
</EditTextPreference>
<EditTextPreference
android:dependency="EnableMongoUpload"
android:title="DeviceStatus Collection Name"
android:key="DeviceStatus Collection Name"
android:dialogTitle="Enter DeviceStatus Collection Name"
android:dialogMessage="This is the name of the collection where the battery and other device data will be stored"
android:defaultValue="devicestatus">
</EditTextPreference>
<SwitchPreference
android:title="Wifi Hack"
Expand Down

0 comments on commit 54338c1

Please sign in to comment.