A Cloudflare Workers backend service for LaMetric Time clocks. Fetches data from external APIs on a schedule, caches it in KV storage, and serves it to LaMetric devices.
Live URL: https://lametric-backend.austin-david-schaefer.workers.dev
-
Install dependencies:
npm install
-
Login to Cloudflare (first time only):
npx wrangler login
-
Register a workers.dev subdomain:
- Visit the Cloudflare dashboard
- Go to Workers & Pages
- Register your workers.dev subdomain (e.g.,
yourname.workers.dev)
-
Create a KV namespace:
npx wrangler kv:namespace create CLOCK_DATA
-
Update
wrangler.tomlwith the KV namespace ID from step 4 -
Deploy:
npm run deploy
-
(Optional) Seed initial data if scheduled worker hasn't run yet:
npx wrangler kv:key put --binding CLOCK_DATA "app:counter" "0"
Run locally with hot reload and scheduled event support:
npx wrangler dev --local --test-scheduledIn another terminal, trigger the scheduled worker:
curl http://localhost:8787/__scheduledTest endpoints:
curl http://localhost:8787/health
curl http://localhost:8787/apps/counter- Go to https://developer.lametric.com/applications
- Create a new "Indicator App" or "Metric App"
- Choose "Poll" as the data source
- Configure:
- URL:
https://your-worker.workers.dev/apps/counter - Poll frequency: 1 minute (or your preference)
- Data format: Predefined (LaMetric Format)
- URL:
- Define a fallback frame:
- Icon: Select any icon you like
- Text:
#0orLoading... - This frame only displays if your API is unreachable
- Publish and install the app on your LaMetric device
- Scheduled worker runs every 5 minutes (configured in
wrangler.toml) - Fetches/updates data and stores in KV
- LaMetric device polls the
/apps/counterendpoint - Returns cached data formatted as LaMetric frames
- Counter increments automatically:
#1,#2,#3, etc. - Random icon from LaMetric's gallery on each request
View live logs from your deployed worker:
npx wrangler tail --format prettyIncrements a counter every 5 minutes and displays on LaMetric devices. README-counter.md
Displays Old School RuneScape XP gains from Wise Old Man API. README-OSRS.md
Displays random Magic: The Gathering cards from Scryfall API. README-scryfall.md
Displays top S&P 500 gainer and loser from Financial Modeling Prep API. README-stoxx.md
Displays multi-city weather (Portland, LA, NYC, Kona, Vrsac) from Open-Meteo API. README-weather.md
See CLAUDE.md for the app module pattern and instructions.