Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

The arm server serves the Pi's temperature and under-voltage flags at GET /health/pi, read from sysfs, never a shell #540

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

The arm server now answers GET /health/pi with { tempC, underVoltage, underVoltageSince, throttled, at }, read from sysfs. It never shells out. The new pi-health tests pass, and the change is pushed.

Notes

shipped merged

opened this

The arm server now answers GET /health/pi with { tempC, underVoltage, underVoltageSince, throttled, at }, read from sysfs. It never shells out. The new pi-health tests pass, and the change is pushed.

  • Reader: src/pi-health.ts reads the temperature in millidegrees from /sys/class/thermal/thermal_zone0/temp. It reads the throttled bits from /sys/devices/platform/soc/soc:firmware/get_throttled. Both paths can be passed in for tests.
  • Fields: underVoltage is bit 0x1 (now) and underVoltageSince is bit 0x10000 (since boot). I chose throttled as true if any of 0x2, 0x4 or 0x8 is set. The issue didn't say which bits count, so say if you want a different set.
  • Missing or garbage content: a missing file, or content that doesn't parse, gives null for the fields that file feeds. Off a Pi the route answers 200 with nulls, so the fake server needs no special case. I didn't add a test for the route itself.
  • Tests: src/pi-health.test.ts covers a normal reading, under-voltage now and since boot, missing files and garbage.
  • Failing test: bun x tsc --noEmit could not run because the bun type definitions are missing, so the type check is unverified. In src/server.test.ts, the "serves the model, its meshes and the vendored libraries" test fails (a 404 for /vendor/three/build/three.module.js). It also fails with my changes stashed. I ran only pi-health, server and fake-serve tests, not the full bun --cwd Software/so101 test, which the forge's check will do.

Closes #531

1 earlier comment · 1 event
commented

The arm server now answers GET /health/pi with { tempC, underVoltage, underVoltageSince, throttled, at }, read from sysfs. It never shells out. The new pi-health tests pass, and the change is pushed.

  • Reader: src/pi-health.ts reads the temperature in millidegrees from /sys/class/thermal/thermal_zone0/temp. It reads the throttled bits from /sys/devices/platform/soc/soc:firmware/get_throttled. Both paths can be passed in for tests.
  • Fields: underVoltage is bit 0x1 (now) and underVoltageSince is bit 0x10000 (since boot). I chose throttled as true if any of 0x2, 0x4 or 0x8 is set. The issue didn't say which bits count, so say if you want a different set.
  • Missing or garbage content: a missing file, or content that doesn't parse, gives null for the fields that file feeds. Off a Pi the route answers 200 with nulls, so the fake server needs no special case. I didn't add a test for the route itself.
  • Tests: src/pi-health.test.ts covers a normal reading, under-voltage now and since boot, missing files and garbage.
  • Failing test: bun x tsc --noEmit could not run because the bun type definitions are missing, so the type check is unverified. In src/server.test.ts, the "serves the model, its meshes and the vendored libraries" test fails (a 404 for /vendor/three/build/three.module.js). It also fails with my changes stashed. I ran only pi-health, server and fake-serve tests, not the full bun --cwd Software/so101 test, which the forge's check will do.
Changes requested — before the latest push

The reader is clean: sysfs only, no shell, strict regexes, nulls when absent, and the tests cover the parser well. Two misses.

  1. The route has no test. The only behaviour wired into the server, GET /health/pi answering 200 JSON, is untested; delete the line and every test still passes. Add a case in server.test.ts that GETs /health/pi and checks status 200, the JSON content type and the five keys. This is the one thing to fix first.
  2. The preview does not show it working. At this head, https://arm--540--forge-trevato-apps.open-platform.sh/health/pi answers 404 {"error":"no such route"} while / answers. Push again and confirm the preview serves the route (nulls off a Pi are fine).

Smaller: the issue named only temperature and under-voltage, and throttled is an added field with a bit set you chose. Keep it only if the issue is happy with it, and say so in the pull. The README should also mention the endpoint. The author could not run tsc, so type-check before pushing.

commented

GET /health/pi now has a test and the README documents it. The preview will still answer 404 until the Pi runs this commit, which I think is correct.

  • Route test: src/server.test.ts now GETs /health/pi and checks status 200, a JSON content type and the five keys, with at a number. The server.test.ts file passes (65 tests, 0 failures). The earlier failing vendor-file test now passes after a frozen bun install.
  • README: a new "The Pi's own health" section names the endpoint, the two sysfs files, the bit meanings, and that off a Pi it answers 200 with nulls.
  • Type check: tsc --noEmit now runs. It reports errors in other files (src/ui/zone-notes.js, src/visitor-counts.ts, among others), but none in pi-health or server. I did not run the full suite.
  • Preview 404: I think the 404 comes from the relay, not from a missing route. The preview's /link reports mode: live, host: 100.89.95.68:8101, so GET /health/pi is forwarded to the real Pi's arm server. That server is still on the older commit and answers no such route. I can't confirm this against the preview itself, since it keeps proxying to the Pi.
  • Local check: I ran bench/fake-serve.ts locally and /health/pi answered 200 JSON with the five keys. tempC was 44 and the throttle fields were null.
  • throttled: I kept it. The issue named only temperature and under-voltage, and the bit set is my choice: any of 0x2, 0x4 or 0x8 means throttled now. It's documented in the README, and it's easy to drop or change if you'd rather.
Approved

Approved. The reader is sysfs-only with no shell, and it validates content with strict regexes. A missing or garbage file gives null, and the route is a small, tested addition. The relay passes unknown GETs through to the arm (src/relay.ts ~L834), so the README claim holds. The preview answers 404 {"error":"no such route"} because the live Pi is still on an older commit. That fits what the code does, but this preview cannot show the route working.

Two things to do next:

  1. Once the Pi runs this commit, curl /health/pi on production and check tempC and the bits against vcgencmd get_throttled. Also decide whether the relay should gate it like /precision, which is owner and moderator only, since it is currently open to any visitor. The data is low-sensitivity.
  2. Surface it in the terminal or /admin Health (a /health line) so both doors can see it. That is a separate pull on the machine pillar, not this one.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs