Developers

The app author’s guide

What a finished app looks like: where it runs, how it talks to the device, what it asks for, and what it must never do with a stranger’s text. Each rule comes with the reason. Community apps are held to this list, so it is a checklist rather than a feeling.

Before you submit

  1. It is a folder: index.html, app.json, pocket.js if it uses it, and nothing it doesn’t need.
  2. app.json names the API version you tested on and only the verbs the app needs.
  3. Every URL to its own files is relative. The folder can be renamed and nothing breaks.
  4. Everything is inline: no CDN, no web fonts, no fetch beyond the device.
  5. Usable at 360 pixels wide with a thumb, inside a captive-portal browser.
  6. On a 401 it says in words what needs the owner. Never a raw status code, never silence.
  7. Nothing a visitor typed goes through innerHTML.
  8. Empty, loading, error and full each look like something.
  9. A title and a one-line description; credits for anything borrowed.
  10. Tested on a real board at the version it declares. A screenshot to go with it.

Then open a pull request adding the folder under examples/ and an entry in examples.json, or post the zip in the Discord.

The shape of an app

An app is a folder on the card with an index.html and an app.json beside it. Its data sits in the same folder. Its identity is the folder name: delete the folder and the app and its data are gone, copy it and you have two, rename it and nothing breaks — because the manifest names no folder and the app uses relative URLs.

The address is the folder: /whiteboard/ serves /whiteboard/index.html, and /whiteboard redirects there so relative URLs resolve inside the folder. The owner can make any app the homepage, and / then redirects to it.

A single .html file still works: dropped on the admin page it is served read-only at its own path, and the admin page offers to give it a folder. But a folder is what lets visitors write, and what makes the app portable.

The manifest

{
  "api": 1,
  "title": "Pirate box",
  "paths": {
    "/":          { "browse": "everyone", "upload": "everyone", "delete": "everyone" },
    "/private/":  { "read": "owner" }
  }
}
KeyMeaning
apiRequired. The lowest API version the app needs. Declare the version of the device you tested on; GET /version tells you.
titleOptional. Shown on the admin page and by launchers. Defaults to the folder name.
pathsOptional. Keys are paths inside the folder; a key ending in / covers everything under it, and the longest matching key wins. Values map a verb to the lowest role that may do it.
gpioOptional, true to ask for the pins. A request, not a grant: the owner allows it once from the admin page.

Verbs: read (open a page or file), browse (list the folder), upload (add or overwrite, including making folders), delete. Roles: everyone and owner. Anything not mentioned defaults to read for everyone and every other verb for the owner, so an app that keeps no files needs only api.

The words moderator, user and $user are reserved for a future identity design. A manifest naming them, or any verb or role the firmware doesn’t know, is reported as needing a newer API version and grants nothing — that is what keeps the grammar safely open.

Limits: 32 apps per card and 8 paths keys per app on ESP32-S3 (6 and 6 on ESP8266); keys up to 32 characters; folder names up to 24; manifests up to 2 KB. A folder past the app cap still shows as an app in the admin page’s file list, marked as waiting for room, and behaves as a plain folder until an app is deleted. Four files are always the owner’s to write, whatever the manifest says: app.json, .app-overrides.json, index.html, and /.settings.json at the root. The names app.json and .app-overrides.json are taken; leave them alone.

pocket.js

Every example ships with pocket.js beside its index.html, and yours can too: it is one file with no dependencies. It knows the app’s folder, talks to the device on the app’s behalf, and turns every refusal into a sentence a person can read.

<script src="pocket.js"></script>
<script>
  Pocket.readJson('entries.json', [])            // null-safe: [] on a first visit
    .then(render);
  Pocket.write('entries.json', entries)          // Blob, string or JSON
    .catch(err => { statusEl.textContent = err.message; }); // "Saving entries.json needs the owner of this device to allow it."
  Pocket.list()                                   // [{name, size}], the app's own files left out
  Pocket.remove('old.txt'); Pocket.mkdir('photos');
  Pocket.pin.read(2); Pocket.pin.write(2, { mode: 'OUTPUT', value: 1 });
  var sock = Pocket.socket(onMessage, onStatus);  // reconnects on its own; sock.send(text)
  Pocket.version(); Pocket.requires(1); Pocket.app(); Pocket.allows('delete');
  Pocket.signIn(password)                         // the owner, for this page: later calls are signed
    .then(() => Pocket.readJson('admin/report.json')) // a path app.json keeps with "read": "owner"
    .catch(err => { statusEl.textContent = err.message; }); // "That password didn't work."
  Pocket.isOwner(); Pocket.signOut();
</script>

Every call returns a Promise and sends X-Requested-With, so a 401 reaches your code as an Error with a readable message instead of the browser’s own password box. Nothing in it is required — the endpoints are plain HTTP — but the examples are what community apps are compared against, and they all use it. The developer guide documents every function.

Where it runs

On a phone, in a captive-portal browser, over a slow link, and usually without internet. On the device’s own network there is none; on a home network there may be. Design for none.

  • One folder, everything inline: no CDN, no fonts from the web, no fetches beyond the device.
  • A size budget. An index.html of tens of kilobytes is fine; a megabyte is not, over a microcontroller’s radio.
  • Usable at 360 pixels wide with a thumb, readable in the portal’s cramped viewport. Fullscreen and the clipboard may not exist there.

Talking to the device

  • Relative URLs for its own files: fetch('board.json'), never fetch('/whiteboard/board.json'). Uploads go to POST /files?path=<its folder>; read the folder from location.pathname.
  • GET /version if it wants to check the version. GET /apps for its own resolved rules, if it wants to hide controls a guest can’t use.
  • Poll sparingly; use the WebSocket for anything live. Check GET /fs-info before a large upload.
  • A microcontroller is on the other end: one request at a time for anything heavy, no request storms on load.

Permissions

  • Declare the least it needs in app.json. A guestbook needs upload; it does not need delete.
  • On a 401, tell the person what they need in words — “Deleting needs the owner’s password” — and offer the sign-in: a password field wired to Pocket.signIn(), as the Owner page example does. Never retry silently, never fail silently, never show a raw status code.
  • The owner may narrow what you asked for from the admin page. Read GET /apps if the app wants to reflect that up front.

Strangers’ text

  • Nothing a visitor typed goes through innerHTML. Anyone on the network can reach the page, and an app that stores text serves it back to everyone.
  • Nothing on the device is private unless the manifest says so, and even then not from someone holding the card. No secrets in files, ever.

Data

  • Its files beside index.html, never at the root.
  • A save that is read back and compared (the whiteboard does this) beats one that is assumed.
  • Last-writer-wins is the device’s only concurrency model. Say so, or design around it.

States

Empty, loading, error and full each look like something. A first visit with no data is a designed screen, not a blank one.

Polish

  • A title and a one-line description in the manifest, for the admin page and the apps page.
  • Credits where code or content came from elsewhere, in the format examples.json already uses.
  • It works on both boards, or says which it needs (sdCard is already a flag on the apps page).

The apps page is the reference: every example there follows this guide. The developer guide has the endpoints, and build with AI hands all of this to an assistant in short form.