04 — Insulin, carbs and glucose to LibreView, from the phone and the Mac
Esta página aún no está disponible en tu idioma.
2026-10-15 · investigation report · follows 02 — direct sensor
The doctor reads LibreView, so whatever replaces Juggluco must keep feeding it: glucose, and the insulin / carbs / notes the user logs. Juggluco does this today. Questions:
- Can the phone app upload treatments (and glucose) to LibreView itself?
- Can the Mac app do it too?
- Can a treatment logged on either device show up on the other, and reach LibreView once?
- Will the same data fit the Nostr sharing being explored in 03?
Result
Section titled “Result”| Question | Answer |
|---|---|
| Phone → LibreView | Yes, proven. GlucoBridge uploads treatments and (direct flavor) sensor glucose; both appear in LibreView’s export under the spike device. |
| Mac → LibreView | Yes, proven. GlucoseBar uploads treatments with the same client logic, byte-identical payload. |
| Sync phone ↔ Mac | Yes, proven over the existing BLE link: either direction in ~1–2 s, edits/deletes on both sides, and changes made on both sides while disconnected all converge. |
| No duplicates in LibreView | Yes, proven with LibreView’s CSV export: the same entry posted by phone, Mac and a test tool is one row; edits replace, deletes remove. |
| Nostr-ready | By design. A treatment is one JSON object with a stable id and a last-writer-wins version — a parameterized-replaceable Nostr event as-is. Not implemented here. |
┌──────── treatments (BLE GATT, JSON) ────────┐Libre 3 ──BLE──▶ GlucoBridge (Android) GlucoseBar (Mac) │ glucose + treatments │ treatments └────────────▶ LibreView ◀──────────────────────┘ one LibreView "device": same DeviceId, same record numbersHow LibreView ingestion works (what Juggluco does)
Section titled “How LibreView ingestion works (what Juggluco does)”Juggluco impersonates Abbott’s FreeStyle Libre 3 Android app: it fetches Abbott’s public app config (API base
URL + API key), logs in with the patient’s email/password and a per-install DeviceId, then POSTs one JSON
document per upload — device settings plus currentGlucoseEntries, scheduledContinuousGlucoseEntries (5-min
history), insulinEntries (rapid/long units), foodEntries (grams), genericEntries (notes, sensor start).
Every entry carries a recordNumber; an edit or a delete ("action":"deleted") is the same record sent again.
The exact bytes are in poc/spikes/libreview/SPEC.md; lv.py there is an executable
reference that generates a golden fixture both apps must reproduce byte for byte (they do).
Key design decisions:
- One LibreView device for both apps. A login token is tied to a
DeviceId, and LibreView lists eachDeviceIdas a separate device. The phone generates the id and hands it to the Mac over BLE, so phone, Mac (and thelv.pytest tool) are one device. That also makes the spike removable in one click (LibreView → My devices). Each sign-in ends the other’s token; it works because both sign in again when refused. With an official app that doesn’t, it stops that app’s upload (45). - Deterministic record numbers, one per version. Treatment
recordNumber = SHA-256("id:version")[0..5] << 8 | type; glucose uses Juggluco’s scheme (sensor serial hash| lifeCount), checked against Juggluco’s own C++. Either app uploading the same version produces the same record, so re-uploads are harmless. LibreView keeps the first value of a record number, so an edit is “delete the uploaded version + add the new one” (as Juggluco does). - Treatment log = the sync unit.
{id, kind, amount, time, note, version, deleted, origin, uploaded-version}; merge = newer version wins, upload watermark only moves forward. The phone numbers every accepted change, the Mac follows that sequence with a cursor — so sync never depends on the two clocks agreeing. - Upload policy. The device that created an entry uploads it at once; the other uploads it only if it’s still pending after 2 minutes. Double uploads still happen (and did) — they must be, and are designed to be, harmless.
What happened (timeline, 2026-10-15)
Section titled “What happened (timeline, 2026-10-15)”| Time | Step | Outcome |
|---|---|---|
| 21:16–21:25 | BLE sync, no LibreView: phone→Mac, Mac→phone, cross edit/delete, edits on both sides while disconnected | all converged (Mac cursor = phone seq, nothing unacked) |
| 23:01 | login with SetDevice:false |
status 20 wrongDeviceForUser — the account was bound to Juggluco’s device |
| 23:04 | phone: login with SetDevice:true (Juggluco’s upload switched off first), upload 2 own entries |
status 0 |
| 23:09 | phone uploads the Mac’s 2 entries after the 2-min grace (one is a delete of a never-uploaded row) | status 0 |
| 23:11 | Mac logs in (SetDevice:false now succeeds — same DeviceId), uploads its own entry |
status 0; phone’s token kept working (not so: the Mac’s sign-in ended it, and the phone signed in again when refused, 45) |
| 23:12 | edit-after-upload (Mac edits a phone entry) — uploaded by both Mac and phone 3 s apart | status 0 ×2 |
| 23:12 | delete-after-upload (phone deletes a Mac entry) | status 0 |
| 23:12 | deliberate duplicate: lv.py re-posts two unchanged entries as the same device |
status 0 |
| 23:13–23:26 | Juggluco force-stopped, direct flavor holds the sensor, glucose upload on | only 1-minute “current” readings went up — LibreView doesn’t keep those as rows |
| 23:22 | CSV #1 | dedupe ✅, delete ✅, edit ignored ❌ (0.5 U edited to 0.7 U still showed 0.5) → record number per version |
| 23:30–23:34 | direct flavor again, uploading the sensor’s backfilled 5-min history from 22:45 (what Juggluco hadn’t uploaded) | status 0 |
| 23:35 | edit test (1.0 → 1.5 U, edited on the Mac) and delete test (5 g, deleted on the phone), new scheme | status 0 |
| 23:49 | CSV #2 | edit ✅ (one row, 1.5 U), delete ✅, glucose ✅ (6 rows 22:49–23:14, continuing Juggluco’s 22:44) |
Verification
Section titled “Verification”LibreView’s upload API answers status 0 even when it later discards data (ingestion is asynchronous), so success
codes prove nothing about duplicates. The only raw read-back is the web app’s Download glucose data CSV (behind
a captcha, so it’s a manual step): it has one row per stored record with Device, Serial Number, record type and
insulin/carb/note columns.
Spike-device rows in the final export (device = “FreeStyle Libre 3”, serial = the shared DeviceId):
| What was sent | Rows in LibreView |
|---|---|
note: uploaded by the phone, re-posted unchanged by lv.py |
1 |
0.3 U: uploaded by the Mac, re-posted unchanged by lv.py |
1 |
| 0.5 U edited to 0.7 U under the same record number, uploaded by Mac and phone | 1 — still 0.5 (edit ignored) |
| 1.0 U edited to 1.5 U with the per-version scheme | 1 — 1.5 |
| 1 U long and 5 g carbs, deleted after upload; 12 g deleted before upload | 0 |
| sensor glucose, 5-min history 22:49–23:14 | 6, values identical to the sensor’s |
| sensor-start record | 1 empty “note” row — Juggluco’s device has the same |
| 1-minute “current” readings (uploaded every minute 23:14–23:26) | 0 — they feed LibreLinkUp’s live view, not the stored history |
So: re-uploading is idempotent per (device, record number), deletes work, edits need a new record number, and the glucose that reports are built from is the 5-minute history (which trails the live reading by ~16 min).
Gotchas found
Section titled “Gotchas found”- LibreView ignores changed values under an existing record number — see above.
- Backfilled history arrives out of order (after the first live reading); tracking “uploaded up to life count N” silently skipped it. Track the set of uploaded life counts instead.
- Abbott’s config CDN returns 403 to Python’s default User-Agent; all clients now send the Android
Dalvik/2.1.0 …User-Agent the phone sends anyway. - The account is bound to one “active” device: a new device must log in with
SetDevice:true, which logs the previous one (Juggluco) out of LibreView. Juggluco then re-takes it on its next upload, so two uploaders with different DeviceIds fight. Exactly one app may own the LibreView upload. Refined by 45: one active device and one live session per app identity (Libre 3 app, LibreLink). Any sign-in ends the previous token, even with the same DeviceId. Two apps share an account only under different identities. - The first
PUT nisperson(active-sensor registration) after login answeredstatus 20 invalid session; it succeeded on the next cycle a minute later. - macOS: CoreBluetooth doesn’t report the link as dropped when the phone app restarts; the Mac’s 150 s silence watchdog reconnects, so post-restart sync takes up to ~3 min.
- An unbundled
swift runbinary reads UserDefaults domainGlucoseBar, notdev.spike.GlucoseBar. - Spike shortcuts not to keep: the phone stores the LibreView password in plain app preferences; the
impersonation (Libre 3 app identity,
Android/16headers from the Mac) is what Juggluco does but is against Abbott’s terms.
Nostr (investigation 03)
Section titled “Nostr (investigation 03)”03 streams glucose from one uploader to any number of encrypted followers and lists treatments as out of scope. They fit without changing anything 03 built — design in SPEC §5:
- Same kind, same keys. One addressable kind-30078 event per treatment (like 03’s hourly chunks), opaque
d, content = this log’s JSON encrypted to 03’s read key. Volume is a few events per day. - One difference: many writers. Glucose has one uploader; treatments are created on the phone, the Mac, maybe a parent’s phone. Each device signs its own changes with its own key, and the identity key of 07’s PROTOCOL v2 authorizes writers (not the phone’s key, which changes with the phone), so a follower link stays read-only.
- Survives key rotation. Event addresses derive from a stable stream id rather than the read key, and each event says which read-key epoch encrypted it (agreed with the Nostr session for 07’s PROTOCOL v2).
- The merge rule already fits. Newest version wins, and it’s the rule both apps already use for BLE — so an entry can arrive over BLE, Nostr, or both, in any order, and every device ends up with the same log.
- LibreView stays with the phone + Mac pair; Nostr-only followers never upload to it.
- Nightscout: 03’s adapter returns empty
treatments; it could serve this log instead (rapid → Correction Bolus, carbs → Carb Correction, note → Note), which is what xDrip+, Nightguard and LoopFollow read.
Code check (2026-10-16): this investigation’s uncommitted changes replay onto origin/main (with 03 and 05) with
one conflict — main.swift, where both added wiring; resolution = keep both, and ble?.treatmentSync because 03
made the BLE transport optional. Mac app builds with 03’s Nostr SDK and passes the fixture + merge tests; Android
juggluco flavor builds and passes its unit tests.
What building it would take: the phone’s TreatmentStore.onChange becomes a listener list (BLE + Nostr), 03’s
NostrPublisher (moving into GlucoBridge anyway) gains a treatment publish + subscribe; on the Mac, 03’s
read-only NostrSource gains a device key (Keychain) and event publishing with 03’s pacing rules.
Cleanup (for the user’s real account)
Section titled “Cleanup (for the user’s real account)”Done 2026-10-16: spike uploads switched off in both apps, spike device removed in LibreView, Juggluco’s upload back on. Verified with a final export: 0 rows from the spike device, and Juggluco’s own history continuous (every 5 min, no gaps, no duplicates) through the spike window — it re-uploaded its backlog after being re-enabled.
- Delete every spike entry from the app (sends LibreView deletes) — or
lv.py cleanup. - LibreView → Account settings → My devices → remove the GlucoBridge device: removes everything that device uploaded, glucose included. Irreversible, but it only holds spike data.
- Juggluco → LibreView → Send to LibreView back on. It re-takes the account and uploads its own backlog (including the hours Juggluco was off), so the gap closes with Juggluco’s data.
In Sukrara: Import history (reading the history back)
Section titled “In Sukrara: Import history (reading the history back)”2026-11-10. The new apps start fresh (no database of the earlier app is read), so the owner asked to bring the history back from LibreView with the existing sign-in. Researched what a client can read back:
| Endpoint | What it gives | Verdict |
|---|---|---|
The app API this report uses (/api/nisperson/getauthentication, /api/measurements, x-newyu-token) |
upload only; Abbott says the Libre 3 app can’t download history (“download your raw glucose data from LibreView”) | nothing to read |
api.libreview.io/glucoseHistory?numPeriods=&period= (the web app, Authorization: Bearer from /auth/login) |
report summaries per period (AGP percentiles, average, days of data), not readings | not history |
LibreLinkUp /llu/connections/{patientId}/graph and /logbook (product: llu.android, version ≥ 4.16, Account-Id: SHA-256 of the user id) |
a follower’s view: the last ~12 h of readings and ~2 weeks of alarms, only for patients the account follows | not the wearer’s 90 days |
LibreView web Glucose History › Download glucose data (POST /export with captchaResponse) |
every reading and entry, as the “Glucose Data” CSV (the layout of 22) | behind a captcha: the person downloads it |
(2026-11-18, 45 45b) the web Daily Log report (POST /reports, client report 5, window.report.Data.Days[]) |
per chosen device: the 5-minute history, the time of every rapid dose and carbs entry, insulin and carbs as hourly sums (long-acting without its minute), notes with their minute; 14 days tried (libre-desktop asks 90) | no captcha, but the website’s own login, which asks for an SMS / email code (then a trusted-device token) |
Sources: YtoTech/libreview-data-export, the LibreLinkUp HTTP dumps
(gist, its comments on glucoseHistory and the
Account-Id header), Abbott’s support page on downloading data from the Libre 3 app.
| Added | Where |
|---|---|
From LibreView = the three steps (open LibreView, Download glucose data, choose the file) and the file import, which reads LibreView’s layout by column position (translated headers), mg/dL or mmol/L (. or ,), month- or day-first dates, 12 or 24 hours |
Android :integrations history/HistoryCsv.kt, ImportPage.kt; HistoryCsvTest (synthetic US and European fixtures) |
| One import path for every origin: nothing twice (2-minute reading rule, the Nightscout linking rule for entries), idempotent, the sensor’s own reading wins, imported data marked and never uploaded again | :core:model HistoryImport, :core:data RoomHistoryImport; HistoryImportTest (property tests) |
| Discarded | Why |
|---|---|
| Downloading with the app API’s token | there is no download endpoint in it |
glucoseHistory |
summaries, not readings |
| LibreLinkUp graph / logbook | a follower’s 12 h for someone they follow; the wearer’s own account follows nobody |
| Automating Download glucose data | its captcha exists to stop exactly that |
| Finger-stick, ketone and servings rows | Sukrara has no record for them (counted as left out) |
2026-11-11, after 0.12.0 (issues #176 and #177). The owner’s LibreView file was refused (“something about the dates”)
and they imported the earlier app’s export instead; and they signed in to LibreView three times (setup, to link a
sensor, the upload). The file reader only knew fixed two-digit layouts (MM-dd-yyyy hh:mm a), while LibreView writes
the account’s own locale: a US account writes one-digit 12-hour times (11-10-2026 9:15 PM), others year first with
AM / PM (Tidepool’s driver lists YYYY-MM-DD hh:mm A) or a localised AM / PM. The logcat of the owner’s phone no
longer held the import (the import didn’t log a refused file then; now it logs the layout with digits as 0).
| Added | Where |
|---|---|
Dates read whatever the layout: the numbers in any order a country uses, one- or two-digit hours, AM / PM in any language’s way (before or after the time), seconds, 21.15 / 21 h 15; which number is the day decided by the file (fits every row → keeps them in order → not in the future and nearest now → day first); the repeated hour of a clock change kept apart; a row without a time left out; ; / tab and UTF-16 files a spreadsheet saved |
history/FileDates.kt, HistoryCsv.kt; FileDatesTest, HistoryCsvTest (synthetic US 12-hour, Spanish p. m. fixtures), HistoryImporterTest (after the earlier app’s export: nothing twice) |
| A file it still can’t read says which date and what to do (download it again as it is, the earlier app’s export, Report the problem with the layout only) | ImportPage.kt (ImportProblem), HistoryImporter.kt |
One LibreView account for the app: signed in once (LibreLinkUp login), email + password kept only in the Keystore secure store (libreview-account), used by the sensor’s receiver ID, the upload (its own app login with them, again by itself when the token stops working) and Import history’s steps; one screen with Sign out (asks first; everywhere); a refused password asks again with the email filled in |
:core:data libreview/LibreViewLogin.kt, :sensor LibreViewAccount.kt, :feature:sensor LibreViewSignInScreen.kt, :integrations LibreViewUploader.kt / LibreViewPage.kt; LibreViewLoginTest, LibreViewAccountTest, LibreViewUploaderTest |
| Discarded | Why |
|---|---|
| Keeping the password out of the phone (the earlier rule: “sent once, never saved”) | the owner asked to sign in once; the Keystore-encrypted store already holds tokens of the same weight, and signing out deletes it |
| The upload’s own sign-in dialog and its “not your sensor’s account” question | one account for the app: the upload and the sensor can’t disagree any more |
| Taking over the uploading device when re-signing in by itself | it would cut off LibreLink / Juggluco without the person choosing: Take over stays a tap |
| Guessing the time zone of a file’s times from the readings already on the phone | LibreView writes no offset and the guess could shift a whole day of history; the phone’s zone is right unless the person travelled |
In Sukrara: glucose that never went up
Section titled “In Sukrara: glucose that never went up”2026-11-15. The owner: LibreView’s last glucose was 2 Nov while Sukrara said “Last upload 9 h ago”. Their LibreView
export by device: the earlier app’s device has 5-minute glucose from 17 Oct to 2 Nov 18:59 (the end of a 15-day
Libre 3 Plus) and treatments until 10 Nov; Sukrara’s device (from 11 Nov) has only treatments, no glucose at all. Since
2 Nov the owner wears a Libre 2 read through Juggluco. Both apps send glucose only from a Libre 3 they read
themselves (record numbers come from the Libre 3 serial and life count), so nothing went up, and nothing said so: the
status showed the last upload of any kind (treatments), the Glucose switch stayed on with “From a Libre 3 connected
to this phone”. Reading the code found the same silence on the Libre 3 path: a sensor registration LibreView refused
once (including status 20 “invalid session”, which this report saw on the first registration after a sign-in) held
that sensor’s glucose until the next sign-in, which a working token never needs, and a treatments upload cleared the
error.
Others: Juggluco shows “Success” while LibreView can still lack data (issue #271);
Abbott’s apps show no upload state at all; Juggluco’s help asks to check that the sensor is on the account and to wait
15–20 min (help, Libre 3 patch guide).
LibreView answers status 0 before it ingests, so the app can only compare what it has with what LibreView accepted.
| Added | Where |
|---|---|
A stall is measured from the data, whatever the cause: the phone’s newest own reading more than 2 h (or two intervals) newer than the newest 5-minute glucose LibreView accepted (glucoseUpToS) or than the switch-on → status “No glucose sent since …” and home’s LibreView isn’t getting your glucose banner (Fix → the page; closed per stall; not for no internet alone) |
LibreViewQueue.behind, LibreViewUploader.glucoseBehind, UploadStatus.Behind, BannerKind.ClinicUploadBehind; LibreViewUploaderTest, BannerSlotTest |
| The Glucose switch says at once when the readings come from Juggluco or another family | LvPageState.otherSource, LibreViewPage |
Registration never given up: retried with backoff, never in the cycle that signed in, every third failure after a new sign-in; status 20 “invalid …” is its own answer (LvPost.InvalidSession); glucose’s own error, kept until glucose goes up |
LibreViewUploader, LibreViewClient, LvSensorState.registerFailures |
| Discarded | Why |
|---|---|
| Uploading the Libre 2 from Juggluco’s readings in this round | another identity (LibreLink’s FSLibreLink.Android, its own device and record numbers) that has to be proved against a real account first, as this report did for the Libre 3: a separate investigation. Done in 41: a Libre 1 / 2 through Juggluco now goes up under Sukrara’s one Libre 3 identity, so there’s no second uploader |
| Telling the person to turn on Juggluco’s Send to Libreview | unverified whether its Libre 2 uploads and Sukrara’s treatments (Libre 3 identity) can share one account without the take-over fight above |
| A notification for the stall | the clinic gap is not urgent the way an alert is; home’s banner and the page are where the person looks, without a notification (CLAUDE.md “Complete flows”) |
| Backfilling 2–11 Nov | those readings were the earlier app’s and Juggluco’s (a Libre 2): Sukrara has no Libre 3 record for them. 41 added Send earlier glucose for the current sensor (3 Nov 14:39 on); 2 Nov 18:59 → 3 Nov 14:39 had no sensor |