PRINTDECKDOCS

Software

The iPhone and Apple Watch apps

The deck on the iPhone and the watch: the apps, the complications, the widgets, the Live Activity and the push messages.

An iPhone app and a watch app for the Printdeck. They use the API of the decks on the local network.

The apps read all decks every 5 seconds while they are open.

A print: the display of the printer, the keys, the layer and the model
A print: the display of the printer, the keys, the layer and the model
The files of the deck, newest first
The files of the deck, newest first
The setup: the deck, the watch and the push messages
The setup: the deck, the watch and the push messages
The start screen until the first reading of the deck
The start screen until the first reading of the deck
The progress of the print
The progress of the print
The file, the layers and the times of the print
The file, the layers and the times of the print
The menu of a print: Pause and Cancel
The menu of a print: Pause and Cancel
The question before a cancel
The question before a cancel

Install

Install the apps from Xcode. The deployment targets are iOS 17 and watchOS 11.

  1. Set DEVELOPMENT_TEAM in project.yml to your team ID. Run xcodegen in this folder.
  2. For a bundle prefix other than org.beetlebug.printdeck, change BUNDLE_PREFIX in project.yml and run xcodegen.
  3. Open Printdeck.xcodeproj. Choose the Printdeck scheme and your iPhone, and run.
  4. For the watch, choose the PrintdeckWatch scheme and the watch, and run. Turn on Developer Mode on the watch. The watch and the Mac must be on the same network.
  5. Open Printdeck on the iPhone. Tap Connect, then tap Allow on the touch screen of the deck. Add connects the next deck.
  6. To add the complication, edit the watch face and choose Printdeck.

If Xcode fails to find the watch, turn off Bluetooth on the iPhone for a minute.

If the deck is missing from the list, open By hand under Add. Type the address, and tap Ask the deck for a key. Or type the key from http://printdeck.local/system and tap Save.

Push messages

  1. On the iPhone, open the deck, then Menu > Notifications, and tap Pair for notifications. Each deck pairs on its own. With several decks the subtitle of a message is the name of the deck.
  2. Allow the notifications.
  3. The deck sends "This phone gets the messages of your prints."

Unpair removes the phone. Settings > Phones on the deck has the same list. Each message is encrypted for the paired phone. The relay and Apple see only the encrypted message (cloud/relay/README.md).

How the pairing works:

  1. The app posts its device token to the relay (POST /register), and gets a send token.
  2. The app makes an X25519 key pair, and pairs with the deck (POST /api/plugin/printdeck/push/pair). Both make the message key with HKDF-SHA256 (the salt is the device token, the info is printdeck push v1).
  3. The notification service extension decrypts the key e of each push (AES-256-GCM).

A build from Xcode uses the APNs sandbox. A TestFlight or App Store build uses production. PUSH_RELAY in project.yml is the URL of the relay.

Away from home

Sign in with passkey on the Projects tab signs in to printdeck.beetlebug.org with the passkey of the owner or of a member, the same passkey as the web site. iOS offers the passkeys of the iPhone and a security key, such as a YubiKey, over USB-C, Lightning or NFC. A key with no passkey for Printdeck sends no user handle, and the app shows "This key has no passkey for Printdeck." The token is in the keychain group, and a 401 asks for the sign-in again. An owner session works for 14 days.

When a deck does not answer, its card shows the live print of the deck from the projects of the session: the model, the progress and the time left. The app finds the print by printer_id of the deck (from /api/plugin/printdeck), or by the name of the printer when the deck has sent no ID. For the owner, the live record of each printer (live in GET /api/v1/printers) fills the card of a print with no project. A print of a project comes first, because it has the picture of the model. A member sees only the prints of the projects.

The sign-in needs the entitlement webcredentials:printdeck.beetlebug.org, so it works only in a build that is signed with the team of project.yml. The service serves /.well-known/apple-app-site-association for the app.

The routes of the service:

Projects

The app has two tabs: Prints, with the cards of the decks, and Projects. The Projects tab has the sign-in, and after it a card for each project with what it does now: the prints that run, the prints ready for pickup, the plates that wait and the files in the queues. A project shows its overview, as the web page has it:

Take photos keeps the camera open and sends each photo after it is taken: to the print on the page of a print, else to the project. A member changes only the notes of a print.

The routes: GET /api/v1/projects/<id>, PATCH /api/v1/projects/<id>/prints/<print>, POST /api/v1/projects/<id>/builds/<build>/plates/<n>/approve, reject and send, GET /api/v1/printers, and POST /api/v1/projects/<id>/photos with the upload to its grant and POST /api/v1/projects/<id>/photos/<photo>/done.

The queue

The deck screen shows the queue of the deck: the files in their order, each with its material and its time, and the total time. Up and Down move a file, and Remove deletes it from the queue. The app has no Start: only a press on the touch screen of the deck starts the next file. Away from home, a card shows the count of the files in the queue of its deck (owner), and a project shows its files in the queues.

At the end of a print with files in the queue, the deck sends "Next in the queue". A tap on a push message opens the deck screen of its deck.

The routes of the deck: GET /api/plugin/printdeck/queue, POST /api/plugin/printdeck/queue/<id>/move with {"by": -1}, and DELETE /api/plugin/printdeck/queue/<id>.

Network

The deck serves plain HTTP on the local network (NSAllowsLocalNetworking). The deck announces itself with Bonjour as _octoprint._tcp. The app saves its IPv4 address, because watchOS may fail to resolve printdeck.local. The address can have a port, as 192.168.1.50:8080.

API

The App Keys flow of OctoPrint gives the app its key, with no key:

All other requests have the header X-Api-Key:

Folders

Screenshots in the simulator

In a debug build, PRINTDECK_ADDRESS and PRINTDECK_KEY set one deck, and PRINTDECK_DECKS sets several, as TAZ|127.0.0.1:7361|key1,Phenom|127.0.0.1:7362|key2. PRINTDECK_SCREEN opens a screen: menu or cancel on the watch, deck, files, setup, camera or loading on the iPhone. The screens of a deck open the first deck. With xcrun simctl launch, add the prefix SIMCTL_CHILD_. The deck of printdeck app -sim reads its API key from OCTOPRINT_API_KEY.

License

The code in this folder is under the MIT License (LICENSE). The rest of the repository is under the AGPL. Shared/LCDScreen.swift is a port of deck/internal/lcd of the deck, by the same authors, under the MIT License here.