diff --git a/bin/ns-upload-entries.sh b/bin/ns-upload-entries.sh index e63bf234e..43be261a0 100755 --- a/bin/ns-upload-entries.sh +++ b/bin/ns-upload-entries.sh @@ -28,7 +28,7 @@ fi # requires API_SECRET and NIGHTSCOUT_HOST to be set in calling environment (i.e. in crontab) ( -curl -m 30 -s -X POST --data-binary @${ENTRIES} \ +curl --compressed -m 30 -s -X POST --data-binary @${ENTRIES} \ ${API_SECRET_HEADER} -H "content-type: application/json" \ ${REST_ENDPOINT} ) && ( test -n "${OUTPUT}" && touch ${OUTPUT} ; logger "Uploaded ${ENTRIES} to ${NIGHTSCOUT_HOST}" ) || logger "Unable to upload to ${NIGHTSCOUT_HOST}" diff --git a/bin/ns-upload.sh b/bin/ns-upload.sh index b70adb734..010292359 100755 --- a/bin/ns-upload.sh +++ b/bin/ns-upload.sh @@ -38,13 +38,13 @@ fi if [[ "${API_SECRET,,}" =~ "token=" ]]; then REST_ENDPOINT="${REST_ENDPOINT}?${API_SECRET}" (test "$ENTRIES" != "-" && cat $ENTRIES || cat )| ( - curl -m 30 -s -X POST --data-binary @- \ + curl --compressed -m 30 -s -X POST --data-binary @- \ -H "content-type: application/json" \ $REST_ENDPOINT ) && ( test -n "$OUTPUT" && touch $OUTPUT ; logger "Uploaded $ENTRIES to $NIGHTSCOUT_HOST" ) || ( logger "Unable to upload to $NIGHTSCOUT_HOST"; exit 2 ) else (test "$ENTRIES" != "-" && cat $ENTRIES || cat )| ( - curl -m 30 -s -X POST --data-binary @- \ + curl --compressed -m 30 -s -X POST --data-binary @- \ -H "API-SECRET: $API_SECRET" \ -H "content-type: application/json" \ $REST_ENDPOINT diff --git a/bin/openaps-install.sh b/bin/openaps-install.sh index 9395ab992..0e77d85d8 100755 --- a/bin/openaps-install.sh +++ b/bin/openaps-install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -BRANCH=${1:-master} +BRANCH=${1:-dev} read -p "Enter your rig's new hostname (this will be your rig's "name" in the future, so make sure to write it down): " -r myrighostname=$REPLY echo $myrighostname > /etc/hostname @@ -46,16 +46,9 @@ if cat /etc/os-release | grep 'PRETTY_NAME="Debian GNU/Linux 8 (jessie)"' &> /de echo "Jubilinux 0.2.0, based on Debian Jessie, is no longer receiving security or software updates!" fi -#Workaround for Jubilinux to install nodejs/npm from nodesource -if getent passwd edison &> /dev/null; then - #Use nodesource setup script to add nodesource repository to sources.list.d - curl -sL https://deb.nodesource.com/setup_8.x | bash - -fi - -#dpkg -P nodejs nodejs-dev # TODO: remove the `-o Acquire::ForceIPv4=true` once Debian's mirrors work reliably over IPv6 apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true -y dist-upgrade && apt-get -o Acquire::ForceIPv4=true -y autoremove -apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true install -y sudo strace tcpdump screen acpid vim python-pip locate ntpdate ntp +apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true install -y sudo strace tcpdump screen acpid vim locate ntpdate ntp #check if edison user exists before trying to add it to groups grep "PermitRootLogin yes" /etc/ssh/sshd_config || echo "PermitRootLogin yes" >>/etc/ssh/sshd_config @@ -73,7 +66,7 @@ sed -i "s/daily/hourly/g" /etc/logrotate.conf sed -i "s/#compress/compress/g" /etc/logrotate.conf curl -s https://raw.githubusercontent.com/openaps/oref0/$BRANCH/bin/openaps-packages.sh | bash - -mkdir -p ~/src; cd ~/src && ls -d oref0 && (cd oref0 && git checkout $BRANCH && git pull) || git clone https://github.com/openaps/oref0.git +mkdir -p ~/src; cd ~/src && ls -d oref0 && (cd oref0 && git checkout $BRANCH && git pull) || git clone https://github.com/openaps/oref0.git -b $BRANCH echo "Press Enter to run oref0-setup with the current release ($BRANCH branch) of oref0," read -p "or press ctrl-c to cancel. " -r cd && ~/src/oref0/bin/oref0-setup.sh diff --git a/bin/openaps-packages.sh b/bin/openaps-packages.sh index 401b783e7..0fdb15242 100755 --- a/bin/openaps-packages.sh +++ b/bin/openaps-packages.sh @@ -10,7 +10,16 @@ echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4 apt-get install -y sudo sudo apt-get update && sudo apt-get -y upgrade -sudo apt-get install -y git python python-dev software-properties-common python-numpy python-pip watchdog strace tcpdump screen acpid vim locate lm-sensors || die "Couldn't install packages" +## Debian Bullseye (Raspberry Pi OS 64bit, etc) is python3 by default and does not support python2-pip. +if ! cat /etc/os-release | grep bullseye >& /dev/null; then + sudo apt-get install -y git python python-dev software-properties-common python-numpy python-pip watchdog strace tcpdump screen acpid vim locate lm-sensors || die "Couldn't install packages" +else + # Bullseye based OS. Get PIP2 from pypa and pip-install python packages rather than using the py3 ones from apt + # Also, install python-is-python2, to override the distro default of linking python to python3 + sudo apt-get install -y git python-is-python2 python-dev-is-python2 software-properties-common watchdog strace tcpdump screen acpid vim locate lm-sensors || die "Couldn't install packages" + curl https://bootstrap.pypa.io/pip/2.7/get-pip.py | python2 || die "Couldn't install pip" + python2 -m pip install numpy || die "Couldn't pip install numpy" +fi # We require jq >= 1.5 for --slurpfile for merging preferences. Debian Jessie ships with 1.4. if cat /etc/os-release | grep 'PRETTY_NAME="Debian GNU/Linux 8 (jessie)"' &> /dev/null; then @@ -21,18 +30,20 @@ else sudo apt-get -y install jq || die "Couldn't install jq" fi -# Install/upgrade to latest version of node (v10) using apt if neither node 8 nor node 10+ LTS are installed -if ! nodejs --version | grep -e 'v8\.' -e 'v1[02468]\.' &> /dev/null ; then - if getent passwd edison; then - # Only on the Edison, use nodesource setup script to add nodesource repository to sources.list.d, then install nodejs (npm is a part of the package) - curl -sL https://deb.nodesource.com/setup_8.x | bash - - sudo apt-get install -y nodejs=8.* || die "Couldn't install nodejs" - else - sudo apt-get install -y nodejs npm || die "Couldn't install nodejs and npm" - fi +# Install node using n if there is not an installed version of node >=8,<=19 +# Edge case: This is not likely to work as expected if there *is* a version of node installed, but it is outside of the specified version constraints +if ! node --version | grep -q -e 'v[89]\.' -e 'v1[[:digit:]]\.'; then + echo "Installing node via n..." # For context why we don't install using apt or nvm, see https://github.com/openaps/oref0/pull/1419 + curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n + # Install the latest compatible version of node + sudo bash n current + # Delete the local n binary used to boostrap the install + rm n + # Install n globally + sudo npm install -g n - # Upgrade npm to the latest version using its self-updater - sudo npm install npm@latest -g || die "Couldn't update npm" + # Upgrade to the latest supported version of npm for the current node version + sudo npm upgrade -g npm|| die "Couldn't update npm" ## You may also need development tools to build native addons: ## sudo apt-get install gcc g++ make diff --git a/bin/oref0-cron-every-minute.sh b/bin/oref0-cron-every-minute.sh index f84f79e52..843d5d801 100755 --- a/bin/oref0-cron-every-minute.sh +++ b/bin/oref0-cron-every-minute.sh @@ -128,9 +128,9 @@ if [[ ! -z "$BT_PEB" || ! -z "$BT_MAC" ]]; then fi fi -if [[ ! -z "$PUSHOVER_TOKEN" && ! -z "$PUSHOVER_USER" ]]; then +#if [[ ! -z "$PUSHOVER_TOKEN" && ! -z "$PUSHOVER_USER" ]]; then #oref0-pushover $PUSHOVER_TOKEN $PUSHOVER_USER 2>&1 >> /var/log/openaps/pushover.log & -fi +#fi # if disk has less than 10MB free, delete something and logrotate cd /var/log/openaps/ && df . | awk '($4 < 10000) {print $4}' | while read line; do diff --git a/bin/oref0-get-ns-entries.js b/bin/oref0-get-ns-entries.js index 6e855fec8..4932aac31 100755 --- a/bin/oref0-get-ns-entries.js +++ b/bin/oref0-get-ns-entries.js @@ -180,12 +180,14 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca headers["If-Modified-Since"] = lastDate.toISOString(); } + headers["User-Agent"] = 'openaps'; var uri = nsurl + '/api/v1/entries/sgv.json?count=' + records + tokenAuth; var options = { uri: uri , json: true , timeout: 90000 , headers: headers + , gzip : true }; request(options, function(error, res, data) { diff --git a/bin/oref0-pump-loop.sh b/bin/oref0-pump-loop.sh index 3ff08fa50..a3ec33b00 100755 --- a/bin/oref0-pump-loop.sh +++ b/bin/oref0-pump-loop.sh @@ -169,8 +169,13 @@ function fail { refresh_after_bolus_or_enact echo "Incomplete oref0-pump-loop (pump suspended) at $(date)" else - pumphistory_daily_refresh - maybe_mmtune + # wait upto45s and try preflight; if successful, refresh pumphistory, else mmtune + wait_for_silence $upto45s + if try_return preflight; then + pumphistory_daily_refresh + else + maybe_mmtune + fi echo "If pump and rig are close enough, this error usually self-resolves. Stand by for the next loop." echo Unsuccessful oref0-pump-loop at $(date) fi diff --git a/bin/oref0-pushover.sh b/bin/oref0-pushover.sh index d31859870..5820b39c6 100755 --- a/bin/oref0-pushover.sh +++ b/bin/oref0-pushover.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env bash source $(dirname $0)/oref0-bash-common-functions.sh || (echo "ERROR: Failed to run oref0-bash-common-functions.sh. Is oref0 correctly installed?"; exit 1) @@ -87,7 +87,7 @@ fi CURL_AUTH='-H api-secret:'${API_SECRET} fi - if snooze=$(curl -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="carbsReq") | select(.date>'$(date +%s -d "10 minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then + if snooze=$(curl --compressed -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="carbsReq") | select(.date>'$(date +%s -d "10 minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then #echo $snooze #echo date -Is -d @$snooze; echo touch -d $(date -Is -d @$snooze) monitor/pushover-sent @@ -107,7 +107,7 @@ elif [[ $ONLYFOR =~ "insulin" ]] && ! cat $FILE | egrep "maxBolus" > /dev/null; elif file_is_recent monitor/pushover-sent $SNOOZE; then echo -n "Last pushover sent less than $SNOOZE minutes ago. " else - curl -s -F token=$TOKEN -F user=$USER $SOUND_OPTION -F priority=$PRIORITY $PRIORITY_OPTIONS -F "message=$(jq -c "{bg, tick, carbsReq, insulinReq, reason}|del(.[] | nulls)" $FILE) - $(hostname)" https://api.pushover.net/1/messages.json | jq .status| grep 1 >/dev/null && touch monitor/pushover-sent && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"carbsReq"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "carbsReq pushover sent." + curl ---compressed s -F token=$TOKEN -F user=$USER $SOUND_OPTION -F priority=$PRIORITY $PRIORITY_OPTIONS -F "message=$(jq -c "{bg, tick, carbsReq, insulinReq, reason}|del(.[] | nulls)" $FILE) - $(hostname)" https://api.pushover.net/1/messages.json | jq .status| grep 1 >/dev/null && touch monitor/pushover-sent && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"carbsReq"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "carbsReq pushover sent." echo fi @@ -152,7 +152,7 @@ else touch $GLANCES && touch -r $GLANCES -d '-60 mins' $GLANCES fi - if snooze=$(curl -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="glance") | select(.date>'$(date +%s -d "$glanceDelay minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then + if snooze=$(curl --compressed -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="glance") | select(.date>'$(date +%s -d "$glanceDelay minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then #echo $snooze #echo date -Is -d @$snooze; echo touch -d $(date -Is -d @$snooze) $GLANCES @@ -195,7 +195,7 @@ else subtext="$carbsMsg${rate}U/h ${duration}m" # echo "pushover glance text=${text} subtext=${subtext} delta=${delta} title=${title} battery percent=${battery}" - curl -s -F "token=$TOKEN" -F "user=$USER" -F "text=${text}" -F "subtext=${subtext}" -F "count=$bgNow" -F "percent=${battery}" -F "title=${title}" https://api.pushover.net/1/glances.json | jq .status| grep 1 >/dev/null && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"glance"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "Glance uploaded and snoozed" + curl --compressed -s -F "token=$TOKEN" -F "user=$USER" -F "text=${text}" -F "subtext=${subtext}" -F "count=$bgNow" -F "percent=${battery}" -F "title=${title}" https://api.pushover.net/1/glances.json | jq .status| grep 1 >/dev/null && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"glance"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "Glance uploaded and snoozed" touch $GLANCES else echo -n "Pushover glance last updated less than $glanceDelay minutes ago @ " @@ -223,7 +223,7 @@ if ! [ -z "$MAKER_KEY" ] && [[ "$MAKER_KEY" != "null" ]] && cat $FILE | egrep "a echo $values > $ifttt - curl --request POST \ + curl --compressed --request POST \ --header 'Content-Type: application/json' \ -d @$ifttt \ https://maker.ifttt.com/trigger/carbs-required/with/key/${key} && touch monitor/ifttt-sent diff --git a/bin/oref0-setup.sh b/bin/oref0-setup.sh index 47eea3f38..1c098cd8c 100755 --- a/bin/oref0-setup.sh +++ b/bin/oref0-setup.sh @@ -285,21 +285,18 @@ function copy_go_binaries () { function move_mmtune () { request_stop_local_binary Go-mmtune - if [ -f /usr/local/bin/mmtune ]; then - mv /usr/local/bin/mmtune /usr/local/bin/Go-mmtune || die "Couldn't move mmtune to Go-mmtune" + if [ -f /root/go/bin/mmtune ]; then + ln -s /root/go/bin/mmtune /usr/local/bin/Go-mmtune else - die "Couldn't move_mmtune() because /usr/local/bin/mmtune exists" + echo "Couldn't move_mmtune()" fi } -function install_or_upgrade_nodejs () { - # install/upgrade to latest node 8 if neither node 8 nor node 10+ LTS are installed - if ! nodejs --version | grep -e 'v8\.' -e 'v1[02468]\.' >/dev/null; then - echo Installing node 8 - # Use nodesource setup script to add nodesource repository to sources.list.d - sudo bash -c "curl -sL https://deb.nodesource.com/setup_8.x | bash -" || die "Couldn't setup node 8" - # Install nodejs and npm from nodesource - sudo apt-get install -y nodejs=8.* || die "Couldn't install nodejs" +function check_nodejs_timing () { + # Redundant check that node is installed + # It is installed as part of openaps-packages.sh + if ! node --version | grep -q -e 'v[89]\.' -e 'v1[[:digit:]]\.'; then + die "No version of node (>=8,<=19) was found, which is an unexpected error (node installation should have been handled by previous installation steps)" fi # Check that the nodejs you have installed is not broken. In particular, we're @@ -314,17 +311,39 @@ function install_or_upgrade_nodejs () { echo "Your installed nodejs ($(node --version)) is very slow to start (took ${NODE_EXECUTION_TIME}s)" echo "This is a known problem with certain versions of Raspberry Pi OS." - if prompt_yn "Install a new nodejs version using nvm?" Y; then - echo "Installing nvm and using it to replace the system-provided nodejs" - - # Download nvm - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash - # Run nvm, adding its aliases to this shell - source ~/.nvm/nvm.sh - # Use nvm to install nodejs - nvm install 10.24.1 - # Symlink node into /usr/local/bin, where it will shadow /usr/bin/node - ln -s ~/.nvm/versions/node/v10.24.1/bin/node /usr/local/bin/node + if prompt_yn "Confirm installation of replacement nodejs/npm versions?" Y; then + echo "Attempting to uninstall current nodejs/npm versions (apt-get remove)" + sudo apt-get -y remove nodejs npm + if [[ -n $NVM_DIR ]]; then + echo "Removing nvm ($NVM_DIR)..." + echo "(you may wish to optionally remove the nvm-related lines that still exist in ~/.bashrc; this script won't do it for you)" + rm -rf "$NVM_DIR" + fi + + # Check that there node and npm are no longer available. If they are, warn the user. + nodePath=$(command -v node) + npmPath=$(command -v npm) + if [[ -e "$nodePath" ]]; then + echo "Note: A 'node' binary (located at '$nodePath') still exists and may interfere with the new installation of node" + fi + if [[ -e "$npmPath" ]]; then + echo "Note: A 'npm' binary (located at '$npmPath') still exists and may interfere with the new installation of npm" + fi + + if [[ ! $(command -v n) ]]; then + echo "n already exists on the system, using it to install a new version of node..." + sudo n current + else + echo "Installing n and using it to replace the system-provided nodejs" + echo "Installing node via n..." + curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n + # Install the latest version of node that is supported on this platform + sudo bash n current + # Delete the local n binary used to boostrap the install + rm n + # Install n globally + sudo npm install -g n + fi NEW_NODE_EXECUTION_TIME="$(\time --format %e node -e 'true' 2>&1)" echo "New nodejs took ${NEW_NODE_EXECUTION_TIME}s to start" @@ -730,7 +749,7 @@ if prompt_yn "" N; then echo Running apt-get autoclean sudo apt-get autoclean - install_or_upgrade_nodejs + check_nodejs_timing # Attempting to remove git to make install --nogit by default for existing users echo Removing any existing git in $directory/.git @@ -796,11 +815,11 @@ if prompt_yn "" N; then echo Checking oref0 installation cd $HOME/src/oref0 if git branch | grep "* master"; then - npm list -g --depth=0 | egrep oref0@0.6.[0] || (echo Installing latest oref0 package && sudo npm install -g oref0) + npm list -g --depth=0 | egrep oref0@0.7.[0] || (echo Installing latest oref0 package && sudo npm install -g oref0) elif [[ ${npm_option,,} == "force" ]]; then echo Forcing install of latest oref0 from $HOME/src/oref0/ && cd $HOME/src/oref0/ && npm run global-install else - npm list -g --depth=0 | egrep oref0@0.6.[1-9] || (echo Installing latest oref0 from $HOME/src/oref0/ && cd $HOME/src/oref0/ && npm run global-install) + npm list -g --depth=0 | egrep oref0@0.7.[1-9] || (echo Installing latest oref0 from $HOME/src/oref0/ && cd $HOME/src/oref0/ && npm run global-install) fi cd $directory || die "Can't cd $directory" @@ -1191,7 +1210,7 @@ if prompt_yn "" N; then # Install Golang mkdir -p $HOME/go source $HOME/.bash_profile - golangversion=1.12.5 + golangversion=1.19.1 if go version | grep go${golangversion}.; then echo Go already installed else @@ -1200,6 +1219,8 @@ if prompt_yn "" N; then echo "Installing Golang..." if uname -m | grep armv; then cd /tmp && wget -c https://storage.googleapis.com/golang/go${golangversion}.linux-armv6l.tar.gz && tar -C /usr/local -xzvf /tmp/go${golangversion}.linux-armv6l.tar.gz + elif uname -m | grep aarch64; then + cd /tmp && wget -c https://storage.googleapis.com/golang/go${golangversion}.linux-arm64.tar.gz && tar -C /usr/local -xzvf /tmp/go${golangversion}.linux-arm64.tar.gz elif uname -m | grep i686; then cd /tmp && wget -c https://dl.google.com/go/go${golangversion}.linux-386.tar.gz && tar -C /usr/local -xzvf /tmp/go${golangversion}.linux-386.tar.gz fi @@ -1213,7 +1234,7 @@ if prompt_yn "" N; then sed --in-place '/.*GOPATH*/d' $HOME/.bash_profile echo 'GOPATH=$HOME/go' >> $HOME/.bash_profile echo 'export GOPATH' >> $HOME/.bash_profile - echo 'PATH=$PATH:/usr/local/go/bin:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bash_profile + echo 'PATH=$PATH:/usr/local/go/bin:$GOROOT/bin:$GOPATH/bin:/root/go/bin/' >> $HOME/.bash_profile sed --in-place '/.*export PATH*/d' $HOME/.bash_profile echo 'export PATH' >> $HOME/.bash_profile fi @@ -1246,8 +1267,14 @@ if prompt_yn "" N; then esac #Build Go binaries - go get -u -v -tags "$radiotags" github.com/ecc1/medtronic/... || die "Couldn't go get medtronic" - ln -sf $HOME/go/src/github.com/ecc1/medtronic/cmd/pumphistory/openaps.jq $directory/ || die "Couldn't softlink openaps.jq" + #go get -u -v -tags "$radiotags" github.com/ecc1/medtronic/... || die "Couldn't go get medtronic" + go install -v -tags "$radiotags" github.com/ecc1/medtronic/cmd/...@latest || die "Couldn't go get medtronic" + #ln -sf /root/go/pkg/mod/github.com/ecc1/medtronic@v0.0.0-20210712211734-b8431dc5211b/cmd/pumphistory/openaps.jq $directory/ || die "Couldn't softlink openaps.jq" + if [[ -f $directory/openaps.jq ]]; then + ls -la $directory/openaps.jq + else + cd $directory && wget https://raw.githubusercontent.com/ecc1/medtronic/master/cmd/pumphistory/openaps.jq || die "Couldn't wget openaps.jq" + fi else #TODO: write validate_ttyport and support non-SPI ports die "Unsupported ttyport. Exiting." diff --git a/bin/oref0_nightscout_check.py b/bin/oref0_nightscout_check.py index 90b6edcc2..6d640da4d 100755 --- a/bin/oref0_nightscout_check.py +++ b/bin/oref0_nightscout_check.py @@ -92,7 +92,11 @@ def startup_checks(args): def check_permissions(): global token_dict - pg=token_dict['permissionGroups'][0] + pg=[] + + for perm_group in token_dict['permissionGroups']: + pg.extend(perm_group) + if pg==["*"]: # admin role logging.warning("The use of the admin role for token based authentication is not recommended, see https://openaps.readthedocs.io/en/master/docs/walkthrough/phase-1/nightscout-setup.md#switching-from-api_secret-to-token-based-authentication-for-your-rig") else: @@ -100,13 +104,14 @@ def check_permissions(): for perm in ["api:treatments:read", "api:treatments:create", "api:treatments:read", "api:treatments:create", "api:devicestatus:read", "api:devicestatus:create"]: logging.debug("Checking %s" % perm) if perm not in pg: - missing.append(perm) + missing.append(perm) if len(missing)>0: - logging.error("The following permissions are missing in Nightscout: %s" % missing) - logging.error("Please follow instructions at https://openaps.readthedocs.io/en/master/docs/walkthrough/phase-1/nightscout-setup.md#switching-from-api_secret-to-token-based-authentication-for-your-rig") - sys.exit(1) - logging.info("All permissions in Nightscout are ok") + logging.error("The following permissions are missing in Nightscout: %s" % missing) + logging.error("Please follow instructions at https://openaps.readthedocs.io/en/master/docs/walkthrough/phase-1/nightscout-setup.md#switching-from-api_secret-to-token-based-authentication-for-your-rig") + sys.exit(1) + + logging.info("All permissions in Nightscout are ok") if __name__ == '__main__': diff --git a/lib/determine-basal/determine-basal.js b/lib/determine-basal/determine-basal.js index a599fc8c6..1a1a286cc 100644 --- a/lib/determine-basal/determine-basal.js +++ b/lib/determine-basal/determine-basal.js @@ -40,7 +40,7 @@ function convert_bg(value, profile) { if (profile.out_units === "mmol/L") { - return round(value / 18, 1).toFixed(1); + return round(value / 18, 1); } else { @@ -474,7 +474,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ // use autosens-adjusted sens to counteract autosens meal insulin dosing adjustments so that // autotuned CR is still in effect even when basals and ISF are being adjusted by TT or autosens // this avoids overdosing insulin for large meals when low temp targets are active - csf = sens / profile.carb_ratio; + var csf = sens / profile.carb_ratio; console.error("profile.sens:",profile.sens,"sens:",sens,"CSF:",csf); var maxCarbAbsorptionRate = 30; // g/h; maximum rate to assume carbs will absorb if no CI observed @@ -695,7 +695,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ } // set eventualBG based on COB or UAM predBGs - rT.eventualBG = eventualBG; + rT.eventualBG = eventualBG; // for FreeAPS-X needs to be in mg/dL } console.error("UAM Impact:",uci,"mg/dL per 5m; UAM Duration:",UAMduration,"hours"); @@ -808,12 +808,12 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ rT.ISF=convert_bg(sens, profile); rT.CR=round(profile.carb_ratio, 2); rT.target_bg=convert_bg(target_bg, profile); - rT.reason="COB: " + rT.COB + ", Dev: " + rT.deviation + ", BGI: " + rT.BGI+ ", ISF: " + rT.ISF + ", CR: " + rT.CR + ", minPredBG " + convert_bg(minPredBG, profile) + ", minGuardBG " + convert_bg(minGuardBG, profile) + ", IOBpredBG " + convert_bg(lastIOBpredBG, profile); + rT.reason="COB: " + rT.COB + ", Dev: " + rT.deviation + ", BGI: " + rT.BGI+ ", ISF: " + rT.ISF + ", CR: " + rT.CR + ", minPredBG: " + convert_bg(minPredBG, profile) + ", minGuardBG: " + convert_bg(minGuardBG, profile) + ", IOBpredBG: " + convert_bg(lastIOBpredBG, profile); if (lastCOBpredBG > 0) { - rT.reason += ", COBpredBG " + convert_bg(lastCOBpredBG, profile); + rT.reason += ", COBpredBG: " + convert_bg(lastCOBpredBG, profile); } if (lastUAMpredBG > 0) { - rT.reason += ", UAMpredBG " + convert_bg(lastUAMpredBG, profile) + rT.reason += ", UAMpredBG: " + convert_bg(lastUAMpredBG, profile) } rT.reason += "; "; @@ -894,7 +894,7 @@ var maxDelta_bg_threshold; var carbsReq = (bgUndershoot - zeroTempEffect) / csf - COBforCarbsReq; zeroTempEffect = round(zeroTempEffect); carbsReq = round(carbsReq); - console.error("naive_eventualBG:",naive_eventualBG,"bgUndershoot:",bgUndershoot,"zeroTempDuration:",zeroTempDuration,"zeroTempEffect:",zeroTempEffect,"carbsReq:",carbsReq); + console.error("naive_eventualBG: " + convert_bg(naive_eventualBG,profile) + ", bgUndershoot: " + convert_bg(bgUndershoot,profile) + ", zeroTempDuration: " + zeroTempDuration + ", zeroTempEffect: " + zeroTempEffect +", carbsReq: " + carbsReq); if ( meal_data.reason == "Could not parse clock data" ) { console.error("carbsReq unknown: Could not parse clock data"); } else if ( carbsReq >= profile.carbsReqThreshold && minutesAboveThreshold <= 45 ) { @@ -910,7 +910,7 @@ var maxDelta_bg_threshold; rT.reason += " and minDelta " + convert_bg(minDelta, profile) + " > " + "expectedDelta " + convert_bg(expectedDelta, profile) + "; "; // predictive low glucose suspend mode: BG is / is projected to be < threshold } else if ( bg < threshold || minGuardBG < threshold ) { - rT.reason += "minGuardBG " + convert_bg(minGuardBG, profile) + "<" + convert_bg(threshold, profile); + rT.reason += "minGuardBG: " + convert_bg(minGuardBG, profile) + "<" + convert_bg(threshold, profile); bgUndershoot = target_bg - minGuardBG; var worstCaseInsulinReq = bgUndershoot / sens; var durationReq = round(60*worstCaseInsulinReq / profile.current_basal); @@ -1138,7 +1138,7 @@ var maxDelta_bg_threshold; var nextBolusMins = round(SMBInterval-lastBolusAge,0); var nextBolusSeconds = round((SMBInterval - lastBolusAge) * 60, 0) % 60; //console.error(naive_eventualBG, insulinReq, worstCaseInsulinReq, durationReq); - console.error("naive_eventualBG",naive_eventualBG+",",durationReq+"m "+smbLowTempReq+"U/h temp needed; last bolus",lastBolusAge+"m ago; maxBolus: "+maxBolus); + console.error("naive_eventualBG " + convert_bg(naive_eventualBG,profile) +", " + durationReq + "m " + smbLowTempReq + "U/h temp needed; last bolus " + lastBolusAge + "m ago; maxBolus: "+maxBolus); if (lastBolusAge > SMBInterval) { if (microBolus > 0) { diff --git a/package.json b/package.json index c7cbcb33b..bffeac98a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oref0", - "version": "0.7.0", + "version": "0.7.1", "description": "openaps oref0 reference implementation of the reference design", "scripts": { "test": "make test",