Skip to content
miblo

SDK

The Miblo App screen: page, cards, frames, layers and peek

The Miblo App screen: screen.page, data and quality and, the old deprecated way, card, frame, layer, show, peek and clear, the flash wear rules and each error.

The App screen

Miblo Desk's screen rotation (Overview, Limits, Sessions) has the App screen, which your program draws. It needs Miblo 1.30 or newer on the computer and on Miblo Desk: an older gadget gets nothing but its update (miblo status and Miblo Hub say so), and in gadgets it answers offline. The screen can be:

  • a web page (Miblo 1.45, the standard way): HTML, CSS and JavaScript that Miblo Hub draws on the computer (page());

The next three are the old way, deprecated since Miblo 1.45 but working:

  • a card: a title and up to four items (a big number, a ring, a bar, a line of text, a tiny chart), drawn by Miblo itself with its own fonts and colours;

  • a frame: a whole 240x240 image, kept in Miblo's flash;

  • a layer: the card drawn over a frame. It is the right way to a beautiful screen: the background goes once, then only the number changes.

Rules that always hold:

  • Miblo comes first. Alerts, "needs you", setup and codes always draw over the App screen.

  • Your program's name is always on the screen, so the person knows whose it is. It is the tool you pass to screen().

  • Each program has its own screen. With several apps, the App screen shows one at a time and moves to the next after each one's own time (miblo apps dwell <id> <seconds>, 5 to 120; 15 s by default). One time per app, no global one.

  • The limits are this computer's, not your program's. Every rate on this page (cards, show, peek, request, frames, animations) is one bucket in the bridge, shared by every program and every official app that is turned on. Run two examples back to back and the second may get rate_limited: wait retryAfter seconds.

  • When the apps show is the person's choice (miblo apps when, Miblo Desk's page or Miblo Hub): when nobody is working (the default: after 60 s with no AI session running or waiting), always in the rotation, when an app asks for the screen (only when your program calls request(), below) or only when I ask (pinned or a peek).

screen()

const screen = miblo.screen({ tool: 'steps' });

tool follows a session's tool rules (1 to 20 characters, not a Claude Code name, no leading _). Every write carries the x-miblo-sdk-tool header; the package sends it for you. A program's screen is its declared app's (see Apps), else its name's.

page(), data() and quality()

Since Miblo 1.45, the standard way to draw the screen is a web page: Miblo Hub renders it at 240x240 on the computer and streams only the pixels that changed to the Miblo Desk. The full guide, with the manifest, window.miblo and the limitations, is in Page Desk apps.

TypeScript
await screen.page('weather.html', { data: { city: 'Recife', temp: 29 }, quality: 'auto', max: 'high' });
await screen.data({ city: 'Recife', temp: 30 });   // the page hears it with miblo.on('data')
await screen.quality('ultra');                     // or the page itself: miblo.quality('ultra')
await screen.clear();
  • page(file, { data, quality, max }): file is a .html file relative to the program's working folder (an installed Desk app's page is always a file of its own package); its CSS, images, fonts, scripts and videos sit next to it and load by relative path. data is JSON, at most 16 KB, and reaches the page as window.miblo.data. It returns { ok, page, quality, max, current }.

  • data(obj): new JSON for the page (at most 16 KB); the page hears it with miblo.on('data', fn).

  • quality(q, { max }): 'auto' (the default), 'verylow' (30 fps target), 'low' (25), 'medium' (20), 'high' (15) or 'ultra' (about 10). auto starts at medium, steps down when the stream stalls and up after about 5 s clean, never above max.

  • New error: no_page (status 409), when data() or quality() come before page().

For now only the TypeScript package (@miblo/status) has these methods; Python does not yet, but the POST /sdk/v1/screen/page route (and screen/data and screen/quality) is in the reference.

card()

await screen.card({
  v: 1,
  title: 'Steps',
  icon: 'steps',
  items: [
    { t: 'big', value: '8,432', label: 'today' },
    { t: 'ring', value: 0.61, label: 'goal 14k', color: 'amber' },
  ],
});

The card's fields

FieldRules
vAlways 1.
titleOptional, up to 24 characters, at the top of the screen (your program's name follows it).
items1 to 4 items, top to bottom.
iconOptional, a name from the set below. A name outside it is drawn as none.
bgOptional, "frame:0" to "frame:3": draws the card over that frame (a layer). layer() fills it in for you.

The whole card is at most 1024 bytes. Unknown fields are dropped; an unknown item type refuses the card.

The items

tFieldsfx it takesHow it shows
bigvalue (text or a whole number, up to 10 characters, required), label?, color?count, pulse, blink, rainA big number with a caption.
ringvalue (0 to 1), label?, color?; live: id, range?, livesweep, orbit (+ speed 0 to 360), pulse, blink, rainA ring that fills up, like the limits' rings.
barvalue (0 to 1), label?, color?; live: id, range?, livesweep, pulse, blink, rainA bar that fills up.
textvalue (up to 40 characters, required), color?ticker, pulse, blink, rainA line of text.
sparkvalues (2 to 24 numbers), label?, color?; live: id, range, live (and values becomes optional)slide, pulse, blink, rainA tiny line chart.
meshmesh ('cube', 'icosphere', 'miblo' or your own vertices), shading?, speed?, light?, color?spin, tumbleA 3D model the Miblo turns; one per card, never in a row.
rowitems: exactly 2 of the others (never a row or a mesh)noneTwo items side by side.
  • label: up to 16 characters.

  • fx: one word, an effect the Miblo computes itself (no file, no flash write). A word the item does not take refuses the card (bad_request). What each one does and costs, and the mesh fields, are in the Screen animations guide (chapter 5).

  • id, range and live: a live chart (Miblo 1.27), fed by push(): see below.

  • color: amber, blue, green, red, white or grey. Without one, each kind has its own (big white, ring coral, bar violet, spark blue, text grey). There are no hex colours in v1.

  • icon: steps, heart, water, coffee, sun, moon, cloud, bolt, check, star, clock, calendar, chart, music, mail, code.

How text is handled

  • Runs of spaces become one, invisible, control and bidi characters are removed, the ends are trimmed and each string is cut to its limit.

  • Miblo's phrases are refused (bad_request): a string that starts like one of Miblo's notices (approved:, phone:, miblo:, allow?, task: and their Portuguese forms) or uses Miblo Desk's alert phrases ("NEEDS YOU", "Asked permission", "Asked a question" and translations). The App screen never passes for a Miblo alert.

  • The field at fault comes in field, shaped like items[1].items[0].value.

A card's life

A card lives in Miblo Desk's memory, not its flash: changing it every minute costs nothing. When the Miblo restarts, the bridge sends the card again within 15 minutes. A card not refreshed for 24 hours is dropped (the screen shows "sem dados" with your program's name).

Returns { ok, current, delivered, gadgets }: current says whether your screen is the one on the App screen right now. Cards: 2 a second, bursts of 5.

push()

A chart that changes all the time (CPU, audio, a sensor) has two modes since Miblo 1.27. In near real time, the value travels with each card and the item's fx animates the change on the Miblo: simple, but every card is one request that costs Miblo Desk 40 to 400 ms, and an item with an effect reaches about 10 fps on a plain card (5 under an animation). In the fluid mode, the item declares live and the samples go through push(), at any rate you like:

await screen.card({ v: 1, title: 'CPU', items: [
  { t: 'ring', id: 'cpu', value: 0.4, range: [0, 100], label: 'now', live: { hz: 10, seconds: 3 } },
  { t: 'spark', id: 'hist', range: [0, 100], label: 'last 6 s', live: { hz: 10, seconds: 3 } },
] });
screen.push('cpu', 42.5);                // or screen.push({ cpu: 42.5, hist: 42.5 })

The package keeps the samples with their time and sends them to the bridge every 500 ms (or every 32 samples). The bridge gathers them in batches of seconds (3 s): it resamples the window to hz × seconds values, quantises each one within the range and sends one request per batch to the Miblo, which plays the batch on its own clock, at 24 to 30 fps, redrawing only the chart's rectangle.

The buffer is necessary: the Miblo plays only when it holds one whole batch and the next is already on its way. It costs a delay of 3 s, and that is compensated because the next batch is loaded behind the scenes while the current one is being shown: playback never waits for the network. A late batch holds the last sample (late); two batches in the queue drop the oldest.

  • live: { hz, seconds }: hz from 1 to 30 (default 10), seconds from 1 to 5 (default 3). On spark, ring and bar only, and at most 2 live items per card (outside or inside a row): a third is refused (live_too_many). fx on a live item is ignored.

  • id: 1 to 16 characters [a-z0-9_-], unique in the card, required with live: it is the key push() uses.

  • range: [min, max]: finite numbers, min < max; required on a spark, [0, 1] by default on a ring and a bar. The samples are quantised within it.

  • One batch per card: the live items of a card share the same seconds (a different one is refused, field items[1].live.seconds), and their hz × seconds add up to 180 at most (two items at 30 Hz × 3 s are; 30 Hz × 5 s twice is refused).

  • push() up to 60 times a second per id (faster is coalesced). The package sends what is waiting every 500 ms or 32 samples, as POST /sdk/v1/screen/live with 1 to 128 samples, each at most 60 s old; the bridge takes 10 of these a second (bursts of 20) and answers { ok, accepted, unknown } (unknown: ids your current card has no live item for, dropped). One batch per Miblo every seconds, up to 1 KB. Nothing goes to the flash.

  • push() never throws: a flush the bridge refused goes to screen({ tool, onPushError }) (Python: screen(tool, on_push_error=...)), else it is dropped. await screen.flush() sends what is waiting now and throws what a background flush would have reported.

  • screen.status() carries live: one entry per id, with i and r (its place in the card), hz, seconds, seq, value (the latest sample), buffered (batches in hand, 0 to 2), playing, late and real: { fps, drawMs }, what the Miblo measures. stop(), clear() and a new card without the id end the stream.

The Screen animations guide has the chapter "Live charts: two modes", with a recipe and the table of which mode to pick; the Desk App Store's Demo ao vivo app shows both side by side.

frame()

A 240x240 image in one of the 4 slots of Miblo's flash.

import fs from 'node:fs';
await screen.frame(0, fs.readFileSync('background.png'));

What you can send:

  • a PNG (8-bit, RGB or RGBA, not interlaced, up to 4096 a side and 4 million pixels in all): it is fitted into 240x240 keeping its proportions;

  • raw RGBA pixels: { rgba, w, h } (TS, with a Uint8Array) or {"rgba": bytes, "w": ..., "h": ...} (Python);

  • a ready MFRM1 file (Miblo's format).

The package sends a PNG or RGBA pixels as base64 inside a request of at most 1 MiB, so in practice a PNG file must stay under about 760 KB and raw RGBA under about 196,000 pixels (443x443); past that the answer is too_large (413). Send a 240x240 PNG and none of this matters.

The computer converts the image to at most 64 colours, encodes it by rows and checks it all before sending; no other software is needed. SVG or HTML you render yourself (a canvas, sharp, resvg...) and send the PNG. A background of flat colours and text takes 5 to 30 KB; a photo usually goes over 60000 bytes after the reduction and is refused with its size (too_many_colours).

Returns { ok, slot, bytes, colours, delivered, gadgets }. An upload may take up to 60 s (the file goes to each gadget in chunks).

Flash wears out

Miblo's flash takes a limited number of writes, and a frame is written to it on every upload. So:

  • each slot takes 1 write every 10 s and 100 a day (rate_limited with retryAfter, checked on the computer before anything is converted or sent); the count survives a restart;

  • what changes goes on the card, not the frame. A layer redraws the card without writing anything;

  • a damaged or incomplete frame is deleted, never drawn.

Slots are shared

The 4 slots belong to every program. A slot is the program's that wrote it until it lets go (removeFrame(), clear()) or its screen goes. Writing another program's slot gives slot_taken, with the owner's name in owner.

layer()

The card drawn over a frame: write the background once, then only send cards.

await screen.layer(0, { v: 1, title: 'Steps', items: [{ t: 'big', value: '8,432', label: 'today' }] });

It is card() with bg: "frame:0". Design the background leaving room for the items: the card's layout is fixed per item count.

A card is drawn over a frame only when it says so (bg: "frame:N"): a frame in a slot alone does not show. The same holds for an app's run() that returns a frame: the runner writes the picture, and the card it returns needs bg: "frame:N" with the same slot.

show()

Pins your screen: it stays on the App screen (no rotation) and Miblo Desk stays on the App screen, like miblo mode app. show(false) unpins it.

await screen.show(true);

Returns { ok, shown, delivered, gadgets }. Once every 10 s, for all programs together.

A pin holds the screen for everyone: while your screen is pinned, another program's animate() gets anim_taken (retryAfter 60). Unpin (show(false)) when you are done, especially between two examples.

peek()

"Look now": the App screen comes to the front for 1 to 10 seconds (default 10), unless Miblo is alerting. For the moment that matters (bitcoin moved 5 %, the build broke).

await screen.peek(10);
  • It needs a card first (no_card).

  • Once every 10 minutes per program, and at most one every 10 s (bursts of 3) for all programs together (rate_limited with retryAfter).

  • It brings your screen forward first, unless another one is pinned.

Returns { ok, seconds, delivered, gadgets }.

request() and release()

Since Miblo 1.29. "I need the screen": your program asks for the App screen for its own time (5 to 120 seconds; without seconds, the time the person gave the app, 15 s by default), for the moment that matters (a goal, a meeting in 5 minutes), only if nothing important is happening: no AI session waiting on the person (a permission, a question), no alert of Miblo's or of another app's on the screen. A session merely running does not stand in the way.

const r = await screen.request({ seconds: 30 });
if (!r.shown) console.log('no screen:', r.why);

The answer is honest, never a guess: { ok, shown: true, seconds, delivered, gadgets } when your screen is on the Miblo, or { ok, shown: false, why, seconds, gadgets } with why:

whyWhat happened
waitingAn AI session needs the person right now
alertAn alert (Miblo's or an app's) is on the screen
manualThe person chose "Only when I ask"
takenAnother app holds the screen (pinned, or it asked first): owner and retryAfter
hiddenThe person turned your app's screen off ("Show the screen on Miblo")
refusedThe Miblo itself said no (it was busy with something of its own)
offline, no_gadgetNo Miblo took it (offline, or none paired)
  • It needs a card first (no_card). Send the moment's card, then ask for the screen.

  • One app at a time; the same program may ask again only 60 s after its last hold ended (rate_limited with retryAfter). Asking while you hold the screen answers the seconds left (held: true), never extends it.

  • The rotation waits; when the time is up (or at release()), the app whose turn it was comes back. screen.release() returns { ok, released }.

  • It works whatever the person chose, except only when I ask; with when an app asks for the screen, it is the only way the apps show.

  • status() says request: { seconds, until } while your screen is there on a request (null otherwise).

clear(), removeFrame() and status()

TypeScriptPythonWhat it does
screen.removeFrame(slot)screen.remove_frame(slot)Deletes one of your slots: { ok, slot, delivered, gadgets }.
screen.clear()screen.clear()Takes your screen off: its card, your slots and your pin. miblo screen clear takes all of them.
screen.status()screen.status()Your screen (below).
screen.budget()screen.budget()What your screen costs the Miblo: the same as status().budget.

status() answers { card, frames, shown, current, area, allowed, rotation, request, anim, live, budget }:

  • card: your card as the bridge keeps it (with tool), or null; frames: your slots, [{ slot, bytes, at }] (at in epoch seconds);

  • shown: pinned; current: your screen is the one on the App screen now; rotation: the seconds an app shows when it has no time of its own;

  • area: { y, h }, the part of the 240x240 screen your content gets. It is { y: 0, h: 240 } unless the person keeps the limits strip on top ("Always show the limits on top"): lay your background out inside it;

  • allowed: false when the person turned your app's screen off ("Show the screen on Miblo"). Your app keeps running for its alerts, your card is kept but never shown, and frame(), animate(), peek(), show() and request() answer 200 with hidden: true and nothing delivered. Send an alert instead of drawing the moment;

  • request: { seconds, until } while a request of yours holds the screen, else null; anim: your animation (with playing or queued), else null; live: your live charts, above;

  • budget: what your screen costs the Miblo in RAM, storage and processing, each in bands (ok, attention, over) with advice in Portuguese and English. Miblo's memory explains it; miblo screen status prints it.

What Miblo Desk does with each call

CallOn the computerOn Miblo Desk
card() / layer()Validates, cleans the strings, keeps itRedraws only what changed; kept in memory
frame()Checks the wear, converts to 64 colours, encodesWrites the whole slot to flash and checks it before use
show()Marks your screen as pinnedStays on the App screen, no rotation
peek()Checks the limitsShows the App screen for a few seconds, unless alerting
request()Refuses what it already knows (manual, a session waiting, another app)Decides honestly: shows it for the seconds asked, or says why not
clear()Forgets your screen and your slotsTakes the card off and deletes your frames

A Miblo Desk that is off or busy is brought up to date by the bridge later on its own. In gadgets, each Miblo answers for itself: error is offline, unpaired, rejected, busy or rate_limited (its own flash limit). Miblo Hub and Miblo Remote draw the same card, pixel for pixel, with Miblo Desk's own code.

Errors and what to do

StatuscodeWhenWhat to do
400bad_request (+ field)A card or name the rules refuseSee field; shorten the text or change the phrase
400bad_frameNot a PNG or MFRM1 the converter takes (e.g. an interlaced PNG)Save as an 8-bit, non-interlaced PNG
409slot_taken (+ owner)The slot is another program'sUse another slot
409no_cardA peek, or a request for the screen, before any cardSend a card first
400live_too_manyA third live item in the cardTwo live items per card at most
400bad_source, bad_region, bad_fx, bad_option (+ field)animate(): a file the decoders cannot read, or an option out of its rangeSee message; the animations guide lists every option
403alerts_onlyThe app declared screen: false: it only sends alertsDeclare a screen, or send alerts
404no_animationA preview with no animation of yoursanimate() first
405method_not_allowedThe wrong HTTP method for the route (a raw client)Use the package's methods
409too_many_screensThe bridge already holds 64 program screensscreen.clear() the ones you no longer use, or miblo screen clear; a screen nothing wrote for a day goes by itself
409anim_taken (+ owner, retryAfter)Another program's screen is pinned or peeking right nowWait retryAfter; if it is your own other example, show(false) there
409no_free_slotsEvery frame slot is held by other programs, or the Miblo's flash is fullmiblo screen clear, or turn an app off
409no_animationmode7() before a picture was animatedanimate(picture, { fx }) first
410app_offThe app this program draws for is turned off (miblo apps disable, Miblo Hub, removed)Turn it on (miblo apps enable <id>); reading and clearing still work
413too_large (+ max)A card over 1024 bytes, a frame request over 1 MiB, an MFRM1 over 60000 bytes of image, an animate() request over 12 MiBShorten the card; shrink the image
415unsupported_media_typeA frame that is neither octet-stream nor JSONUse the package's frame()
422too_many_colours (+ bytes)The image is too detailed for a frameUse flat colours and fewer gradients
422too_detailedAn animation too detailed even as whole frames, or for a per-line effectFewer colours, a smaller region
429rate_limited (+ retryAfter)Cards, frames (the wear), show, peek, request or animate over the limit, for all programs togetherWait retryAfter seconds; change the card, not the frame
503busy (+ retryAfter)Another program's frame or animation is being uploadedTry again in a second

A 200 with hidden: true is not an error: the person turned your app's screen off (see allowed above).

The rates, for the whole computer

WhatRate
Cards (card(), layer(), a kept scene played again)2 a second, bursts of 5
show()1 every 10 s
peek()1 every 10 minutes per program, and 1 every 10 s (bursts of 3) for all
request()60 s after your last hold ended; 1 every 10 s (bursts of 3) for all
frame()1 write per slot every 10 s and 100 a day (the flash), and 1 conversion a second (bursts of 3)
animate()1 written animation every 2 s (bursts of 4); 1 decode every 2 s (bursts of 4), dry runs included
mode7()1 a second, bursts of 3
Live flushes (push())10 a second, bursts of 20

Complete example: a steps app

This example uses a card, the old and deprecated way (see Page Desk apps for the new one).

The background goes once; then, every minute, only the number changes (no flash writes).

// MIBLO_TOKEN=$(miblo sdk token) node steps.mjs
import fs from 'node:fs';
import { MibloStatus } from '@miblo/status';

const screen = new MibloStatus().screen({ tool: 'steps' });
await screen.frame(0, fs.readFileSync(new URL('./steps-background.png', import.meta.url)));
await screen.show(true);                       // or: miblo mode app

let steps = 8432;
for (;;) {
  await screen.layer(0, { v: 1, title: 'Steps', icon: 'steps', items: [
    { t: 'big', value: steps.toLocaleString('en-US'), label: 'today' },
    { t: 'ring', value: Math.min(1, steps / 14000), label: 'goal 14k', color: 'amber' },
  ] });
  await new Promise((r) => setTimeout(r, 60_000));
  steps += Math.floor(Math.random() * 120);
}

The TypeScript example and its background image ship inside the @miblo/status package (examples/steps.mjs and examples/steps-background.png); the copy there has Portuguese labels (Passos, hoje), the same program otherwise. It loops forever by design: stop it with Ctrl+C, then miblo screen clear (or screen.clear()) to take the screen off.