This commit is contained in:
gjkoolen 2025-10-20 13:37:03 +02:00
commit 959aff4071
4 changed files with 21 additions and 15 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.venv/ .venv/
.vscode/ .vscode/
src/backups/

View file

@ -1,6 +1,8 @@
import requests import requests
import time import time
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import hashlib
import binascii
from datetime import datetime from datetime import datetime
from collections import deque from collections import deque
@ -14,18 +16,21 @@ brokercreds = ["hass","Bruk#5"]
##### Variables ##### ##### Variables #####
# API JWT token, Account-Id and Patient_Id # API JWT token, Account-Id and Patient_Id
jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImM1ZGVhZGZiLTNlZDYtMTFlYS1hZjZmLTAyNDJhYzExMDAwYSIsImZpcnN0TmFtZSI6IkdlcnRqYW4iLCJsYXN0TmFtZSI6Iktvb2xlbiIsImNvdW50cnkiOiJOTCIsInJlZ2lvbiI6ImV1Iiwicm9sZSI6InBhdGllbnQiLCJlbWFpbCI6Imdqa29vbGVuQGdtYWlsLmNvbSIsInMiOiJsbHUuYW5kcm9pZCIsInNpZCI6IjkzYTZmMmU2LWRjNDQtNDA0Mi04YjBiLTcxMGQ3MzAyMzMyNSIsInRhc2tUeXBlIjoidG91IiwiZXhwIjoxNzYwMTkzMDM2LCJpYXQiOjE3NjAxODk0MzYsImp0aSI6ImU0NTRlYzljLTE2ZTMtNDQwMy05YjYyLTc0NjAxZTkzNDFjOSJ9.hiyrVjE2kWvBr2DjtPojdTDtkqNrPI57HubXYl4Kko0" jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImM1ZGVhZGZiLTNlZDYtMTFlYS1hZjZmLTAyNDJhYzExMDAwYSIsImZpcnN0TmFtZSI6IkdlcnRqYW4iLCJsYXN0TmFtZSI6Iktvb2xlbiIsImNvdW50cnkiOiJOTCIsInJlZ2lvbiI6ImV1Iiwicm9sZSI6InBhdGllbnQiLCJzIjoibGx1LmFuZHJvaWQiLCJzaWQiOiIyZDM3NTJmNy01M2EwLTQ2N2ItOTAyNS02YmIzODBmZTYxZWEiLCJleHAiOjE3NzY1MDYwNTIsImlhdCI6MTc2MDk1NDA1MiwianRpIjoiNDYzYmRiZjQtNjJiNi00N2I4LWJiNzYtN2FmMmJjNGY2YjkzIn0.0pxP3zagyWaTF-r0F9mHOtSsbsMwz3lUvzEnQQmDNek"
Account_ID = "dad20d62aeef891d94bda411af269900180cb7b84a0ce51d60b52463339935b1" #Account_ID = "dad20d62aeef891d94bda411af269900180cb7b84a0ce51d60b52463339935b1"
Patient_ID = "c5deadfb-3ed6-11ea-af6f-0242ac11000a" Patient_ID = "c5deadfb-3ed6-11ea-af6f-0242ac11000a"
# API endpoint for login # API endpoint for login
#url = f"https://api-eu.libreview.io/llu/connections/{Patient_ID}/graph" #url = f"https://api-eu.libreview.io/llu/connections/{Patient_ID}/graph"
url = f"https://libreview-proxy.onrender.com/eu/auth/continue/tou" url = f"https://libreview-proxy.onrender.com/eu/auth/continue/tou"
digest = hashlib.sha256(Patient_ID.encode('utf-8')).digest()
Account_ID = binascii.hexlify(digest).decode('utf-8')
# Headers # Headers
headers = { headers = {
"content-type": "application/json", # This nececcery "Accept": "application/json", # This nececcery
"product": "llu.android", # This nececcery "product": "llu.android", # This nececcery
"version": "4.13.0", # Version older then 4.12.0 gives error. "version": "4.16", # Version older then 4.12.0 gives error.
"Authorization": f"Bearer {jwt_token}", # JWT_token for login "Authorization": f"Bearer {jwt_token}", # JWT_token for login
"Account-Id" : Account_ID # Extra login credentials "Account-Id" : Account_ID # Extra login credentials
} }
@ -50,7 +55,7 @@ limits_max_hours = 4 # nr of hours in the above lists
last_bolus_time = time.time()-3600 last_bolus_time = time.time()-3600
last_bolus_type = 0 last_bolus_type = 0
GLUC_READOUT_PERIOD = 5 # in minutes GLUC_READOUT_PERIOD = 1 #5 # in minutes
GLUC_SLOPE_PERIOD = 30 # in minutes GLUC_SLOPE_PERIOD = 30 # in minutes
GLUC_BUFFER_LENGTH = round(GLUC_SLOPE_PERIOD/GLUC_READOUT_PERIOD) GLUC_BUFFER_LENGTH = round(GLUC_SLOPE_PERIOD/GLUC_READOUT_PERIOD)
gluc_buffer = deque([6.0] * GLUC_BUFFER_LENGTH, maxlen=GLUC_BUFFER_LENGTH) # The gluc_buffer always contains only the last xx elements. Initialized on 6.0 gluc_buffer = deque([6.0] * GLUC_BUFFER_LENGTH, maxlen=GLUC_BUFFER_LENGTH) # The gluc_buffer always contains only the last xx elements. Initialized on 6.0
@ -106,7 +111,6 @@ def main(url_main, headers_main):
print("Hey joh check je glucosepeil !") print("Hey joh check je glucosepeil !")
Mqtt.publish(send_topic, f"Hey joh check peil ! (lastbolus -{round(hours_since_last_bolus, 1)})") Mqtt.publish(send_topic, f"Hey joh check peil ! (lastbolus -{round(hours_since_last_bolus, 1)})")
else: # Request has failed else: # Request has failed
print(f"❌ Error: Could not connect to server: {response.status_code}") print(f"❌ Error: Could not connect to server: {response.status_code}")
except requests.exceptions.JSONDecodeError: except requests.exceptions.JSONDecodeError:

View file

@ -1,7 +1,8 @@
import requests import requests
# API endpoint for login # API endpoint for login
url = "https://api-eu.libreview.io/llu/auth/login" # Replace with the actual API URL #url = "https://api-eu.libreview.io/llu/auth/login" # Replace with the actual API URL
url = "https://libreview-proxy.onrender.com/eu/llu/auth/login" # Replace with the actual API URL
# Login credentials # Login credentials
payload = { payload = {
@ -14,9 +15,9 @@ headers = {
'accept-encoding': 'gzip', 'accept-encoding': 'gzip',
'cache-control': 'no-cache', 'cache-control': 'no-cache',
'connection': 'Keep-Alive', 'connection': 'Keep-Alive',
'content-type': 'application/json', 'Accept': 'application/json',
'product': 'llu.android', 'product': 'llu.android',
'version': '4.7' 'version': '4.16'
} }
# Send the POST request # Send the POST request

View file

@ -7,7 +7,7 @@ import paho.mqtt.client as mqtt
from time import sleep from time import sleep
##### Mqtt vars ##### ##### Mqtt vars #####
broker_address = "192.168.1.250" broker_address = "192.168.1.160"
broker_port = 1883 broker_port = 1883
recieve_topic = "telegrambot/out/#" recieve_topic = "telegrambot/out/#"
send_topic_server = "telegrambot/in/server/" send_topic_server = "telegrambot/in/server/"