Compare commits
3
Commits
4dfff77b95
...
f35da9b883
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f35da9b883 | ||
|
|
c335935e2d | ||
|
|
db174fc610 |
No files matched your search
@@ -3,5 +3,4 @@ __pycache__/
|
||||
ir-pico/cache/
|
||||
speech/cache/
|
||||
node_modules/
|
||||
box/image
|
||||
box/heard.wav
|
||||
+10
-21
@@ -1,21 +1,20 @@
|
||||
# box: the part of the agent within reach of the couch: a Raspberry Pi 3B with the AIY Voice HAT.
|
||||
# Tools come from the flake: nix develop --command make test
|
||||
#
|
||||
# A box's system comes from lib.mkBox in a flake of your own (FLAKE), as nixosConfigurations.BOX.
|
||||
# Build its image, write it to a card, put the Wi-Fi secret on it, boot the Pi:
|
||||
# make image FLAKE=... BOX=...
|
||||
# A box's system, and so its image, come from lib.mkBox in your household's own flake: build the
|
||||
# image there (nix build), and deploy changes from there (nixos-rebuild). Here, the tools that take
|
||||
# no household details: write the image to a card, put the Wi-Fi secret on it, boot the Pi:
|
||||
# make card DEV=/dev/sdX # look first
|
||||
# make flash DEV=/dev/sdX CONFIRM=erase # then write
|
||||
# make flash DEV=/dev/sdX IMG=.../sd-image/x.img CONFIRM=erase # then write
|
||||
# make wifi-secret SSID=...
|
||||
# After that, changes go over ssh: make deploy. Then, on the home server, as the brain's user,
|
||||
# Then, on the home server, as the brain's user,
|
||||
# with speech and the brain installed: make keys.
|
||||
|
||||
FLAKE = .
|
||||
BOX = box
|
||||
ADMIN = $(USER)
|
||||
HOST = $(BOX).local
|
||||
NIX = nix --option extra-platforms aarch64-linux
|
||||
DEV =
|
||||
IMG =
|
||||
SSID =
|
||||
MNT = /mnt/pdtv26-card
|
||||
TEXT = Hello. Press my button and talk to me.
|
||||
@@ -29,7 +28,7 @@ CAMERA_URL = $(HOME)/.config/pdtv26-camera/rtsp-url
|
||||
SPEECH_KEY = /etc/pdtv26-speech/speech-key
|
||||
ON_BOX = ssh $(ADMIN)@$(HOST)
|
||||
|
||||
.PHONY: help test image card flash wifi-secret deploy say volume record keys speech-key ask-key ir-key look-key rtsp-url
|
||||
.PHONY: help test card flash wifi-secret say volume record keys speech-key ask-key ir-key look-key rtsp-url
|
||||
|
||||
## list targets
|
||||
help:
|
||||
@@ -39,31 +38,21 @@ help:
|
||||
test:
|
||||
nix build -L --no-link ..#checks.x86_64-linux.box-js ..#checks.x86_64-linux.box-py ..#checks.x86_64-linux.box-system
|
||||
|
||||
## BOX's SD card image (aarch64: under qemu, unless this is an aarch64 machine)
|
||||
image:
|
||||
$(NIX) build -L --out-link image '$(FLAKE)#nixosConfigurations.$(BOX).config.system.build.sdImage'
|
||||
ls -l image/sd-image/
|
||||
|
||||
## show the card at DEV, and check it's removable, on USB, and under 128 GB
|
||||
card:
|
||||
./card-check.sh $(DEV)
|
||||
|
||||
## erase the card at DEV and write the image: make flash DEV=/dev/sdX CONFIRM=erase
|
||||
# Not "flash: image": image links into the Nix store, where every mtime is 1970, so make would always rebuild.
|
||||
## erase the card at DEV and write the image IMG to it: make flash DEV=/dev/sdX IMG=... CONFIRM=erase
|
||||
flash: card
|
||||
@test "$(CONFIRM)" = erase || { echo "this erases $(DEV); add CONFIRM=erase"; exit 1; }
|
||||
@test -e image || { echo "no image yet: make image"; exit 1; }
|
||||
./flash.sh image/sd-image/*.img $(DEV)
|
||||
@test -f "$(IMG)" || { echo "which image? add IMG=.../sd-image/....img, from your household's nix build"; exit 1; }
|
||||
./flash.sh '$(IMG)' $(DEV)
|
||||
|
||||
## put the Wi-Fi network's PSK on the card, from the passphrase in the desktop keyring: make wifi-secret SSID=...
|
||||
wifi-secret:
|
||||
@test -n "$(SSID)" || { echo "which network? add SSID=..."; exit 1; }
|
||||
./wifi-secret.sh '$(SSID)' $(MNT)
|
||||
|
||||
## build BOX's system here and switch the Pi to it, over ssh: make deploy [HOST=...]
|
||||
deploy:
|
||||
nixos-rebuild switch --flake '$(FLAKE)#$(BOX)' --target-host $(ADMIN)@$(HOST) --sudo --option extra-platforms aarch64-linux
|
||||
|
||||
## speak TEXT through the box's speaker, with espeak-ng: make say [TEXT="..."] [AMP=0..200]
|
||||
say:
|
||||
printf '%s\n' "$(TEXT)" | ssh $(ADMIN)@$(HOST) 'espeak-ng -a $(AMP) --stdin --stdout | aplay -q -D speaker'
|
||||
|
||||
+9
-6
@@ -13,7 +13,7 @@ A private git repository of your own holds what's yours: the names you choose, a
|
||||
url = "git+https://git.inference.coop/dckc/pdtv26";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
outputs = { pdtv26, ... }: {
|
||||
outputs = { self, pdtv26, ... }: {
|
||||
nixosConfigurations.pimote = pdtv26.lib.mkBox {
|
||||
name = "pimote"; # the box's host name on your network
|
||||
server = "den-pc"; # your home server's host name: speech and the brain
|
||||
@@ -21,6 +21,8 @@ A private git repository of your own holds what's yours: the names you choose, a
|
||||
admin = "pat"; # who looks after the box, and logs in to deploy
|
||||
sshKeys = [ "ssh-ed25519 AAAA... pat@laptop" ];
|
||||
};
|
||||
# The box's SD card image, built on x86_64 Linux.
|
||||
packages.x86_64-linux.sd-image = self.nixosConfigurations.pimote.config.system.build.sdImage;
|
||||
};
|
||||
}
|
||||
```
|
||||
@@ -38,13 +40,14 @@ The brain comes after the box, in step 5, since it needs the box's keys.
|
||||
|
||||
## 3. Make the box's SD card
|
||||
|
||||
On any Linux machine with Nix that can run ARM programs (on Debian or Ubuntu, `apt install qemu-user-static`), in pdtv26's `box/`:
|
||||
The image carries your household's names, so it's built from your household repository, on any Linux machine with Nix that can run ARM programs (on Debian or Ubuntu, `apt install qemu-user-static`). The Wi-Fi passphrase and the keys stay out of it.
|
||||
|
||||
1. `make image FLAKE=path/to/household BOX=pimote`, then `make card DEV=/dev/sdX` to check you have the right device, and `make flash DEV=/dev/sdX CONFIRM=erase`.
|
||||
2. `make wifi-secret SSID=MyNetwork`: it puts the network's PSK on the card from the passphrase in your desktop keyring, not in the image or the repository. Store the passphrase there once, with `secret-tool store --label="Wi-Fi MyNetwork" service wifi ssid MyNetwork`.
|
||||
3. Put the card in the Pi, plug in the IR emitter's USB cord, and power it up.
|
||||
1. In your household repository: `nix build --option extra-platforms aarch64-linux .#sd-image`.
|
||||
2. In pdtv26's `box/`: `make card DEV=/dev/sdX` to check you have the right device, then `make flash DEV=/dev/sdX IMG=path/to/household/result/sd-image/*.img CONFIRM=erase`.
|
||||
3. Also in `box/`: `make wifi-secret SSID=MyNetwork`: it puts the network's PSK on the card from the passphrase in your desktop keyring, not in the image or the repository. Store the passphrase there once, with `secret-tool store --label="Wi-Fi MyNetwork" service wifi ssid MyNetwork`.
|
||||
4. Put the card in the Pi, plug in the IR emitter's USB cord, and power it up.
|
||||
|
||||
After this, changes to the box go over ssh: `make deploy FLAKE=path/to/household BOX=pimote`.
|
||||
After this, changes to the box go over ssh, from your household repository: `nixos-rebuild switch --flake .#pimote --target-host pat@pimote.local --sudo --option extra-platforms aarch64-linux`.
|
||||
|
||||
## 4. Join the private network
|
||||
|
||||
|
||||
+7
-3
@@ -24,7 +24,7 @@ const fromButton = (source) => source.endsWith('-button');
|
||||
|
||||
/**
|
||||
* @typedef {{ at: number, kind: string, source: string, reason?: string, code?: string, times?: number }} Event
|
||||
* @typedef {{ name: string, up: boolean, at: number, since: number }} Check
|
||||
* @typedef {{ name: string, up: boolean, at: number, since: number, outage?: number }} Check outage: when the latest outage we saw began
|
||||
* @typedef {{ conversations: number, turns: number, huh: number, interrupts: number, irPresses: number, looks: number }} Tally
|
||||
* @typedef {{ word: string, since?: number, why?: string }} State
|
||||
* @typedef {{ state: State, heartbeat?: number, checks: (typeof CHECKS[number] & Partial<Check>)[], today: Tally, total: Tally, recent: Event[] }} Summary
|
||||
@@ -82,7 +82,9 @@ export class Status {
|
||||
/** @param {string} name @param {boolean} up @param {number} at */
|
||||
check(name, up, at) {
|
||||
const prev = this.#checks.get(name);
|
||||
this.#checks.set(name, { name, up, at, since: prev && prev.up === up ? prev.since : at });
|
||||
const since = prev && prev.up === up ? prev.since : at;
|
||||
const outage = up ? prev?.outage : since;
|
||||
this.#checks.set(name, { name, up, at, since, ...(outage === undefined ? {} : { outage }) });
|
||||
}
|
||||
|
||||
size() { return this.#events.length; }
|
||||
@@ -93,7 +95,9 @@ export class Status {
|
||||
if (!up) return { word: 'not checked yet' };
|
||||
if (!up.up) return { word: 'unreachable', since: up.since };
|
||||
const ready = this.#events.findLast((e) => e.kind === 'ready');
|
||||
if (!ready || ready.at < up.since) return { word: 'booting', since: up.since };
|
||||
// Services restart together, so ready can come before the check sees the box up again: a ready
|
||||
// counts unless it's from before the latest outage we saw.
|
||||
if (!ready || ready.at < (up.outage ?? -Infinity)) return { word: 'booting', since: up.since };
|
||||
const alive = Math.max(this.#heartbeat ?? 0, this.#events.findLast((e) => fromButton(e.source))?.at ?? 0);
|
||||
if (now - alive > 3 * HEARTBEAT_MS) return { word: 'not responding', since: alive, why: 'no heartbeat from its button service' };
|
||||
const last = this.#events.findLast((e) => e.kind === 'conversation' || e.kind === 'end');
|
||||
|
||||
@@ -41,6 +41,24 @@ test('a ready from before the box went away does not count: booting', () => {
|
||||
assert.equal(s.summary(4 * MIN).state.word, 'booting');
|
||||
});
|
||||
|
||||
test('a ready during the outage counts: services restart together, and the check sees the box up last', () => {
|
||||
const s = new Status(dayOf);
|
||||
s.check('box', true, 0);
|
||||
s.record({ at: 1 * MIN, kind: 'ready', source: 'pdtv26-button' });
|
||||
s.check('box', false, 2 * MIN);
|
||||
s.record({ at: 2.5 * MIN, kind: 'ready', source: 'pdtv26-button' });
|
||||
s.check('box', true, 3 * MIN);
|
||||
assert.deepEqual(s.summary(4 * MIN).state, { word: 'ready for duty', since: 2.5 * MIN });
|
||||
});
|
||||
|
||||
test('a ready from before the server started counts, if the server saw no outage', () => {
|
||||
const s = new Status(dayOf);
|
||||
s.record({ at: 1 * MIN, kind: 'ready', source: 'pdtv26-button' });
|
||||
s.check('box', true, 10 * MIN);
|
||||
s.beat(10.5 * MIN);
|
||||
assert.deepEqual(s.summary(11 * MIN).state, { word: 'ready for duty', since: 1 * MIN });
|
||||
});
|
||||
|
||||
test('checks keep when they last changed', () => {
|
||||
const s = new Status(dayOf);
|
||||
s.check('brain', true, 1 * MIN);
|
||||
|
||||
Reference in new issue
Block a user