Setting up a Nightscout server on Raspberry PI 4 could be done directly on the OS or via docker containers. This page describes the containerized way. For an installation directly on the OS; follow one of the Linux installation guides.
This how-to includes a clean installation of a Raspberry Pi, and targets users with an interest in containerization with a basic knowledge on system administration. No expert knowledge is required to get started, however managing your own service come with a responsibility for security and data safekeeping. https://nightscout.github.io/nightscout/new_user/#security-and-safekeeping
It is crucial to install the 64-bit OS to support the use of MongoDB. The official get-started guide can be used https://www.raspberrypi.com/documentation/computers/getting-started.html to get familiar with Raspberry Pi ecosystem.
Use the Raspberry Pi Imager to install the 64 Bit OS. Can be downloaded from https://www.raspberrypi.com/software/
- Open the Image manager
- Click the
Choose OS
- Open the list
Raspberry Pi OS (Others)
- Select:
Raspberry Pi OS Lite (64-bit)
- Choose Storage, and select your SD card. *(Prefer to use an SSD)
- Write the image to the SD card
- Insert the SD card into you Pi and start it up
Open the command line terminal to the Raspberry Pi, and make sure your OS is up-to-date
More information https://docs.docker.com/engine/install/debian/#install-docker-engine
$ sudo apt update
$ sudo apt upgrade
Install docker
$ sudo apt install docker.io
$ sudo usermod -aG docker pi
$ logout
Test if the docker installation succeeded.
$ groups
> Should include the docker group for the user
$ docker run hello-world
> Hello from Docker!
Portainer will allow you to manage the containers via a web application For more information on installing docker Portainer see https://pimylifeup.com/raspberry-pi-portainer/
$ sudo docker pull portainer/portainer-ce:latest
Test if Portainer is running in a browser; navigate Pi's IP address on port 9000 http://PI_IO_ADDRESS:9000/
This section is only needed if you want to build your own image. Starting from Nightscout 14.2.6 an image docker image Raspberry Pi is released on docker hub. https://hub.docker.com/layers/nightscout/cgm-remote-monitor/14.2.6/images/sha256-063c64dba9b5916070a52909b03d980725cca99f4ca018b533e64c065a4ce2e5?context=explore
Previously, Nightscout did not publish an image suitable for Raspberry Pi. If you want to build your own image, continue else go the next chapter.
For this how-to we can build our image using Portainer. See: https://docs.portainer.io/user/docker/images/build#method-1-using-the-portainer-web-editor
- Open Portainer in the browser.
- Create an image using the web editor
- Name the image
- Make sure you update to the latest release and update the tag
14.2.6
to the most recent version https://github.com/nightscout/cgm-remote-monitor/tags
#
# CGM Remote Monitor Dockerfile
# Inspired by https://github.com/dhermanns/rpi-nightscout
#
# Pull base image.
FROM node:14-alpine
# Install Git and NPM
RUN apk update && apk add -y software-properties-common python g++ make git
# Upgrade
RUN apk upgrade -y
# Create node user
RUN mkdir -p /opt/app
WORKDIR /opt/app
RUN chown -R node:node /opt/app
USER node
# Install the application, and remove unused folders, to limit the image size
RUN git clone https://github.com/nightscout/cgm-remote-monitor.git . && \
git checkout tags/14.2.6 && \
npm install && \
npm run postinstall && \
npm run env && \
rm -rf node_modules && \
rm -rf tmp && \
rm -rf .git
EXPOSE 1337
CMD ["node", "lib/server/server.js"]
To spin up a set of docker images that together creates the Nightscout web site.
See: https://docs.portainer.io/user/docker/stacks/add#option-1-web-editor
- Make sure the
service > nightscout > image
is matching with the image above - Update the
YOUR_PUBLIC_HOST_URL
- Update the environment variable
YOUR_API_SECRET
(The rest is done in the next chapter)
Inspired by https://github.com/nightscout/cgm-remote-monitor/blob/master/docker-compose.yml
version: '3.4'
services:
nightscout:
image: nightscout/cgm-remote-monitor:14.2.6
environment:
TZ: Europe/Berlin
MONGO_CONNECTION: mongodb://mongo:27017/mycgmic
API_SECRET: YOUR_API_SECRET
BG_HIGH: 8
BG_LOW: 3.9
BG_TARGET_TOP: 7
BG_TARGET_BOTTOM: 3.9
AUTH_DEFAULT_ROLES: readable devicestatus-upload
ENABLE: careportal boluscalc food bwp cage sage iage iob cob basal ar2 rawbg pushover bgi pump openaps cors"
SHOW_FORECAST: openaps
SHOW_PLUGINS: careportal openaps pump iob sage cage
CUSTOM_TITTLE: Nightscout
DISPLAY_UNITS: mmol
ports:
- "1337:1337"
depends_on:
- mongo
labels:
- 'traefik.enable=true'
# Change the below Host from `localhost` to be the web address where Nightscout is running.
# Also change the email address in the `traefik` service below.
- 'traefik.http.routers.nightscout.rule=Host(`YOUR_PUBLIC_HOST_URL`)'
- 'traefik.http.routers.nightscout.entrypoints=websecure'
- 'traefik.http.routers.nightscout.tls.certresolver=le'
volumes:
- /home/pi/docker/rpi-nightscout:/var/opt/ssl/:ro
restart: always
mongo:
image: mongo:4.4.9
volumes:
- ./data:/data/db
ports:
- "27017:27017"
- "27018:27018"
- "27019:27019"
- "28017:28017"
restart: always
traefik:
image: traefik:latest
container_name: 'traefik2'
command:
- '--providers.docker=true'
- '--providers.docker.exposedbydefault=false'
- '--entrypoints.web.address=:80'
- '--entrypoints.web.http.redirections.entrypoint.to=websecure'
- '--entrypoints.websecure.address=:443'
- "--certificatesresolvers.le.acme.httpchallenge=true"
- "--certificatesresolvers.le.acme.httpchallenge.entrypoint=web"
- '--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json'
# Change the below to match your email address
- '--certificatesresolvers.le.acme.email=YOUR_EMAIL'
ports:
- '443:443'
- '80:80'
volumes:
- './letsencrypt:/letsencrypt'
- '/var/run/docker.sock:/var/run/docker.sock:ro'
restart: always
Replace within the Stack your personal settings
- YOUR_API_SECRET
- YOUR_EMAIL
- YOUR_PUBLIC_HOST_URL
To test, go to Nightscout URL and test if it is working!
Edit your stack and set the environment variables in the section services > nightscout > environment
If you migrate from Heroku, check the setting. https://devcenter.heroku.com/articles/config-vars#using-the-heroku-dashboard
Else check the documentation for environment variables. https://github.com/nightscout/cgm-remote-monitor#environment
Historical data can be migrated, there are 3 options; Accept the loss of your old data, backfill with your uploaders (see next chapter), or migrate the data fast from the old MongoDB to the new MongoDB with export and import.
Migrate MongoDB with data tools. https://www.mongodb.com/try/download/database-tools
- Install de data tools
- Check your MongoDB settings in Heroku settings the
MONGODB_URI
it contains a value similar to:mongodb+srv://USER:SECRET@cluster0.ilbqf.mongodb.net/mycgmic?retryWrites=true&w=majority
- Export the current DB with, update the URI and output file (Replace USER & SECRET)
cd "C:\Program Files\MongoDB\Tools\100\bin"
$ mongodump --uri mongodb+srv://USER:SECRET@cluster0.ilbqf.mongodb.net/mycgmic --out="C:\mongodump"
- Restore the DB, update the destination IP and dump the file (User the Pi's IP)
cd "C:\Program Files\MongoDB\Tools\100\bin"
mongorestore --host=YOUR_HOST --port=27017 "C:\mongodump"
- * When current data needs the be replace, use the parameter
--drop
cd "C:\Program Files\MongoDB\Tools\100\bin"
mongorestore --host=YOUR_HOST --port=27017 --drop "C:\mongodump"
Make sure other tools that upload are configured with a new URL. See: https://nightscout.github.io/uploader/setup/ and https://nightscout.github.io/nightscout/downloaders/
- Android APS https://androidaps.readthedocs.io/en/latest/Installing-AndroidAPS/Nightscout.html?highlight=upload#androidaps-settings
- If you have Android APS as a follower, update the follower too
- xDrip https://xdrip.readthedocs.io/en/latest/use/cloud/#nightscout-sync-rest-api
Backfill (optional) If you migrated the database or did not care about the historical data, this step could be skipped. This process might be slow and should be done per uploader,
- Android APS uploads the treatments
NS Client > ... (option menu) > Full synchronization
- xDrip to upload the BG values, use settings
Cloud Upload > Extra Options > Back-fill data
Thank you for this guide. I have a running nightscout instance on my pi4 :). I am not able to upload to it from AAPS, I am getting ERROR io.socket.engineio.client.EngineIOException:xhr poll error every 5 seconds. do you have any suggestions on where I went wrong?
Thank you.