Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save techbelle/8f65b95a8436e5c85524611ed2f3dee5 to your computer and use it in GitHub Desktop.

Select an option

Save techbelle/8f65b95a8436e5c85524611ed2f3dee5 to your computer and use it in GitHub Desktop.
howto.md

SetUp Nightscout with MongoDB Atlas, xDrip+, and Google App Engine

This document describes making Google App Engine hosted nightscout application, with MongoDB Atlas and xDrip+.

Google App Engine

  1. Navigate to https://cloud.google.com
  2. Go to App Engine and create your first project. Choose the name of your project wisely, this will also be your URL to access Nightscout for yourself.
  3. Select your appengine configuration. Standard runtime, usCentral, node.js (note: us-central1 is where free tier is!)
  4. Open the terminal on your computer. If you dont know where this is, do a search for "Terminal" and open that application.
  5. Install gcloud command sdk, hit enter many times to accept all the defaults
  6. Run gcloud init to configure account, project, and default zone
  7. gcloud config set compute/region us-central1 (to ensure you're on free tier)

MongoDB Atlas Set Up

  1. Navigate to https://cloud.mongodb.com
  2. After creating your account, set up your first cluster, being sure to select GCP Free tier, M0 instance size. Note the default is an M30.
  3. After the cluster is created, create your first user by clicking "Database Access" in the left nav menu. You'll want to create a user with readWriteAnyDatabase, and note the password.
  4. Next, go to "Network Access" in the left nav menu. Enter the value of 0.0.0.0/0
  5. On your clusters page, click the connnect button, then "Connect Your Application" and copy your mongodb+srv connection string.

Nightscout Application Set Up

  1. Clone the nightscout web monitor to your laptop using git clone https://github.com/nightscout/cgm-remote-monitor.git
  2. Open the package.json file and modify it slightly. If you search through this short document, you'll see this entry: postinstall all you need to do is change this word, and only this word, to gcp-build
  3. Save the file and close it
  4. Go to my gist for app.yaml here https://gist.github.com/techbelle/81ad2814cf193ea6921db3fe5df94f28
  5. Copy it onto your laptop via copy paste
  6. Modify the items in the file between the < > symbols. Specifically, this will be your mongodb connection string, projectname, and API Secret.
  • The MongoDB connection string is the one from your atlas deployment.
  • The BASE_URL will contain your App Engine project name, the one I said to choose wisely.
  • The API secret is the one that goes with your xDrip+ application, and will allow your app to communicate with your mobile phone. It's a number and letter combination you completely make up. This should be lengthy, and you'll need to hand type it into your phone later for xDrip configuration.

Start Nightscout Web App

  1. Back in the terminal, run gcloud app deploy
  2. Check all your configuration shown. The path, source, Target URL etc should all be correct. Target URL should match what you put into the app.yaml for the BASE_URL file. If it doesn't match, it won't work.
  3. Hit enter
  4. You should see some messages about uploading files to Google Cloud Storage, followed by Updating Service. This will take a few minutes.
  5. When that's done, you'll want to run gcloud app browse or open your appspot URL in a web browser.
  6. This will open a new window with your app running in the cloud!
  7. In the top right, there's a little icon that looks like 3 lines. Click that. This will open a settings menu. Near the bottom there's an item called Authenticate. Click that. It asks here for your API secret from the app.yaml file.

xDrip Set Up and Configuration

  1. Navigate to https://github.com/NightscoutFoundation/xDrip from your Android mobile phone
  2. Take a picture of the barcode and it will install the xDrip+ app
  3. In the left navigation menu select Settings
  4. Select Cloud Upload
  5. Click Nightscout Sync then Enabled should be ON
  6. Fill out your Base URL in this format: https://apisecret@projectname.appspot.com/api/v1/ where API secret is the value from your app.yaml file, the project name is your project name from google app engine.
  7. Exit menu
  8. You should now see the main UI of xDrip+. In the middle it has a button that says Start Source Setup Wizard. Click that.
  9. You will now enable your CGM transmitter to send data. Do not do this step unless you have already installed your CGM with sensor needle on yourself. You will need your transmitter ID.
@rconn1000
Copy link

Sorry, I am new to this game. All seemed to be going well until the line "Go to my gist for app.yaml". What does this mean and how do I do it?

@techbelle
Copy link
Author

Hi there! Sorry, I should have linked this directly. https://gist.github.com/techbelle/81ad2814cf193ea6921db3fe5df94f28 is where you need to go. You'll need to have an app.yaml file for the application to work successfully. Let me know if you have further questions!

@alexsheyko
Copy link

2.1. Open the package.json file and modify
"node": "^10.15.2 || ^8.15.1",
to
"node": "^10",

@alexsheyko
Copy link

When gcloud app deploy error:

Step #0 - "fetcher": Access to bucket staging.PROJECT.appspot.com denied. You must grant Storage Object Viewer permission to _GCP_ID_@cloudbuild.gserviceaccount.com.

need in IAM add role Cloud Storage: Viewer for GCP_ID@cloudbuild.gserviceaccount.com

@Colonietas
Copy link

I´m on START NIGHTSCOUT WEB APP and I dont know what I have to do on the first step. Any help please?

@ulagrezlak
Copy link

1- Clone the nightscout web monitor to your laptop using git clone https://github.com/nightscout/cgm-remote-monitor.git -- where to copy and how ,I am using Windows10 ? and when and how to run this script ?

2- Modify the app.yaml file and store in google sdk folder ,then run it in gcloud sdk shell ,getting this error

Beginning deployment of service [default]...
Created .gcloudignore file. See gcloud topic gcloudignore for details.
ERROR: gcloud crashed (OSError): [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'E:\google\google-cloud-sdk\platform\gsutil\third_party\funcsigs\docs\index.rst'

why ? how to fix it ?

@ulagrezlak
Copy link

you never mention .jason file where and how to deploy it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment