Nightscout in Fly.io


Too complicated? Not what you’re looking for?

Consider a hosted Nightscout service! Check for easier solutions here.


Fly.io

Fly.io

Fly.io proposes a simple migration wizard from Heroku and you can create your new Nightscout site in Fly.io.

Pros:

  • Nightscout fits in the free tier

  • Easy to migrate an existing site from Heroku

Cons:

  • Maintaining your site requires the use of command line instructions, not very intuitive

  • Fly.io stores variables as secrets: you cannot read them

  • Relying on the MongoDB Atlas database



Step 0: Create a database


Make sure you create one before starting your Nightscout web app creation with Fly.io.

Come back here when you have a MONGODB_URI connection string.


Copy the connection string from your previous platform: edit the variables and look for MONGODB_URI.

If you don’t see MONGODB_URI but see MONGO_CONNECTION (NOT MONGO_COLLECTION): use its value.



Step 1: Create a fly.io account

Sign up to Fly.io.


You will need to add credit card information to get Nightscout running.
Whenever requested, add one to prove you’re a real person:

../../../_images/FlyIOA1.png ../../../_images/FlyM10.png

Nightscout should run for free within the allowances. If you get billed, please report costs here to have the documentation updated.



Step 2: Open the web terminal

a) In a new browser tab, open the terminal. Sign-in with the account you created above, if requested.
If you just closed the terminal, you might need to wait some time (20 minutes) before you can open a new session (the message below appears).

../../../_images/FlyIO07.png

b) Click on the image with code (Launch Web CLI).

../../../_images/FlyIO06.png

c) Wait until the web terminal is ready.

../../../_images/FlyIO08.png

d) A command prompt will open. You will either type the few required commands there or copy/paste them from the documentation.

../../../_images/FlyIO09.png



Step 3: Prepare the Nightscout project

Type (or copy and paste) the following command in the terminal:

curl https://nightscout.github.io/_static/flyboot.sh | bash

../../../_images/FlyIO01.png

b) Navigate to the Nightscout code directory copied locally by typing:

cd cgm-remote-monitor

../../../_images/FlyIO02.png

c) Deploy your site with Fly.io.
Type the following command:

flyctl launch

../../../_images/FlyIO13.png

To the question Would you like to copy its configuration to the new app? answer Y (yes).

To the question: App Name (leave blank to use an auto-generated name): answer with the name you want for your new Nightscout site (lowercase letters, numbers, - but no space or special characters.

../../../_images/FlyIO14.png

If you see an Error message, the name is either unauthorized or already taken.

Go back to c) and try another one.

../../../_images/FlyIO15.png

If you see Configuration is valid, you can continue.

The name you chose will be your Nightscout site name (followed by fly.dev).

../../../_images/FlyIO16.png



Step 5: Set your Nightscout secrets

a) Compile the information below.

File all necessary fields, click on the Validate button at the bottom of the form, if no error is seen you will have all variables displayed in the text box at the bottom, click on the Copy All button.


Mandatory variables

These three variables below must have a value.

MONGODB_URI

The MongoDB Connection String to connect to your MongoDB cluster. If you don’t have this from your Mongo database, please re-read installation instructions at Nightscout database before continuing


API_SECRET


A passphrase that must be at least 12 characters long. Avoid special characters, which can cause problems in some cases

DISPLAY_UNITS



Preferred BG units for the site: mg/dl or mmol/l (or just mmol)


Customizations

Leave default values if you don’t want to change them

CUSTOM_TITLE


The display name for the Nightscout site. Appears in the upper left of the main view. Often set to the name of the CGM wearer

THEME



Default setting for new browser views for the color theme of the CGM graph. (default colors or colorblindfriendly)

ENABLE


Plugins to enable for your site. Must be a space-delimited lower-case list. Include the word bridge here if you are receiving data from the Dexcom Share service

SHOW_PLUGINS


Default setting for whether or not these plugins are checked (active) by default not merely enabled. Include plugins here as in the ENABLE line; space-separated and lower-case

TIME_FORMAT



Default setting for new browser views for the time mode. (12 or 24)

NIGHT_MODE



Default setting for new browser views for whether Night Mode should be enabled. (on or off)

BOLUS_RENDER_OVER


U value over which the bolus values are rendered on the chart if the x U and Over option is selected


Dexcom Share

If you want Nightscout to import directly from Dexcom Share

BRIDGE_USER_NAME


Your Dexcom account username to receive CGM data from the Dexcom Share service. Also make sure to include bridge in your ENABLE line.

BRIDGE_PASSWORD


Your Dexcom account password to receive CGM data from the Dexcom Share service. Also make sure to include bridge in your ENABLE line

BRIDGE_SERVER



If you are bridging from the Dexcom Share service and are anywhere outside the US change this to EU. (US or EU)


Alarms

You can customize alarms or leave them to default values

ALARM_TYPES



simple and/or predictv. Simple alarms trigger when BG crosses the various thresholds set below. Predict alarms use a formula that forecasts where the BG is going based on its trend. You will not get warnings when crossing the BG thresholds set below when using the predict type

