M5Stack Nightscout monitor
Copyright (C) 2018, 2019 Martin Lukasek martin@lukasek.cz
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
This software uses some 3rd party libraries:
IniFile by Steve Marple (GNU LGPL v2.1)
ArduinoJson by Benoit BLANCHON (MIT License)
IoT Icon Set by Artur Funk (GPL v3)
Additions to the code:
Peter Leimbach (Nightscout token)
Latest software revisions
What is this good for?
Syntax of M5NS.INI configuration file
Display
Buttons
Battery
Installation and support
Donations - support the project π
The first working ALPHA version.
Speaker is pretty noisy, while GSM/GPRS communication is in progress.
Section [gsm] with key apn is required with your provider APN string. The default is "internet".
[gsm]
apn = internet
The query is repeated every 2 minutes to conserve GPRS data and it also takes some time, so 15 secs would be too fast.
Created project for GSM.
Split of Nightscout read and display code (this should allow simpler user display code update and more different "faces" from users).
New concept of display pages (different display designs, information, faces).
Switch page by short press of the right button.
Power OFF by the right button long press (4 seconds).
Right button works also as power ON after power off by this button.
New page added with large simple info (large BG, clock, delta + arrow and few icons only).
New M5NS.INI key "default_page" added (default 0).
Smaller WiFi symbol (now as blue WiFi icon in 2 sizes for the 2 different Nightscout queries).
Buttons do not work during Nightscout communication (blue WiFi symbol displayed).
Bigger delta value even with COB+IOB values displayed (COB: and IOB: shortened to C: and I: ).
Errors now logged silently (log can be displayed as the last page).
Warning triangle icon added to show that errors are in the log (up to 5 errors - grey, more - yellow). Only last 10 errors can be displayed.
New M5NS.INI key "restart_at_time" added (default no restart) to restart M5Stack regularly at predefined time to reconnect to WiFi access point and clear possible other errors. No startup sound during soft restart, snooze state reapplied, errors cleared.
New M5NS.INI key "restart_at_logged_errors" added (default no restart) to restart M5Stack after predefined amount of errors logged in error log to reconnect to WiFi access point and clear possible other errors. No startup sound during soft restart, snooze state reapplied, errors cleared.
Right button power icon changed to door icon to better express the page change/power off functions.
More silent speaker. Found the way how to switch off adc1 after sound play.
Added token key in M5NS.INI to allow connection to secured Nightscout sites (thanks to Peter Leimbach).
Added keys snd_warning_at_startup and snd_alarm_at_startup to play warning/alarm sound test during startup (1 = play, 0 = do not play).
More WiFi APs possible. Now you can create section [wlan0], [wlan1], up to [wlan9] in M5NS.INI.
Added SD card info for better error handling.
Added empty Nightscout check. No restarts repeat if Nightscout is empty.
Wait for NTP time synchronization.
Added check for http/https in Nightscout URL in M5NS.INI
Increased default warning volume to 50.
Added last 2 weeks revisions to README.
Large DELTA value displayed if no COB/IOB on display.
Sample M5NS.INI file now has default values in mg/dL.
Corrected volume bug, it did not work at all. Now accepts values from M5NI.INI correctly.
Added battery icon. This feature works only on newer M5Stack units. Removed seconds from time to make more place for possibly more icons.
Fixed restart bug if some properties were not defined on Nightscout.
Added button function icons (set M5NS.INI key info_line = 1). This is now default option.
Added loop and basal info (set M5NS.INI key info_line = 2).
Original sensor information available when M5NS.INI key info_line = 0
Small changes to silence background hiss as much as possible.
BG/calibration/unknown entries are now filtered.
Missed reading sound alert added. You can adjust it by snd_no_readings key in M5NS.INI (default 20 minutes).
Added possibility to change warning sound volume by warning_volume key in M5NS.INI (0-100, default=20, 0=silent).
Added possibility to change alarm sound volume by alarm_volume key in M5NS.INI (0-100, default=100, 0=silent).
Reorganized left upper part of display to get space for COB and IOB display.
Added show_COB_IOB key to M5NS.INI. If show_COB_IOB = 1 then carbs and insulin on board are displayed. Set 1 (ON) by default.
COB and IOB are grey if 0 and white if any carbs or IU on board.
Added key show_current_time to M5NS.INI. If show_current_time = 1 (default now) then current clock is displayed instead of last sensor reding time.
Snooze alarm function introduced and placed on the middle button.
New M5NS.INI key snooze_timeout (default 30 min) to specify time for how long should be sound alarm silent after press of the middle button.
New M5NS.INI key alarm_repeat to specify time (default 5 min) when sound alarm shoud repeat if its reason remains.
Corrected bug with alarm sometimes repeating twice.
WiFi symbol moved to the source code. External SD file is no more needed.
Configuration file M5NS.INI handling moved to separate source files.
Larger JSONDocument size for xDrip and possibly other Nightscout upload application compatibility.
A little bit better HTTP error handling and error printing to the M5Stack screen.
When "show_mgdl = 1", then all values in M5NS.INI have to be in mg/dL instead of mmol/L.
Updated device detection for xDrip.
Only one query to Nightscout for minigraph as well as the last value. Faster code execution, less traffic.
Added the main source code M5_NightscoutMon.ino to GitHub. Sorry I forgot in initial commit ;-)
Initial GitHub commit
M5Stack is small development kit based on ESP32. It is in a nice plastic box, equipped with color display, micro SD card slot, 3 buttons, speaker and internal battery. It is great to monitor and display something, so I used it to monitor my daughter's glycemia. It is nice, comfortable and cheap solution.
We use Abbott Freestyle Libre, together with MiaoMiao transmitter. It transmits the glycemia values to her mobile phone (we used to use Spike on iPhone, but you can also use Tomato on iPhone or xDrip, Glimp and more on Android). The daughterβs mobile phone then sends data to the Nightscout, where we (parents) watch it using the web application or a mobile phone (Spike, Nightscout, β¦). We use the small M5Stack monitor with my software to monitor the glycemia during nights in our sleeping room, my wife has one in the kitchen and we take one always on our trips. It has different backlight intensity for night usage and alarms for hypo/hyper glycemia situations.
In short it displays information from Nightscout site and provides visual and sound alarms if needed.
Some people were asking for the software. I am not a professional programmer, I am a hardware engineer, but I work more with tables, numbers and e-mails recent years, so I was a little bit shy about the code. As there is quite a lot of people interested in something that shows current values and makes alarms during nights, I decided to release the code as an Open Source.
If you know what to do with it, just download the code, modify it any way it suits you and use it in M5Stack. If you do not know how to handle the source code, just find someone who can. It is easy, just open it in Arduino IDE, download M5Stack libraries, Arduino JSON library and build it to you M5Stack. M5Stack is in more versions, the Core is just enough. Current price on Aliexpress is about 27.95 USD https://www.aliexpress.com/item/M5Stack-Official-Stock-Offer-ESP32-Basic-Core-Development-Kit-Extensible-Micro-Control-Wifi-BLE-IoT-Prototype/32837164440.html
You will need a microSD card. It has to be formatted to FAT32 format and you have to put at least M5NS.INI file with configuration to the root of the microSD card. It is a good idea to put M5_NightscoutMon.jpg files to the SD card root too. You can replace M5_NightscoutMon.jpg with any 320x240 pixels picture if you want to customize your experience.
You have to update M5NS.INI file to your requirements. As a minimum requirement you will need to update your Nightscout URL and your WiFi SSID and password.
[config]
nightscout = yoursite.herokuapp.com β use your Nightscout site URL
token = security token - token for access secured Nightscout site, if public Nightscout site is used, delete token line and do not use it
bootpic = /M5_NightscoutMon.jpg β boot picture
name = YourName β display name
time_zone = 3600 β the time zone where you live in seconds (3600 is GMT+1, Prague)
dst = 3600 β your daylight saving time offset (3600s is +1 hour)
show_mgdl = 0 β use 0 to display values in mmol/L or 1 for mg/dl
default_page = 0 β page number displayed after startup
show_current_time = 1 β show current time instead of last valid data time
restart_at_time = HH:MM β time in HH:MM format when the device will restart
restart_at_logged_errors = 0 - restart device after particular number of errors in the log (0 = do not restart)
show_COB_IOB = 1 β show COB and IOB, values are grayed out if COB/IOB value is 0
snooze_timeout = 30 - sound snooze time in minutes after press of the middle button
alarm_repeat = 5 - sound repeat interval in minutes (alarm repeats only if alarm/warning conditions are met)
info_line = 1 - 0 = sensor info, 1 = button function icons, 2 = loop info + basal
brightness1 = 50 β the first (default) brightness value
brightness2 = 100 β the second brightness value
brightness3 = 10 β the third brightness value
- following values are in mmol/L or mg/dL depending on the previous setting of "show_mgdl" key value
yellow_low = 4.5 β glycemia values under this value will be displayed in yellow color
yellow_high = 9 β glycemia values over this value will be displayed in yellow color
red_low = 3.9 β glycemia values under this value will be displayed in red color
red_high = 11 β glycemia values over this value will be displayed in red color
snd_warning = 3.7 β softer high beep sound will beep every 5 mins when under this value
snd_alarm = 3.0 β strong alarm will sound every 5 min when under this value
snd_warning_high = 14.0 β softer high beep sound will beep every 5 mins when over this value
snd_alarm_high = 20.0 β strong alarm will sound every 5 min when over this value
snd_no_readings = 20 β softer high beep sound will beep every 5 mins when time in minutes when last data was read is over this value
snd_warning_at_startup = 1 - play test warning sound with its volume during startup (1 = play, 0 = do not play)
snd_alarm_at_startup = 0 - play test alarm sound with its volume during startup (1 = play, 0 = do not play)
warning_volume = 20 - volume of warning sound in range 0-100 (0=no sound, 1=silent, 100=max volume)
alarm_volume = 100 _- volume of alarm sound in range 0-100 (0=no sound, 1=silent, 100=max volume)
[wlan1] β you can connect up to 9 WiFi access point, no need to setup all, one is enough
ssid = ssid1
pass = pass1
[wlan2]
ssid = ssid2
pass = pass2
[wlan3]
...
There are currently 3 display pages, that can be changed by a short press of the right button. The button does not work when the device communicated with Nightscout (small blue WiFi icon is displayed).
Page 0 - default page
What you see on the display is a matter of your M5NS.INI and Nightscout configuration. By default you will see current time, date and user name from config file in upper left corner. You will see IOB (Insulin On Board) an COB (Carbs On Board) values bellow the name. Right from the IOB/COB value is current BG delta (difference from the last reading, trend where the BG is going). Box with time difference from last valid data from Nighscout is displayed in upper right corner. Delay of 5 mins is OK and the box has grey color, 5-15 mins is warning and the box will have white background, more than 15 mins without a valid data is error and the box background will be red. There is also possibility to set sound warning on data delay in M5NS.INI.
Glycemia (BG) value and its direction are bellow the basic information. There is a mini graph created from 10 last BG values right of the glycemia value. The mini graph shows only values in range 3-12 mmol/L (48-216 mg/dL) and values bellow/above this will be displayed on mini graph as the min/max values.
There are also icons in upper side of display. Plug or battery icon displays battery status (on newer devices only). Red clock indicated silent "snooze" mode activated. Grey or yellow (more than 5 errors) shows that there are errors in error log (last page). Blue WiFi icon in 2 sizes (2 different queries) indicated that MStack is downloading data from Nightscout.
Last line contains icons for buttons or data source or Loop information (depending on M5NS.INI key "info_line").
Page 1 - simple page with large BG value
Long distance visible page with large BG value and larger clock. Top line contains current time, icons, delta value a BG direction arrow.
Bottom info line is the same as on page 0.
Error Log page
Displays last 10 record errors and total number of errors record since last restart. Occasional communication errors, such as "timeout" or "connection refused" are normal and happen sometimes due to WiFi and internet connection and Nightscout site status. If you have a lot of errors every few minutes, consider to move your M5Stack to a different place or extend WiFi signal.
The left button changes the backlight in the 3 steps defined in M5NS.INI file.
The middle button snoozes M5Stack for defined time to prevent alarm or warning sound. You can "snooze" it even before the alarm is activated. Snooze active is indicated by red clock icon in status icon area.
Shor press of the right button switches display pages. Long press (4 seconds) puts M5Stack to the sleep as it is a little bit tricky to double click standard red power button.
Battery icon feature works only on newer M5Stack units. Here are my battery measurements and battery icon statuses:
internal battery total 43 minutes
plug icon = full charge or plugged in ... 1 min
gray full battery icon ... 13 min
white 2/3 battery icon ... 20 min
yellow 1/3 battery icon ... 8 min
red empty battery icon ... 1 min
extended battery total 7:49 hrs:min
plug icon = full charge or plugged in ... 53 min
gray full battery icon ... 2 hrs 59 min
white 2/3 battery icon ... 1 hr 55 min
yellow 1/3 battery icon ... 1 hr 48 min
red empty battery icon ... 14 min
Installation can be done by download or git clone the code to the Arduino IDE environment. You have to download ESP32 board and M5Stack libraries, Arduino JSON library and build it to you M5Stack.
Another easier possibility is to download latest M5Burner release. It is Windows executable with binary M5Stack firmware included. Just unzip it, start the M5Burner.exe, choose COM port where your M5Stack is connected and burn the firmware. Simple. Remember to add you microSD card with M5NS.INI configuration file.
There is a Facebook group M5STACK NIGHTSCOUT where you can get support and installation guides in several languages prepared by members of the M5Stack Nightscout community. Please check the Files section first and search the group before asking questions. A lot of questions have been answered already. Big thanks to Patrick Sonnerat, Didier FrΓ©tignΓ©, Peter Leimbach and more...
If you find my project useful, I will appreciate if you donate me few bucks for further development or buy me a glass of beer or wine π·.
I also collect and repair vintage 8-bit computers, so if you have some really old computer, I could give it a new home and care π.