Skip to content

Remote Overrides Not Working in Dev #1536

Closed

Description

@gestrich

Describe the bug

Remote overrides do not work in dev. The device token is not being consistently uploaded to Nightscout leading to overrides failing.

To Reproduce

  1. Fresh install of Loop dev branch.
  2. Enter Nightscout credentials during onboarding.
  3. Agree to iOS prompt to allow notifications at end of onboarding.
  4. Add a few overrides to Loop and enact one of these overrides locally.
  5. Go on Nightscout and attempt to enact another override. An error "Could no find deviceToken in loopSettings".

Expected behavior

It is expected that you can enact overrides from Nightscout after agreeing to the prompt.

Phone

  • Hardware: iPhone XS
  • OS Version: 14.7.1

Loop Version

  • Dev - latest.

Activity

  1. gestrich commented on Aug 29, 2021

    @gestrich
    ContributorAuthor

    @ps2 Here is a write-up on what appears to be the problem. I can put up a pull request if you like but would like your feedback beforehand.

    1. LoopDataManager Currently Expects Device Token to be Persisted: In LoopDataManager.storeSettings(), the deviceToken is overridden by whatever is persisted in LoopSettings. Since LoopSettings doesn't persist the deviceToken, that is always nil. This was discussed in a possible solution in Store device token to LoopSettings #1494. That was declined though since the token should not be persisted per iOS guidelines.
    2. NightScout Uploader is Created Lazily: When onboarding, the uploader will be set to nil in its lazy getter. This is not set again until rebooting the app (since lazy). This leads to the upload failing when the notification prompt is agreed to during onboarding.
    3. registerForRemoteNotifications() only called during Onboarding: If you are offline during onboarding or setup Nightscout after onboarding, the deviceToken will not be pushed to Nightscout. Nothing seems to trigger registerForRemoteNotifications() later so there doesn't seem to be an opportunity to get the token again. Also, the token may change as discussed in the PR 1494, so it seems we need to allow the token to get updated. didFinishLaunchingWithOptions may be the place to put it per StackOverflow.
  2. gestrich commented on Aug 29, 2021

    @gestrich
    ContributorAuthor

    Here's how I'm handling these various issues in the remote bolus branch for now LoopKit/LoopWorkspace@17bb9b6

    • For number 1, I am using the token that gets fetched, rather than the token persisted at LoopSettings. Number 3 also helps with this to make sure we always fetch the token on startup. I did review Pete's suggested solutions in PR Store device token to LoopSettings #1494 but I think this change handles those same concerns.
    • For number 2, I removed the lazy getter. Instead I update the Nightscout uploader when the api key and url are set. This can be improved more by hooking into the flow in that class that sets all credentials. but I didn't want to spend a lot of time refactoring the setup of the uploader before any feedback. (Not sure if the case is handled of changing Nightscout credentials without reboot -- only if Settings get submitted when Nightscout service gets setup).
    • For number 3, I'm fetching the remote token on startup to ensure we always have a token. This doesn't handle the case of setting up Nightscout after onboarding but would be readily fixed with an app reboot for now.
  3. avouspierre commented on Aug 29, 2021

    @avouspierre

    I tried to modify the dev version with PR 1494 + your hack but always the same issue error. I tried to restart NS and re-compile Loop but no change. I seems unable to register the device token. Do I need to do a fresh install ?

  4. gestrich commented on Aug 29, 2021

    @gestrich
    ContributorAuthor

    @avouspierre This commit contains the updated solution LoopKit/LoopWorkspace@17bb9b6 Note there are changes to the NightscoutSerivce and Loop projects respectively.

  5. changed the title [-]Overrides Not Working in Dev[/-] [+]Remote Overrides Not Working in Dev[/+] on Aug 29, 2021
  6. avouspierre commented on Aug 29, 2021

    @avouspierre

    Thank a lot @gestrich . The patch is perfect and allows to do remote overrides with NS

  7. blameitonben commented on Aug 29, 2021

    @blameitonben
  8. Willbumster commented on Aug 29, 2021

    @Willbumster
  9. jonfawcett commented on Feb 20, 2022

    @jonfawcett

    Is this still the only fix for remote overrides in Dev?

    Symptoms: remote overrides don't do anything after Dev install. Locally set overrides also do not upload to NS Treatments table so they are not on the NS graph. I'm not sure if both of these are caused by the same issue since I haven't found mentions of the second. I haven't started my own debugging yet to figure out what's going on because I found this old issue.

  10. Trpl7ca commented on Feb 20, 2022

    @Trpl7ca

    I don't use remote overrides, but my local overrides have not been showing up either in NS while using dev or dash-integration.

  11. gestrich commented on Feb 21, 2022

    @gestrich
    ContributorAuthor

    I do not think this fixes the issue of overrides not showing on the Nightscout graph (missing the tape). This fix is in the remote bolus branch. I'm not sure of other fixes or what has made it into dev.

  12. gestrich commented on Feb 27, 2022

    @gestrich
    ContributorAuthor

    I noticed that @ps2 has fixed #2 mentioned above (NightScout Uploader is Created Lazily) in dev with the below commit. I'm not sure about the other issues I mentioned in this PR.

    commit eb97cb140a7ddc27ed497ab414c30cfba44a68d1
    Author: Pete Schwamb <pete@schwamb.net>
    Date:   Mon Feb 21 20:39:38 2022 -0600
    
        Adding fetch of therapy settings, and fixing bug with uncalled completion handlers
    
  13. ps2 commented on Feb 28, 2022

    @ps2
    Collaborator

    #1614 should fix the token uploading issue and the issue with not calling registerForRemoteNotifications on startup.

  14. ps2 commented on Mar 4, 2022

    @ps2
    Collaborator

    I believe the issues described here are now fixed. There remain reports of Loop overrides not being triggered even when the notification arrives and is displayed on the user's phone. As best I can tell, this seems to be an issue with dasd not allowing Loop to be launched for some reason, and this behavior appears to be resolved with iOS 15.4 (beta).

  15. jgefaell commented on Mar 6, 2022

    @jgefaell

    Prior to this pull and build from today I was unable to enact remote overrides from Nightscout. As of this code it is working as expected. I can enact a remote override in Nightscout and it is invoked and appears in the Loop app. Before I would enact the override and nothing would happen on the app.

    I'm not sure if this observation is part of this issue? I couldn't find another and hadn't opened one yet.

    * gitRevision: 7c6b7c1
    * gitBranch: N/A
    * workspaceGitRevision: 8d9072c
    * workspaceGitBranch: dev
    
  16. github-actions commented on Aug 29, 2023

    @github-actions

    This issue is stale because it has been open for 30 days with no activity.

  17. github-actions commented on Sep 13, 2023

    @github-actions

    This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions