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
toolyou pass toscreen().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 getrate_limited: waitretryAfterseconds.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 callsrequest(), below) or only when I ask (pinned or a peek).
screen()
const screen = miblo.screen({ tool: 'steps' });screen = miblo.screen("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.
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 }):fileis a.htmlfile 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.datais JSON, at most 16 KB, and reaches the page aswindow.miblo.data. It returns{ ok, page, quality, max, current }.data(obj): new JSON for the page (at most 16 KB); the page hears it withmiblo.on('data', fn).quality(q, { max }):'auto'(the default),'verylow'(30 fps target),'low'(25),'medium'(20),'high'(15) or'ultra'(about 10).autostarts atmedium, steps down when the stream stalls and up after about 5 s clean, never abovemax.New error:
no_page(status 409), whendata()orquality()come beforepage().
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' },
],
});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
| Field | Rules |
|---|---|
v | Always 1. |
title | Optional, up to 24 characters, at the top of the screen (your program's name follows it). |
items | 1 to 4 items, top to bottom. |
icon | Optional, a name from the set below. A name outside it is drawn as none. |
bg | Optional, "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
t | Fields | fx it takes | How it shows |
|---|---|---|---|
big | value (text or a whole number, up to 10 characters, required), label?, color? | count, pulse, blink, rain | A big number with a caption. |
ring | value (0 to 1), label?, color?; live: id, range?, live | sweep, orbit (+ speed 0 to 360), pulse, blink, rain | A ring that fills up, like the limits' rings. |
bar | value (0 to 1), label?, color?; live: id, range?, live | sweep, pulse, blink, rain | A bar that fills up. |
text | value (up to 40 characters, required), color? | ticker, pulse, blink, rain | A line of text. |
spark | values (2 to 24 numbers), label?, color?; live: id, range, live (and values becomes optional) | slide, pulse, blink, rain | A tiny line chart. |
mesh | mesh ('cube', 'icosphere', 'miblo' or your own vertices), shading?, speed?, light?, color? | spin, tumble | A 3D model the Miblo turns; one per card, never in a row. |
row | items: exactly 2 of the others (never a row or a mesh) | none | Two 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 themeshfields, are in the Screen animations guide (chapter 5).id,rangeandlive: a live chart (Miblo 1.27), fed by push(): see below.color:amber,blue,green,red,whiteorgrey. 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 likeitems[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 })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 }:hzfrom 1 to 30 (default 10),secondsfrom 1 to 5 (default 3). Onspark,ringandbaronly, and at most 2 live items per card (outside or inside arow): a third is refused (live_too_many).fxon a live item is ignored.id: 1 to 16 characters[a-z0-9_-], unique in the card, required withlive: it is the keypush()uses.range: [min, max]: finite numbers,min < max; required on aspark,[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,fielditems[1].live.seconds), and theirhz × secondsadd 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 perid(faster is coalesced). The package sends what is waiting every 500 ms or 32 samples, asPOST /sdk/v1/screen/livewith 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 everyseconds, up to 1 KB. Nothing goes to the flash.push()never throws: a flush the bridge refused goes toscreen({ 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()carrieslive: one entry perid, withiandr(its place in the card),hz,seconds,seq,value(the latest sample),buffered(batches in hand, 0 to 2),playing,lateandreal: { fps, drawMs }, what the Miblo measures.stop(),clear()and a new card without theidend 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'));with open("background.png", "rb") as f:
screen.frame(0, f.read())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 aUint8Array) 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_limitedwithretryAfter, 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' }] });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);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);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_limitedwithretryAfter).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);r = screen.request(30)
if not r["shown"]:
print("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:
why | What happened |
|---|---|
waiting | An AI session needs the person right now |
alert | An alert (Miblo's or an app's) is on the screen |
manual | The person chose "Only when I ask" |
taken | Another app holds the screen (pinned, or it asked first): owner and retryAfter |
hidden | The person turned your app's screen off ("Show the screen on Miblo") |
refused | The Miblo itself said no (it was busy with something of its own) |
offline, no_gadget | No 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_limitedwithretryAfter). 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()saysrequest: { seconds, until }while your screen is there on a request (nullotherwise).
clear(), removeFrame() and status()
| TypeScript | Python | What 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 (withtool), ornull;frames: your slots,[{ slot, bytes, at }](atin 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:falsewhen 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, andframe(),animate(),peek(),show()andrequest()answer200withhidden: trueand nothing delivered. Send an alert instead of drawing the moment;request:{ seconds, until }while a request of yours holds the screen, elsenull;anim: your animation (withplayingorqueued), elsenull;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 statusprints it.
What Miblo Desk does with each call
| Call | On the computer | On Miblo Desk |
|---|---|---|
card() / layer() | Validates, cleans the strings, keeps it | Redraws only what changed; kept in memory |
frame() | Checks the wear, converts to 64 colours, encodes | Writes the whole slot to flash and checks it before use |
show() | Marks your screen as pinned | Stays on the App screen, no rotation |
peek() | Checks the limits | Shows 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 slots | Takes 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
| Status | code | When | What to do |
|---|---|---|---|
| 400 | bad_request (+ field) | A card or name the rules refuse | See field; shorten the text or change the phrase |
| 400 | bad_frame | Not a PNG or MFRM1 the converter takes (e.g. an interlaced PNG) | Save as an 8-bit, non-interlaced PNG |
| 409 | slot_taken (+ owner) | The slot is another program's | Use another slot |
| 409 | no_card | A peek, or a request for the screen, before any card | Send a card first |
| 400 | live_too_many | A third live item in the card | Two live items per card at most |
| 400 | bad_source, bad_region, bad_fx, bad_option (+ field) | animate(): a file the decoders cannot read, or an option out of its range | See message; the animations guide lists every option |
| 403 | alerts_only | The app declared screen: false: it only sends alerts | Declare a screen, or send alerts |
| 404 | no_animation | A preview with no animation of yours | animate() first |
| 405 | method_not_allowed | The wrong HTTP method for the route (a raw client) | Use the package's methods |
| 409 | too_many_screens | The bridge already holds 64 program screens | screen.clear() the ones you no longer use, or miblo screen clear; a screen nothing wrote for a day goes by itself |
| 409 | anim_taken (+ owner, retryAfter) | Another program's screen is pinned or peeking right now | Wait retryAfter; if it is your own other example, show(false) there |
| 409 | no_free_slots | Every frame slot is held by other programs, or the Miblo's flash is full | miblo screen clear, or turn an app off |
| 409 | no_animation | mode7() before a picture was animated | animate(picture, { fx }) first |
| 410 | app_off | The 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 |
| 413 | too_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 MiB | Shorten the card; shrink the image |
| 415 | unsupported_media_type | A frame that is neither octet-stream nor JSON | Use the package's frame() |
| 422 | too_many_colours (+ bytes) | The image is too detailed for a frame | Use flat colours and fewer gradients |
| 422 | too_detailed | An animation too detailed even as whole frames, or for a per-line effect | Fewer colours, a smaller region |
| 429 | rate_limited (+ retryAfter) | Cards, frames (the wear), show, peek, request or animate over the limit, for all programs together | Wait retryAfter seconds; change the card, not the frame |
| 503 | busy (+ retryAfter) | Another program's frame or animation is being uploaded | Try 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
| What | Rate |
|---|---|
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);
}# MIBLO_TOKEN=$(miblo sdk token) python3 steps.py
import os, random, time
from miblo_status import MibloStatus
screen = MibloStatus().screen("steps")
with open(os.path.join(os.path.dirname(__file__), "steps-background.png"), "rb") as f:
screen.frame(0, f.read())
screen.show(True) # or: miblo mode app
steps = 8432
while True:
screen.layer(0, {"v": 1, "title": "Steps", "icon": "steps", "items": [
{"t": "big", "value": f"{steps:,}", "label": "today"},
{"t": "ring", "value": min(1, steps / 14000), "label": "goal 14k", "color": "amber"},
]})
time.sleep(60)
steps += random.randint(0, 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.