ALARM_URGENT_HIGH


Urgent High BG threshold triggers the ALARM_URGENT_HIGH alarm. Set in mg/dL or mmol/L as set in DISPLAY_UNITS variable

ALARM_URGENT_LOW


Urgent Low BG threshold triggers the ALARM_URGENT_LOW alarm. Set in mg/dL or mmol/L as set in DISPLAY_UNITS variable

ALARM_HIGH


High BG threshold triggers the ALARM_HIGH alarm. Set in mg/dL or mmol/L as set in DISPLAY_UNITS variable

ALARM_LOW


Low BG threshold triggers the ALARM_LOW alarm. Set in mg/dL or mmol/L as set in DISPLAY_UNITS variable

ALARM_TIMEAGO_URGENT


Default setting for new browser views for the number of minutes since the last CGM reading to trigger an ALARM_TIMEAGO_URGENT alarm

ALARM_TIMEAGO_WARN


Default setting for new browser views for the number of minutes since the last CGM reading to trigger an ALARM_TIMEAGO_WARN alarm

Now click on the Validate button below

If errors show up below, please correct them and click Validate again.

Click the button Validate above.






Save this!

What you just copied is the secrets configuration used to build your site.
This is important information to maintain your Nightscout.
Make sure you keep a copy of it somewhere safe.


b) Click on the Copy all button above.

Tip

Now do not copy anything else!
If you do another copy/paste after you clicked the Copy All button, click again now before pasting the configuration!


c) Then, in the terminal, paste what you copied above, hit Enter

../../../_images/FlyIO21.png

Wait until setting secrets complete.

../../../_images/FlyIO22.png



Step 6: Deploy Nightscout

a) In the terminal type:

flyctl deploy

You app will deploy. It will take time (about 10 minutes).

../../../_images/FlyIO17.png

Do not interrupt the process.


When deploy completes you should see your new Nightscout site name.

../../../_images/FlyIO18.png

b) Last but not least: make sure to downscale your app with the following command:

flyctl scale count 1

../../../_images/FlyIO19.png

Enter y to confirm.

../../../_images/FlyIO20.png

c) Exit the terminal typing exit or pressing Ctrl D ( D with a Mac).

Keep in mind you’ll need some time to reopen it if you need to (as explained in step 2 above).
Close the browser tab.


d) You can now see your site in the fly.io dashboard at https://fly.io/dashboard click on the application (not the builder):

../../../_images/FlyIOA2.png

e) Inside your app you should see that it is running and has a clickable hostname.

../../../_images/FlyIO05.png

New Nightscout Setup


a) Your Nightscout site should open and direct you to a new profile creation.

../../../_images/NewNS50.png

b) Setup your Time zone and eventually all other fields. Do not leave any fields empty. If you don’t know which value to use, just use the default value. You can change these values later at any time.

../../../_images/NewNS44.png

c) Browse down to Authentication status and click Authenticate. Enter your API secret. Click Update.

../../../_images/NewNS45.png

d) Click Save.

../../../_images/NewNS46.png

e) If the following pop-up shows up click OK, and check status (upper right of the window).

../../../_images/NewNS47.png

f) If you need to modify your profile after this, authenticate with the lock icon (top right of the page): enter your API secret. Then click on the hamburger menu and select Profile Editor.

../../../_images/NewNS43.png

Privacy warning

Anyone with access to the URL of your Nightscout site, can view your BG and run reports of your data. It it strongly recommended that you enable security to your site once you’re done with the setup


g) Dexcom Share users should see data flowing in after some minutes. xDrip+ users (including Medtronic CareLink followers) should setup the uploader as shown here. xDrip4iOS users here. AAPS and Loop: consult the relative documentation.

../../../_images/NewNS48.png

You have completed a new Nightscout site creation. You can continue here now.

The following section provides more information that you might not need to use now.




Editing Config Vars in Fly.io

Open a web terminal

In a new browser tab, sign-in with your fly.io account, then open a web terminal.
(See here the detailed sequence).


Secrets

Fly.io variables are Secrets, you cannot see the values of your secret variables.
You can only delete them and set them: you cannot edit them.
Please make sure you write them down somewhere!


If you want to create a new secret or modify an existing one you need to use the flyctl secrets set command.

In the command line below replace yourappname by the app name (usually your Nightscout site name: yourappname.fly.dev). For example if you want to set your Nightscout site vertical scale to linear:

flyctl secrets set SCALE_Y="linear" -a yourappname

If your SCALE_Y secret was already set to linear you will see the following message:

Error No change detected to secrets. Skipping release.

When changing a secret, the app will automatically redeploy. You will see this sequence (it will take a few minutes):

Release v1 created
==> Monitoring deployment

 1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]
--> v1 deployed successfully

Hint

If you know you will change several secrets, add --stage to all the lines except the last one.

flyctl secrets set SCALE_Y="linear" -a yourappname --stage
flyctl secrets set SCALE_Y="linear" -a yourappname --stage

flyctl secrets set SCALE_Y="linear" -a yourappname

This will avoid your app to redeploy every time.