Web server

Juggluco contains a web server. You can turn it on with Left menu->Settings->Web server. Via the web server other programs can make use of the data in Juggluco. In the following 127.0.0.1 is used for the hostname or IP of the web server. In this way you can try out the commands by opening this web page on the same phone where Juggluco is running. If you unset "Local only" in Left menu->Settings -> Web server, you can also use it from other hosts on your home network by replacing 127.0.0.1 with the IP of the phone. If Use SSL is set, you can replace http://127.0.0.1:17580 with https://ahostname:aport. Whereby "ahostname" is the hostname associated with the SSL certificate and "aport" is the port that your modem redirects to "SSL Port" (set in left menu->Settings->Web server) of your phone. You can also use this page when using something different from "http://127.0.0.1:17580": If you add ?urlstart=aurl  http://127.0.0.1:17580 in all these examples is replaced with aurl.  For example you can use https://www.juggluco.nl/Juggluco/webserver.html?urlstart=http://192.168.1.69:17580 in which case http://127.0.0.1:17580 is replaced with http://192.168.1.69:17580. (It works only when you click on a link, not when you open a link in a different tab or window). You can also append the api_secret, for example: https://www.juggluco.nl/Juggluco/webserver.html?urlstart=http://192.168.1.74:17580/somethingsecret whereby somethingsecret is the api_secret.

Instead of Juggluco on a phone, you can also use Juggluco server. Android or WearOS apps can, instead of making use of the web server, also receive a broadcast every time a new glucose value is received from the sensor.

Juggluco export web server

Starting with Juggluco 7.1.0 exactly the same data as can be exported in Juggluco with Left middle menu->Export, can also be assessed with via the web interface.

Stream

http://127.0.0.1:17580/x/stream

Scans

http://127.0.0.1:17580/x/scans

History

http://127.0.0.1:17580/x/history

Amounts

http://127.0.0.1:17580/x/amounts

Meals

http://127.0.0.1:17580/x/meals

After one of the above commands you can place '?' followed by a list of the following options separated by '&".

Option

Meaning

Example

header

Place a header with the meaning of each column above the columns.

http://127.0.0.1:17580/x/stream?header

mg/dL

Give glucose in mg/dL

The default unit is dependent on the unit settings of Juggluco or Juggluco server.

http://127.0.0.1:17580/x/stream?header&mg/dL

mmol/L

Give glucose in mmol/L

http://127.0.0.1:17580/x/stream?mmol/L&header

days=

Specify for how many days data should be returned.

http://127.0.0.1:17580/x/history?header&days=0.8

duration=

The duration of data in seconds. Multiple days and duration specifications are added. When the total duration is zero, it defaults to 5 hours.

http://127.0.0.1:17580/x/stream?duration=3600

starttime=

Start time in Unix time (seconds since 00:00 1 January 1970 GMT).

http://127.0.0.1:17580/x/amounts?starttime=1698266963

endtime=

End time in Unix time (seconds since 00:00 1 January 1970 GMT).

http://127.0.0.1:17580/x/stream?endtime=1698266963

start=

Other way to specify the start time for testing purposes. The time is in local time (Nightscout uses GMT).

http://127.0.0.1:17580/x/scans?header&start=2023-02-23T8:43:00&days=8

end=

Specify end time.

http://127.0.0.1:17580/x/stream?end=2023-10-28T23:10&header

maxcount=

Truncates output to the specified number of items.

http://127.0.0.1:17580/x/stream?maxcount=3

token=

The Nightscout token used for Nightscout commands, can also be used for the Juggluco's export commands. In other Nightscout servers, Nightscout token is different from api_secret, but in the Nightscout server in Juggluco they are the same.

api_secret and api-secret also work with all commands that use the web server in Juggluco. They are http header elements. api_secret is plain text, api-secret is SHA1 encoded. Examples:

api_secret: xyx

api-secret: 3c4bc8e59079403cb17a03a19c889769faadfdc8

Juggluco 7.1.15 has added a third method to supply the api_secret. You can add the api_secret after the hostname and port. This has the advantage that you can also add an api_secret to app that themselves don’t have the possibility to supply an api_secret or token. This is meant to be used with Nightscout clients. So you can give as Nightscout Follow URL http://127.0.0.1:17580/xyz instead of http://127.0.0.1:17580 when xyz is the api_secret.

