Skip to content

Commit 02af7ed

Browse files
committed
Merge branch 'dev' into offline-xdrip
Conflicts: bin/oref0-setup.sh
2 parents 993e067 + d45140a commit 02af7ed

File tree

9 files changed

+118
-45
lines changed

9 files changed

+118
-45
lines changed

bin/oref0-bluetoothup.sh

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,37 @@ if [ "$DEBUG" != "" ]; then
2323
fi
2424

2525
# start bluetoothd if bluetoothd is not running
26+
# Added a bunch of if is_debian_jessie checks as stretch seems to behave better here.
27+
2628
if ! ( ps -fC bluetoothd >/dev/null ) ; then
27-
echo bluetoothd not running! Starting bluetoothd...
28-
sudo $EXECUTABLE 2>&1 | tee -a /var/log/openaps/bluetoothd.log &
29+
if is_debian_jessie ; then
30+
echo bluetoothd not running! Starting bluetoothd.
31+
sudo $EXECUTABLE 2>&1 | tee -a /var/log/openaps/bluetoothd.log &
32+
else
33+
echo bluetoothd not running! Starting bluetoothd via systemctl.
34+
sudo systemctl bluetooth start
35+
fi
2936
fi
3037

3138
if is_edison && ! ( hciconfig -a hci${adapter} | grep -q "PSCAN" ) ; then
32-
echo Bluetooth PSCAN not enabled! Restarting bluetoothd...
33-
sudo killall bluetoothd
34-
sudo $EXECUTABLE 2>&1 | tee -a /var/log/openaps/bluetoothd.log &
39+
if is_debian_jessie ; then
40+
echo Bluetooth PSCAN not enabled! Restarting bluetoothd...
41+
sudo killall bluetoothd
42+
sudo $EXECUTABLE 2>&1 | tee -a /var/log/openaps/bluetoothd.log &
43+
else
44+
echo Bluetooth PSCAN not enabled! Restarting bluetoothd via systemctl...
45+
sudo systemctl bluetooth restart
46+
fi
3547
fi
3648

3749
if ( hciconfig -a hci${adapter} | grep -q "DOWN" ) ; then
50+
# Not sure that this is needed on Stretch, add an is_debian_jessie check here if something different required.
3851
echo Bluetooth hci DOWN! Bringing it to UP.
3952
sudo hciconfig hci${adapter} up
40-
sudo $EXECUTABLE 2>&1 | tee -a /var/log/openaps/bluetoothd.log &
41-
fi
53+
fi
4254

4355
if !( hciconfig -a hci${adapter} | grep -q $HOSTNAME ) ; then
44-
echo Bluetooth hci name does not match hostname: $HOSTNAME. Setting bluetooth hci name.
45-
sudo hciconfig hci${adapter} name $HOSTNAME
56+
# Not sure that this is needed on Stretch, add an is_debian_jessie check here if something different required.
57+
echo Bluetooth hci name does not match hostname: $HOSTNAME. Setting bluetooth hci name.
58+
sudo hciconfig hci${adapter} name $HOSTNAME
4659
fi

bin/oref0-pump-loop.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ main() {
8888
echo Completed oref0-pump-loop at $(date)
8989
update_display
9090
run_plugins
91+
update_bgproxy
9192
echo
9293
else
9394
# pump-loop errored out for some reason
@@ -112,6 +113,16 @@ function run_script() {
112113
}
113114

114115

116+
function update_bgproxy {
117+
if [ "$(get_pref_string .enableEnliteBgproxy '')" == "true" ]; then
118+
echo Calling Bgproxy
119+
jq 'map({sgv:.sgv, date:.date, dateString:.dateString})' monitor/glucose.json > monitor/bgproxydata.json
120+
bgproxy -f monitor/bgproxydata.json
121+
echo Bgproxy completed
122+
fi
123+
124+
}
125+
115126
function run_plugins {
116127
once=plugins/once
117128
every=plugins/every

bin/oref0-setup.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,10 @@ if prompt_yn "" N; then
858858
mv -f /etc/cron.daily/logrotate /etc/cron.hourly/logrotate
859859
fi
860860

861+
if ! grep -qa "kernel.panic" /etc/sysctl.conf ; then
862+
echo -e "# reboot rig 3 seconds after a kernel panic\nkernel.panic = 3" >> /etc/sysctl.conf
863+
fi
864+
861865
# configure ns
862866
if [[ ! -z "$NIGHTSCOUT_HOST" && ! -z "$API_SECRET" ]]; then
863867
echo "Removing any existing ns device: "
@@ -1118,6 +1122,7 @@ if prompt_yn "" N; then
11181122
#fi
11191123

11201124
sudo pip install --default-timeout=1000 flask flask-restful || die "Can't add xdrip cgm - error installing flask packages"
1125+
sudo pip install --default-timeout=1000 -U flask-cors
11211126

11221127
# xdrip CGM (xDripAPS), also gets installed when using xdrip-js
11231128
if [[ ${CGM,,} =~ "xdrip" || ${CGM,,} =~ "xdrip-js" ]]; then
@@ -1133,7 +1138,8 @@ if prompt_yn "" N; then
11331138
if [[ ${CGM,,} =~ "xdrip-js" ]]; then
11341139
echo xdrip-js selected as CGM, so configuring xdrip-js
11351140
git clone https://github.com/xdrip-js/Logger.git $HOME/src/Logger
1136-
cd $HOME/src/Logger
1141+
cd $HOME/src/Logger
1142+
sudo apt-get install -y bluez-tools
11371143
sudo npm run global-install
11381144
touch /tmp/reboot-required
11391145
fi
@@ -1273,14 +1279,17 @@ if prompt_yn "" N; then
12731279
# Install Golang
12741280
mkdir -p $HOME/go
12751281
source $HOME/.bash_profile
1276-
if go version | grep go1.11.; then
1282+
golangversion=1.12.5
1283+
if go version | grep go${golangversion}.; then
12771284
echo Go already installed
12781285
else
1286+
echo "Removing possible old go install..."
1287+
rm -rf /usr/local/go/*
12791288
echo "Installing Golang..."
12801289
if uname -m | grep armv; then
1281-
cd /tmp && wget -c https://storage.googleapis.com/golang/go1.11.linux-armv6l.tar.gz && tar -C /usr/local -xzvf /tmp/go1.11.linux-armv6l.tar.gz
1290+
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
12821291
elif uname -m | grep i686; then
1283-
cd /tmp && wget -c https://dl.google.com/go/go1.11.linux-386.tar.gz && tar -C /usr/local -xzvf /tmp/go1.11.linux-386.tar.gz
1292+
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
12841293
fi
12851294
fi
12861295
if ! grep GOROOT $HOME/.bash_profile; then

lib/autotune/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function tuneAllTheThings (inputs) {
100100

101101
// tune insulinPeakTime
102102
var newPeak = peak;
103-
if (peakDeviations) {
103+
if (peakDeviations && peakDeviations[2]) {
104104
var currentPeakMeanDev = peakDeviations[2].meanDeviation;
105105
var currentPeakRMSDev = peakDeviations[2].RMSDeviation;
106106
//console.error(currentPeakMeanDev);

lib/determine-basal/determine-basal.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
7878
}
7979
if (minAgo > 12 || minAgo < -5) { // Dexcom data is too old, or way in the future
8080
rT.reason = "If current system time "+systemTime+" is correct, then BG data is too old. The last BG data was read "+minAgo+"m ago at "+bgTime;
81-
// if BG is too old/noisy, or is completely unchanging, cancel any high temps and shorten any long zero temps
82-
} else if ( glucose_status.short_avgdelta === 0 && glucose_status.long_avgdelta === 0 ) {
81+
// if BG is too old/noisy, or is changing less than 1 mg/dL/5m for 45m, cancel any high temps and shorten any long zero temps
82+
} else if ( bg > 60 && glucose_status == 0 && glucose_status.short_avgdelta > -1 && glucose_status.short_avgdelta < 1 && glucose_status.long_avgdelta > -1 && glucose_status.long_avgdelta < 1 ) {
8383
if ( glucose_status.last_cal && glucose_status.last_cal < 3 ) {
8484
rT.reason = "CGM was just calibrated";
8585
} else {
8686
rT.reason = "Error: CGM data is unchanged for the past ~45m";
8787
}
8888
}
89-
if (bg <= 10 || bg === 38 || noise >= 3 || minAgo > 12 || minAgo < -5 || ( glucose_status.short_avgdelta === 0 && glucose_status.long_avgdelta === 0 ) ) {
90-
if (currenttemp.rate >= basal) { // high temp is running
91-
rT.reason += ". Canceling high temp basal of "+currenttemp.rate;
89+
if (bg <= 10 || bg === 38 || noise >= 3 || minAgo > 12 || minAgo < -5 || ( bg > 60 && glucose_status == 0 && glucose_status.short_avgdelta > -1 && glucose_status.short_avgdelta < 1 && glucose_status.long_avgdelta > -1 && glucose_status.long_avgdelta < 1 ) ) {
90+
if (currenttemp.rate > basal) { // high temp is running
91+
rT.reason += ". Replacing high temp basal of "+currenttemp.rate+" with neutral temp of "+basal;
9292
rT.deliverAt = deliverAt;
9393
rT.temp = 'absolute';
94-
rT.duration = 0;
95-
rT.rate = 0;
94+
rT.duration = 30;
95+
rT.rate = basal;
9696
return rT;
9797
//return tempBasalFunctions.setTempBasal(basal, 30, profile, rT, currenttemp);
9898
} else if ( currenttemp.rate === 0 && currenttemp.duration > 30 ) { //shorten long zero temps to 30m

lib/profile/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ function defaults ( ) {
6262
, offline_hotspot: false // enabled an offline-only local wifi hotspot if no Internet available
6363
, noisyCGMTargetMultiplier: 1.3 // increase target by this amount when looping off raw/noisy CGM data
6464
, suspend_zeros_iob: true // recognize pump suspends as non insulin delivery events
65+
// send the glucose data to the pump emulating an enlite sensor. This allows to setup high / low warnings when offline and see trend.
66+
// To enable this feature, enable the sensor, set a sensor with id 0000000, go to start sensor and press find lost sensor.
67+
, enableEnliteBgproxy: false
6568
// TODO: make maxRaw a preference here usable by oref0-raw in myopenaps-cgm-loop
6669
//, maxRaw: 200 // highest raw/noisy CGM value considered safe to use for looping
6770
};

lib/profile/targets.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ function lookup (inputs, profile) {
4747
//console.error(temptargets_data[i]);
4848
tempTargets = bgTargets;
4949
break;
50+
} else if (! temptargets_data[i].targetBottom || ! temptargets_data[i].targetTop) {
51+
console.error("eventualBG target range invalid: " + temptargets_data[i].targetBottom + "-" + temptargets_data[i].targetTop);
52+
break;
5053
} else if (now >= start && now < expires ) {
5154
//console.error(temptargets_data[i]);
5255
tempTargets.high = temptargets_data[i].targetTop;

tests/determine-basal.test.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('determine-basal', function ( ) {
7878
//function determine_basal(glucose_status, currenttemp, iob_data, profile)
7979

8080
// standard initial conditions for all determine-basal test cases unless overridden
81-
var glucose_status = {"delta":0,"glucose":115,"long_avgdelta":0.1,"short_avgdelta":0};
81+
var glucose_status = {"delta":0,"glucose":115,"long_avgdelta":1.1,"short_avgdelta":0};
8282
var currenttemp = {"duration":0,"rate":0,"temp":"absolute"};
8383
var iob_data = {"iob":0,"activity":0,"bolussnooze":0};
8484
var autosens = {"ratio":1.0};
@@ -126,7 +126,7 @@ describe('determine-basal', function ( ) {
126126
it('should do nothing when low and rising w/o IOB', function () {
127127
var glucose_status = {"delta":6,"glucose":75,"long_avgdelta":6,"short_avgdelta":6};
128128
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
129-
console.log(output);
129+
//console.log(output);
130130
output.rate.should.equal(0.9);
131131
output.duration.should.equal(30);
132132
//output.reason.should.match(/75<80.*setting current basal/);
@@ -248,27 +248,30 @@ describe('determine-basal', function ( ) {
248248
});
249249

250250
it('should temp to 0 when LOW w/ positive IOB', function () {
251-
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":0.1,"short_avgdelta":0};
251+
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":-1.1,"short_avgdelta":0};
252252
var iob_data = {"iob":1,"activity":0.01,"bolussnooze":0.5};
253253
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
254+
//console.log(output);
254255
output.rate.should.equal(0);
255256
output.duration.should.be.above(29);
256257
//output.reason.should.match(/BG 39<80/);
257258
});
258259

259260
it('should low temp when LOW w/ negative IOB', function () {
260-
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":0.1,"short_avgdelta":0};
261+
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":-1.1,"short_avgdelta":0};
261262
var iob_data = {"iob":-2.5,"activity":-0.03,"bolussnooze":0};
262263
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
264+
//console.log(output);
263265
output.rate.should.be.below(0.8);
264266
output.duration.should.be.above(29);
265267
//output.reason.should.match(/BG 39<80/);
266268
});
267269

268270
it('should temp to 0 when LOW w/ no IOB', function () {
269-
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":0.1,"short_avgdelta":0};
271+
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":-1.1,"short_avgdelta":0};
270272
var iob_data = {"iob":0,"activity":0,"bolussnooze":0};
271273
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
274+
//console.log(output);
272275
output.rate.should.equal(0);
273276
output.duration.should.be.above(29);
274277
//output.reason.should.match(/BG 39<80/);
@@ -476,7 +479,7 @@ describe('determine-basal', function ( ) {
476479
var output = determine_basal({glucose:10},currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
477480
//console.log(output);
478481
output.rate.should.be.below(1);
479-
output.reason.should.match(/Canceling high temp/);
482+
output.reason.should.match(/Replacing high temp/);
480483
});
481484

482485
it('profile should contain min_bg,max_bg', function () {
@@ -725,6 +728,7 @@ describe('determine-basal', function ( ) {
725728
profile.current_basal = 0.825;
726729
profile.model = "523";
727730
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
731+
//console.log(output);
728732
//output.rate.should.equal(0);
729733
//output.duration.should.equal(0);
730734
output.rate.should.equal(0.825);
@@ -738,6 +742,7 @@ describe('determine-basal', function ( ) {
738742
profile.current_basal = 0.875;
739743
profile.model = "522";
740744
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
745+
//console.log(output);
741746
//output.rate.should.equal(0);
742747
//output.duration.should.equal(0);
743748
output.rate.should.equal(0.9);

0 commit comments

Comments
 (0)