text
stringlengths
1
93.6k
sensor_exception_codes = {
SENSOR_EXCEPTIONS.SENSOR_OK: SENSOR_EXCEPTIONS.SENSOR_OK_STR,
SENSOR_EXCEPTIONS.SENSOR_INIT: SENSOR_EXCEPTIONS.SENSOR_INIT_STR,
SENSOR_EXCEPTIONS.SENSOR_CAL_NEEDED: SENSOR_EXCEPTIONS.SENSOR_CAL_NEEDED_STR,
SENSOR_EXCEPTIONS.SENSOR_ERROR: SENSOR_EXCEPTIONS.SENSOR_ERROR_STR,
SENSOR_EXCEPTIONS.SENSOR_CAL_ERROR: SENSOR_EXCEPTIONS.SENSOR_CAL_ERROR_STR,
SENSOR_EXCEPTIONS.SENSOR_CHANGE_SENSOR: SENSOR_EXCEPTIONS.SENSOR_CHANGE_SENSOR_STR,
SENSOR_EXCEPTIONS.SENSOR_END_OF_LIFE: SENSOR_EXCEPTIONS.SENSOR_END_OF_LIFE_STR,
SENSOR_EXCEPTIONS.SENSOR_NOT_READY: SENSOR_EXCEPTIONS.SENSOR_NOT_READY_STR,
SENSOR_EXCEPTIONS.SENSOR_READING_HIGH: SENSOR_EXCEPTIONS.SENSOR_READING_HIGH_STR,
SENSOR_EXCEPTIONS.SENSOR_READING_LOW: SENSOR_EXCEPTIONS.SENSOR_READING_LOW_STR,
SENSOR_EXCEPTIONS.SENSOR_CAL_PENDING: SENSOR_EXCEPTIONS.SENSOR_CAL_PENDING_STR,
SENSOR_EXCEPTIONS.SENSOR_CHANGE_CAL_ERROR: SENSOR_EXCEPTIONS.SENSOR_CHANGE_CAL_ERROR_STR,
SENSOR_EXCEPTIONS.SENSOR_TIME_UNKNOWN: SENSOR_EXCEPTIONS.SENSOR_TIME_UNKNOWN_STR,
SENSOR_EXCEPTIONS.SENSOR_LOST: SENSOR_EXCEPTIONS.SENSOR_LOST_STR
}
is_connected = False
lastBolusTime = None
cycleTimer = None
cycleCount = 0
blynk = None
nightscout = None
CONFIG_FILE = "/etc/ddguard.conf"
def to_int(string):
try:
i = int(string)
except:
i = 0
return i
#########################################################
#
# Function: read_config()
# Description: Read parameters from config file
#
#########################################################
def read_config(cfilename):
# Parameters from global config file
config = ConfigParser()
config.read(cfilename)
#TODO: check if file exists
try:
# Read Blynk parameters
read_config.blynk_server = config.get('blynk', 'server').split("#")[0].strip('"').strip("'").strip()
read_config.blynk_token = config.get('blynk', 'token').split("#")[0].strip('"').strip("'").strip()
read_config.blynk_heartbeat = to_int(config.get('blynk', 'heartbeat').split("#")[0].strip('"').strip("'"))
except ConfigParser.NoOptionError as NoSectionError:
syslog.syslog(syslog.LOG_ERR, "ERROR - Needed blynk option not found in config file")
return False
try:
# Read Nightscout parameters
read_config.nightscout_server = config.get('nightscout', 'server').split("#")[0].strip('"').strip("'").strip()
read_config.nightscout_api_secret = config.get('nightscout', 'api_secret').split("#")[0].strip('"').strip("'").strip()
except ConfigParser.NoOptionError as NoSectionError:
syslog.syslog(syslog.LOG_ERR, "ERROR - Needed nightscout option not found in config file")
return False
try:
# Read BGL alert parameters
read_config.bgl_low_val = to_int(config.get('bgl', 'bgl_low').split("#")[0].strip('"').strip("'"))
read_config.bgl_pre_low_val = to_int(config.get('bgl', 'bgl_pre_low').split("#")[0].strip('"').strip("'"))
read_config.bgl_pre_high_val = to_int(config.get('bgl', 'bgl_pre_high').split("#")[0].strip('"').strip("'"))
read_config.bgl_high_val = to_int(config.get('bgl', 'bgl_high').split("#")[0].strip('"').strip("'"))
except ConfigParser.NoOptionError as NoSectionError:
syslog.syslog(syslog.LOG_ERR, "ERROR - Needed bgl option not found in config file")
return False
# Disable BGL parameters if not specified in config
if read_config.bgl_pre_high_val == 0:
read_config.bgl_pre_high_val = 1000
if read_config.bgl_high_val == 0:
read_config.bgl_high_val = 1000
print ("Blynk server: %s" % read_config.blynk_server)
print ("Blynk token: %s" % read_config.blynk_token)
print ("Blynk heartbeat: %d\n" % read_config.blynk_heartbeat)
print ("Nightscout server: %s" % read_config.nightscout_server)
print ("Nightscout api_secret: %s\n" % read_config.nightscout_api_secret)
print ("BGL low: %d" % read_config.bgl_low_val)
print ("BGL pre low: %d" % read_config.bgl_pre_low_val)
print ("BGL pre high: %d" % read_config.bgl_pre_high_val)
print ("BGL high: %d\n" % read_config.bgl_high_val)
return True
#########################################################
#
# Function: on_sigterm()
# Description: signal handler for the TERM and INT signal
#