http://127.0.0.1:17580/x/history?token=xyz

The data contains the following columns:

Column header

Meaning

Used with:

Sensorid

Sensor identifier

Sensor only

Nr

Number starting with 1 for the first data item of a particular sensor or data source and incremented with each new item.

both

UnixTime

Time in number of seconds since 00:00 1 January 1970 GMT

both

YYYY-mm-dd-HH:MM:SS

Local time split into its component parts. mm= month, MM= Minute.

both

TZ

Time zone in number of hours from GMT

both

Min

Number of minutes since the start of the sensor.

sensor only

mmol/L or mg/dL

Glucose value. If the url doesn't contain mmol/L or mg/dL, is the unit dependent on the unit setting of Juggluco.

sensor only

Rate

Rate of change.

sensor only

ChangeLabel

Label for rate of change

sensor only

Source

0 for Amounts entered in Juggluco, 1 for Kerfstok.

amounts only

Value

Value of amount

amounts only

Label

Label for amount

amounts only

The meaning of rate of change:

Rate:

Label:

Arrow in Abbott app:

<=-2

FALLING_QUICKLY

Between -2 and -1

FALLING

-1 to 1

STEADY

1 to 2

RISING

>=2

RISING_QUICKLY

nan

NOT_DETERMINED


Meals can easily be imported into R, Python and Mathematica. The footer of each meal contains also the unix time (seconds since 1 january 1970 00:00 GMT) after the date in local time.

R:

library(rvest)
library(xml2)
meal1=html_table(read_html("http://127.0.0.1:17580/x/meals?days=6"),header=TRUE)

tail(meal1[[1]]$Ingredient,n=1)
[1] "2023-12-29 13:12"
> tail(meal1[[1]]$Quantity,n=1)
[1] 1703851920
> as.POSIXct(tail(meal1[[1]]$Quantity,n=1), origin="1970-01-01")
[1] "2023-12-29 13:12:00 CET"

Python:

import pandas as pd
from datetime import datetime
meal1=pd.read_html("http://127.0.0.1:17580/x/meals?days=6")

print(datetime.fromtimestamp(meal1[0]['Quantity'].iloc[-1]))
print(meal1[0]['Ingredient'].iloc[-1])
2023-12-29 13:12:00
2023-12-29 13:12

Mathematica:

xDrip / Nightscout web server

Some existing apps make use of a xDrip or Nightscout web interface.

xDrip

Juggluco incorporates an xDrip web server. This way you can receive glucose values via http://127.0.0.1:17580/sgv.json on the devices running Juggluco. Turn the server on in Juggluco under left menu->watch->web server.


Juggluco recognizes the following xDrip server options:

count=nr

Give nr values, instead of 24.

For example to receive 10 values use:

http://127.0.0.1:17580/sgv.json?count=10

brief_mode=Y

Display less information. For example:

http://127.0.0.1:17580/sgv.json?count=2&brief_mode=Y

sensor=Y

Give sensor start date and age. For example:

http://127.0.0.1:17580/sgv.json?count=3&sensor=Y&brief_mode=Y

all_data=Y

If necessary also displays values of previous sensors.

no_empty=Y

Displays nothing instead of [] when no data is available.

Juggluco added the following option:

interval=seconds

interval gives the minimal number of seconds between values. If not specified, it is set to 270 seconds (4.5 minutes) to keep in line with xDrip. This means that if multiple values are given they are spaced at least 270 seconds apart (the first is always the most recent value). If you like to receive values spaced more closely in time, you can specify a smaller number.

for example:

http://127.0.0.1:17580/sgv.json?count=100&interval=90

To receive 100 glucose values spaced 90 seconds apart. In reality this will be around 2 minutes apart.

Another possibility could be to round values instead of skipping them. But averaging the last values makes the measurement older. If the last value is the average of the last 5 values, the average of its age will be 2 to 3 minutes. Because the measurement location is already physiologically distance from the blood, there is more to say for extrapolating instead of averaging the values. Thus, if you have for the last 5 minutes 10,9,8,7 and 6 mmol/L you should return 5 mmol/L instead of 7.6 mmol/L.

