Drafted By: Greg Waehner (Facebook GregWaehner)
Edited By: Jim Sifferle
Last Updated: 18-Feb-2015
This Nightscout Labs is intended to provide “do-it-yourself” (DIY) guidance on how to transition your Android Uploader from MongoDB direct upload to the “REST API” upload method. This guide is written using the Azure interface, but the REST API and it’s instructions work on Heroku too.
As “do-it-yourself,” this is intended for individuals who are
- Comfortable with Azure and MongoLab hosting;
- Willing to accept the increased configuration and maintenance complexity; and
- Willing to accept that the “Support Team” does not support this for the entire community;
- MongoDB upload method will be deprecated over time.
- REST API uses HTTPS which improves privacy by encrypting the data sent from your uploader phone to your website
- REST API works better on Wi-Fi networks where firewalls may block access to MongoDB upload ports. Examples include schools, hotels, and public hotspots.
- Implementing redundancy is easier with the REST API than with Mongo.
Ok, so you are now a believer… how do you do it?
At a high-level, you will
- Configure the Azure website for the API_SECRET “Connection String.” The “API_SECRET” value is a user-defined value that must be at least 12 characters.
- Change the Android Uploader preferences to use REST API Upload rather than Mongo
Step 1: Go to the Configure section of your Azure website in the Management portal.
Step 2: Add the API_SECRET to your Azure website “Connection Strings”
Please note – The original “API_SECRET” LABS information is located here. Originally, the instructions were to place the “API_SECRET” in the “APP SETTINGS.” This is no longer the case — please ensure you use the CONNECTION STRING with “custom” for the 3rd column, as this visually hides the “secret passphrase.” The API_SECRET connection string must be UPPER CASE, and the value must be at least 12 characters long. If this variable is set too short, your Azure site will not start.
Step 3: Configure the Android Uploader to use REST API rather than MongoDB
The original Labs page covering this topic is located here. The following is written without screenshots to ensure backward and forwards compatibility.
- On your “uploader phone,” open the Android Uploader (Nightscout) application.
- Turn OFF the “MongoDB Upload.”
- Turn ON the REST API.
- Choose to enter the REST API URL / API Base URL
- Enter “https://YOUR_API_SECRET_VALUE@YOUR_WEBSITE.azurewebsites.net/api/v1”
- Make sure you enter “https” and not “http”
- YOUR_API_SECRET_VALUE is the at least 12 character value you set for the API_SECRET app setting.
- YOUR_WEBSITE.azurewebsites.net is your Azure website address.
Please note – You CAN NOT use the MongoDB and REST API at the same time for the same site. You can do either MongoDB or REST API, but not both concurrently for the same website.
Step 4: Verify It’s Working
- Restart your Azure website via the management portal to ensure the new API_SECRET value is loaded.
- Close the Nightscout uploader application on your phone, and then “ensure it is closed” by either restarting the phone, or going into “Settings | Apps | Nightscout” and “force close,” or by choosing “recent apps” from the phone home screen and “swipe” to close.
- Now load Nightscout application on your uploader again. It should take a minute to sync.
- If everything works, then you will start seeing “new data” on your Azure website.
If it’s not working….
- If Azure is giving you an error, then your API_SECRET probably isn’t 12+ characters.
- If Azure is working but not current data, then
- Double check that “Use REST API” is on
- Confirm the accuracy of the “API_SECRET_VALUE”
- Confirm https:// rather than http://