text
stringlengths
1
93.6k
#
# The DD-Guard gateway module periodically receives real time data from the
# Medtronic Minimed 670G insulin pump and uploads it to the cloud service
#
# Dependencies:
#
# DD-Guard uses the Python driver by paazan for the "Contour Next Link 2.4"
# radio bridge to the Minimed 670G to download real time data from the pump.
# https://github.com/pazaan/decoding-contour-next-link
#
# For the cloud connection and app communication the official Blynk Python
# library is used.
# https://github.com/blynkkk/lib-python
#
# Author:
#
# Ondrej Wisniewski (ondrej.wisniewski *at* gmail.com)
#
# Changelog:
#
# 23/09/2019 - Initial public release
# 13/10/2019 - Add handling of parameters from configuration file
# 24/10/2019 - Add handling of BGL status codes
# 24/10/2019 - Add handling of display colors according to limits
# 02/11/2019 - Run timer function as asynchronous thread
# 07/11/2019 - Add missing sensor exception codes
# 24/11/2019 - Integrate Nightscout uploader
# 03/12/2019 - Adapt to modified library names
# 03/12/2019 - Make Blynk uploader optional
# 11/02/2020 - Add Blynk virtual pin for active insulin
# 03/03/2020 - Improved robustness of CNL2.4 driver
# 14/04/2020 - Adapt to new data format from CNL driver
# 15/04/2020 - Add more status data to blynk uploader
# 28/06/2020 - Syntax updates for Python3
# 09/11/2020 - Replace Blynk timer with Python timer,
# Account for Pump Time drift
#
# TODO:
# - Upload missed data when the pump returns into range
# - Add some notification mechanism for alarms e.g. Telegram or Pushover message
# - Upload data to Tidepool
#
# Copyright 2019-2020, Ondrej Wisniewski
#
# This file is part of the DD-Guard project.
#
# DD-Guard 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 crelay. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
import blynklib
import signal
import syslog
import sys
import time
import threading
if sys.version_info[0] < 3:
from ConfigParser import ConfigParser
else:
from configparser import ConfigParser
import datetime
import cnl24driverlib
import nightscoutlib
from sensor_codes import SENSOR_EXCEPTIONS
VERSION = "0.8"
UPDATE_INTERVAL = 300
RETRY_INTERVAL = 180
RETRY_DELAY = 5
MAX_RETRIES_AT_FAILURE = 3
# virtual pin definitions
VPIN_SENSOR = 1
VPIN_BATTERY = 2
VPIN_UNITS = 3
VPIN_ARROWS = 4
VPIN_STATUS = 5
VPIN_ACTINS = 6
VPIN_LASTBOLUS = 7
# color definitions
BLYNK_WHITE = "#F0F0F0"
BLYNK_GREEN = "#23C48E"
BLYNK_BLUE = "#04C0F8"
BLYNK_YELLOW = "#ED9D00"
BLYNK_RED = "#D3435C"
BLYNK_DARK_BLUE = "#5F7CD8"