Nightscout

Juggluco only implements Nightscout used by apps contacting Nightscout; it has not the intent to implements commands used by no one and full-filling no other purpose than what other commands already do.

Nightscout commands implemented in Juggluco:

You can receive the same results as with http://127.0.0.1:17580/sgv.json, but with time in GMT instead of server local time, also with: http://127.0.0.1:17580/api/v1/entries/sgv.json and http://127.0.0.1:17580/api/v1/entries.json

In csv format: http://127.0.0.1:17580/api/v1/entries/sgv.csv

In tsv format: http://127.0.0.1:17580/api/v1/entries/sgv.tsv or http://127.0.0.1:17580/api/v1/entries/sgv.txt or http://127.0.0.1:17580/api/v1/entries

For only the last value in tsv format, you can use http://127.0.0.1:17580/api/v1/entries/current

You can receive the amounts from Juggluco with:

http://127.0.0.1:17580/api/v1/treatments

In addition to count, you have also the following options:

find[date][$gt]=datemsec

give results after datemsec, where datemsec is the number of milli seconds since 00:00 1 January 1970 GMT For example: http://127.0.0.1:17580/api/v1/treatments?count=5&find[date][$gt]=1679266800000

find[date][$gte]=datemsec

gives results at or after datemsec

find[date][$lt]=datemsec

give results before datemsec, where datemsec are the number of milli seconds since 00:00 1 January 1970 GMT For example: http://127.0.0.1:17580/api/v1/entries.json?count=5&find[date][$lt]=1679266800000

find[date][$lte]=datemsec

gives results at or before datemsec

By using dateString or created_at instead of date, you can use a date in the format YYYY-mm-DDThh:MM:ss, were mm is the month and MM the minutes. For example

http://127.0.0.1:17580/api/v1/entries.json?count=5&find[dateString][$lt]=2023-03-02T08:04:01

token=the_api_secret

See the Juggluco export web server options above.

Pebble

Made for a 2013 watch, some apps still use the following command:

http://127.0.0.1:17580/pebble

It contains the following information:

now: current time in milliseconds since 1 January 1970 00:00 GMT.

sgv: current glucose value in the unit of the server. For Libre sensor you can determine the unit by using the knowledge that the value of mg/dL is in the range 39-501 mg/dL and of mmol/L in the range 2.2-27.8 mmol/L.

Table 1: Meaning of trend and direction in pebble results

trend

Rate of change

direction

DexCom arrow

Abbott arrow

0

nan




1

>=3.5

DoubleUp

2

[2, 3.5)

SingleUp

3

[1, 2)

FortyFiveUp

4

(-1, 1)

Flat

5

(-2, -1]

FortyFiveDown

6

(-3.5, -2]

SingleDown

7

<=-3.5

DoubleDown

