Skip to content

Add remote commands via APNS for Loop users #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 39 commits into
base: dev
Choose a base branch
from

Conversation

codebymini
Copy link
Collaborator

@codebymini codebymini commented Jul 9, 2025

Summary
This commit implements remote commands via APNS (Apple Push Notification Service) for caregivers to Loop users, adding a new communication method for sending commands to Loop devices.

Key Changes
🆕 New Features:
APNS-based remote commands - New communication channel for Loop users
TOTP authentication - Added Time-based One-Time Password (TOTP) generator for secure authentication
QR code scanner - Simple QR code scanning functionality
Override presets - New system for managing and applying override presets
Enhanced remote settings - Improved remote configuration management

📱 New Views & Services:
LoopAPNSBolusView - Remote bolus commands interface
LoopAPNSCarbsView - Remote carb entry interface
LoopAPNSService - Core APNS communication service
LoopAPNSSettingsView - APNS configuration settings
OverridePresetsView - Override preset management

🗑️ Removed:
Legacy Loop Nightscout remote views (LoopNightscoutRemoteView, LoopOverrideView, LoopOverrideViewModel)

�� Infrastructure:
Updated project configuration and dependencies
Enhanced storage system for new remote features
Added necessary permissions and capabilities to Info.plist
Validation of Loop APNS key format

Introduces a more robust and secure remote command system
Replaces the previous Nightscout-based remote functionality with APNS-based communication
This represents a significant architectural improvement for remote Loop control, moving from Nightscout-based commands to a more direct and secure APNS-based approach.

@codebymini codebymini force-pushed the loop-remote-commands-apns branch 2 times, most recently from 1db6ba2 to d5ce515 Compare July 9, 2025 22:48
@bjorkert bjorkert requested a review from marionbarker July 17, 2025 15:00
@marionbarker
Copy link
Collaborator

The app stops responding when modifying various rows in the Configure Loop APNS Settings section.

Enclosed is the most recent ips file from my iPhone 15 pro.

Loop Follow-2025-07-17-154247.ips.zip

Once configured, the remote commands worked well. I'll do more testing after the crash is fixed and the branch conflicts are resolved.

@marionbarker
Copy link
Collaborator

I tested again. (I used the latest commit, d593cce, merged dev to it and resolved the conflict).

I can select all and remove each of the items in:

  • LOOP APNS KEY ID
  • LOOP DEVELOPER TEAM ID
  • LOOP APNS KEY

I can then add each item back in.

I can use the Camera to rescan the QR code URL if the row is already filled out.

  • If I clear that row - the app hangs, when I restart, it is cleared
  • If the row is cleared and I use the camera to scan, the app hangs but when I restart, the row is filled in

With this crash I am getting ips files on the SE 2nd gen but not on the iPhone 15 pro, even though they both act the same. Here's one:

@codebymini codebymini force-pushed the loop-remote-commands-apns branch from 95183f5 to 33b2054 Compare July 18, 2025 22:06
@marionbarker
Copy link
Collaborator

The notes now say that Nightscout Remote is no longer supported for Loop.

If that is the decision, I understand it. However, Nightscout should not be provided as an option on the Remote Settings screen if a Loop URL is detected.

@bjorkert
Copy link
Contributor

I just updated the RemoteSettingsView to conditionally enable the Nightscout remote type based on viewModel.isTrioDevice, ensuring it's only an option for Trio users.

@marionbarker
Copy link
Collaborator

Test Issues

iPhone 15 observing a Loop URL
LoopFollow commit a1d17ce

When an override fails with the message "Failed to activate override invalid Nightscout URL", it needs to be a modal alert.

  • I have a long list of overrides, tapped the top one and app seemed non responsive
  • I just had to scroll to the bottom of the screen to get see that error message

@marionbarker
Copy link
Collaborator

Test Summary

If there is a network error - I think message should be network error - check before sending again and return to main screen

Is there a way to make sure the NS URL and the TOTP are from the same site? And if they don't match - warn the user?

Test Details

This is with SE 2nd gen phone running iOS 18.5:

I have my APNS credential entered.
I have NS test site 3 entered as URL (Loop site)

As an experiment, I changed the QR Code URL to point to a different site and confirmed the value updated

Then I issued an override

  • the overrides shown are from site 3 (not the new site)
  • the override selected went to site 3 (not the new site)
  • the NS URL continued to point to test site 3
  • remote command for bolus and carb claimed success on LoopFollow phone but stopped working on Loop phone
  • I think this is OK: Overrides work without need for the TOTP, only bolus and carbs need that
  • But it would be nice if the status ok went to red if the NS URL and the QR don't come from the same site.

Then I changed back to the QR code URL that goes with test site 3

  • remote command went through to Loop phone (but LoopFollow phone got a network error and stayed on carb screen) (add to summary)

@bjorkert
Copy link
Contributor

Updated the Override Presets view to improve user feedback and align with Trio Remote Control

Changes:

  • Replaced inline success/error messages with alert dialogs (they were getting lost at the bottom of long lists)
  • Added confirmation dialogs before activating/cancelling overrides
  • Success alerts now auto-dismiss the view for a cleaner flow
  • Aligned the UI/UX with the existing TRC OverrideView implementation

@marionbarker
Copy link
Collaborator

Design comments (my opinion only, for consideration)

On the main Remote Settings screen, there is a debug / info box at the bottom:

  • having the Current TOTP Code on the main Remote Settings screen seems appropriate
  • what about moving the rest of that to the Configure Loop APNS Settings screen instead

On the main Remote Settings screen, the Setup Complete turns green when all the rows on the Configure Loop APNS Settings screen are filled in - whether they are correct or not

  • I deliberately modified the APNS KEY and the Setup Complete remains green
  • When I try to send a remote with the "bad" key, I get the new error: Failed generating JWT token, check APNS Key ID, APNS Key and Team ID
  • Can Setup Complete be tested before being turned green? And if that error occurs, turn it to incomplete again?

The APNS settings are not Loop specific.

  • Perhaps remove LOOP from the rows in the Configure Loop APNS Settings screen for APNS and Developer.
  • Perhaps rename the screen to APNS and Loop Settings - because the QR image must be obtained from the Loop phone.

@codebymini codebymini force-pushed the loop-remote-commands-apns branch from d4e45e0 to 770caf5 Compare July 28, 2025 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants