nightscout / Trio

MIT License
45 stars 125 forks source link

[Bug] SAGE not updating in NightScout #269

Open TymHuckin opened 1 month ago

TymHuckin commented 1 month ago

image

I've noticed that the sensor is doesn't always update in Nightscout. I change the sensor yesterday (G6/Anubis) and it's still showing as over 13 days old. Had this before but then suddenly it updated. 0.1.0 56a3f87 updated on my phone 4 June 2024.

LiroyvH commented 3 weeks ago

Can confirm, same issue here.

aug0211 commented 3 weeks ago

Noticed this with G7 as well.

Let’s all observe closely and gather data on our next sensor changes to provide details and logs so we can help get to the bottom of this.

aug0211 commented 3 weeks ago

Observed again today.

  1. Existing G7 had issues and stopped getting readings
  2. Inserted a new sensor for a “background warmup” while hoping the old sensor would come back online
  3. At 25m into “background warmup”, old sensor had still not come online - decided to cut over to new sensor
  4. Used the “replace sensor” option in G7 app
  5. Scanned QR code in G7 app to pair new sensor
  6. Confirmed in G7 app that sensor was already applied
  7. “Forgot” old sensor in iOS Bluetooth settings
  8. G7 app picked up new sensor
  9. Trio began receiving new readings
  10. Observed that SAGE in Nightscout was not updated
  11. Observed that no “CGM Sensor Start” (or similar) event had been created in Nightscout by Trio
  12. Manually (via Shortcut) added “CGM Sensor Start” event to Nightscout via iOS shortcut
  13. Observed SAGE updating in Nightscout after manually running the shortcut
bjornoleh commented 3 weeks ago

The sensor details are stored in a file on your phone, probably in the Trio/monitordirectory. Could you please look that up and post it here?

aug0211 commented 3 weeks ago

Definitely, will do when kiddo is home and I can look at his phone - most likely this evening.

bjornoleh commented 3 weeks ago

For some background, SAGE uploads to Nightscout was implemented by merging this branch:

https://github.com/trixing/freeaps/commits/patch/sage/

After some refactoring, SAGE was later fixed for G6 by this PR:

https://github.com/Artificial-Pancreas/iAPS/pull/212

The fix for G7 is in here somewhere:

https://github.com/nightscout/Trio/commit/cf5d5621785d44369d54f69a5936b0646d000bed

Then apparently SAGE was broken by a refactor after the transition to submodules in Trio, where relevant files were removed:

https://github.com/nightscout/Trio/commit/47fa01786a7457b30e2307a11e02908719fa0aa9

Later, SAGE was fixed for Libre, but not Dexcom: https://github.com/nightscout/Trio/commit/15713b0f1d5d97cec8273df9edfa02315225a2b0

I assume we would need a similar fix for G6 and G7 SAGE to be updated in NS.

I suspect @avouspierre is already looking at this, but wanted to include a tag, as he fixed this for Libre :-)

aug0211 commented 3 weeks ago

Looks like Trio sees a sensor from ~3 sensors back (yes, we've had multiple fail early so changed before 10d).

That may be when we swapped from using xDrip4iO5. Or maybe completely unrelated - I can't pinpoint exactly when we switched over.

image

bjornoleh commented 3 weeks ago

@aug0211 , only G6 sessions are written to this file, xdrip sessions are not.

If you look at my sleuthing above, you can track down the deleted files that broke this:

FreeAPS/Sources/APS/CGM/DexcomSourceG5.swift FreeAPS/Sources/APS/CGM/DexcomSourceG6.swift FreeAPS/Sources/APS/CGM/PluginSource.swift

Some change likely broke this for G7 at the same time, I have not pinpointed that.

The fix for Libre can probably be used as a model to fix this for Dexcom again.

aug0211 commented 3 weeks ago

Ooh interesting, good finds. Was so intent on getting the requested data uploaded I missed your findings!

I don't think it's accurate that only G6 gets added to that log though, otherwise my log should be blank (using G7 exclusively for some time).

Either way it seems like the fix is somewhere in this area you've identified. Nice!

bjornoleh commented 3 weeks ago

I meant exclusively Dexcom sessions (probably including G7), and not xdrip :-)

LiroyvH commented 3 weeks ago

Can confirm, using G6 btw, that the 'cgm-state.json' file has not been updated for me for the new sensor. Last sensor showing up is from 04-May-2024. I changed it on May 31st.

snickerdoodleparent commented 20 hours ago

+1 here -- for G7. An install of Trio on a new phone June 12, no cgm-state.json file was created. I've tried scanning for new sensor, deleted CGM and added it again, SAGE does not update and cgm-state.json doesn't exist.