Rate of change is the Rate returned when exporting stream and scans in Juggluco (for example: http://127.0.0.1:17580/x/stream?header&duration=200).

bgdelta=rate*5

datetime: time of glucose value in milliseconds since 1 january 1970 00:00 GMT.

iob: Insulin on board (since Juggluco 7.1.10). Measure of how much insulin of previous rapid insulin injections is still present in the body. pebble is the only command that returns this measure.

http://127.0.0.1:17580/pebble has the following options:

units=mmol: give glucose values in mmol/L instead of the server units  e.g. http://127.0.0.1:17580/pebble?units=mmol

units=mg: give glucose values in mg instead of server units. e.g. http://127.0.0.1:17580/pebble?units=mg

count= specify the number of glucose values to return. e.g. http://127.0.0.1:17580/pebble?count=3

To used this web interface with SSL, you give Juggluco an SSL key as described in Left menu->Settings->Web server->Help.

Juggluco server

This web interface is also put in a standalone version of the network connectivity of Juggluco: see https://www.juggluco.nl/Juggluco/cmdline

In the same way as the other options, you can also turn on the eXport/xDrip/Nightscout web server. For local only usage, you do

./juggluco -x

You can see the current settings with

./juggluco -l

Output:

[...]

eXport web server turned on (port 17580)

http only over localhost

[...]

If you want to access from other hosts, you need to use capital X:

./juggluco -X

./juggluco -l now shows:

eXport web server turned on (port 17580)

can also be used remotely over http

With -e you can enable SSL encryption.

The http web server always uses port 17580, because xDrip watch apps can only be used with this port number. The SSL version is accessed by the port specified with -o

./juggluco -e -o 9191

says to enable the SSL (https) version and to use port 9191.

The mirror port, the http and the https port all need to be different.

./juggluco -l now shows:

Use SSL, sslport=9191

You can configure an api-secret with -g "an api-secret", for example you can use

./juggluco -g Xsa%sLF8

To set the api-secret to "Xsa%sLF8"

When you also enable https, this gives a kind of access restriction so that only people who know the api-secret can see your data. See api-secret.

As with the web server in the Juggluco app, you can also give treatments via the Nightscout web protocol. You also have to specify for each label what should be done with it. If juggluco server has received "Amounts", you can see the available labels with ./juggluco -l, for example:

eXport web server turned on (port 17580)
can also be used remotely over http
Use SSL, sslport=9191
0: Aspart      Not set
1: Carbohydra  Not set
2: Dextro      Not set
3: Levemir     Not set
4: Bike        Not set
5: Walk        Not set
6: Blood       Not set
7: bad         Not set
api/v1/treatments turned off

For each label numbered 0 to 7, you have to say what it is.

The following code is used for that:

R: Rapid acting Insulin

L: Long acting Insulin

C: Carbohydate

O: cOmments

D: Don't send

You assign a label to a category, by using '-' followed by the number of the label followed by the letter for the category.

To assign Aspart to Rapid acting Insulin you use -0R : Aspart is label number 0 and R means "Rapid acting Insulin". To assign all labels you can use:

./juggluco -0R -1C -2C -3L -4O -5O -6O -7D

labels 0 is R, 1 and 2 are C (Carbohydrate) and 4, 5 and 6 are O (cOmments) and 7 is not sent.

Now,

./juggluco -l shows:

eXport web server turned on (port 17580)
can also be used remotely over http
Use SSL, sslport=9191
0: Aspart      Rapid acting insulin
1: Carbohydra  Carbohydrate
2: Dextro      Carbohydrate
3: Levemir     Long acting insulin
4: Bike        Comments
5: Walk        Comments
6: Blood       Comments
7: bad         Don't send
api/v1/treatments turned off

Now it still doesn't give treatments. You first have to turn it on with -t

./juggluco -t

./juggluco -l now shows:

Saving in directory jugglucodata
eXport web server turned on (port 17580)
can also be used remotely over http
Use SSL, sslport=9191
0: Aspart      Rapid acting insulin
1: Carbohydra  Carbohydrate
2: Dextro      Carbohydrate
3: Levemir     Long acting insulin
4: Bike        Comments
5: Walk        Comments
6: Blood       Comments
7: bad         Don't send
api/v1/treatments turned on
api_secret: Xsa%sLF8

Mirror port 9113
unit: mg/dL
connection:

SSL

To make use of SSL, you need to give Juggluco server a SSL certificate for the hostname by which the server is accessed. How you can get an SSL key is described in the help under Left menu->Settings->Webserver and in the README in the source of Juggluco server. For Juggluco server, you need to put the the private key in a file named prevkey.pem and the fullchain in a file named fullchain.pem in jugglucodata. jugglucodata is the directory were Juggluco server saves its data:

ls -l jugglucodata/
total 136
-rwxr-xr-x   1 juggluco juggluco   8064 18 nov 20:36 backup.dat
-rwxr-xr-x   1 juggluco juggluco   4716  8 nov 13:12 fullchain.pem
drwxr-xr-x   2 juggluco juggluco   4096 12 jan  2023 logs
-rwxr-xr-x   1 juggluco juggluco 253952 18 nov 20:00 meals.dat
drwxr-xr-x   4 juggluco juggluco   4096 12 jan  2023 nums
-rw-r--r--   1 juggluco juggluco   1702  8 nov 13:12 privkey.pem
drwxr-xr-x 104 juggluco juggluco   4096 18 nov 12:36 sensors
-rwxr-xr-x   1 juggluco juggluco  22032 18 nov 17:49 settings.dat