implement pair command

This commit is contained in:
DavidVentura
2024-01-31 16:38:23 +01:00
parent a93c0badff
commit 5379266fc8
3 changed files with 39 additions and 0 deletions
+3
View File
@@ -11,6 +11,9 @@ venv: requirements.txt
run: node_modules
./node_modules/.bin/ts-node --esm http_server.ts
pair: node_modules
./node_modules/.bin/ts-node --esm cmd/pair.ts
hook: bundle.js venv
./venv/bin/python3 -u loader3.py
+5
View File
@@ -11,6 +11,11 @@ Per pictures of the [X5](https://github.com/DavidVentura/cam-reverse/blob/master
To execute the HTTP server, run `make run`; you can access the JPEG stream at http://localhost:1234/ and a file `audio.pcm` will be created.
The roundtrip delay when using MJPEG is [~350ms](pics/delay.jpg?raw=true).
## Pairing a new camera
Connect to the device's access point and run `SSID=<your ssid> PSK=<your password> make pair`.
## Protocol
The protocol is weirdly complex, though very little communication is necessary to use the device
+31
View File
@@ -0,0 +1,31 @@
import { RemoteInfo } from "dgram";
import { discoverDevices } from "../discovery.js";
import { DevSerial } from "../impl.js";
import { Handlers, makeSession, Session, configureWifi } from "../session.js";
const opts = {
debug: true,
ansi: true,
discovery_ip: "192.168.1.255",
};
let sessions: Record<string, Session> = {};
let devEv = discoverDevices(opts);
const onLogin = configureWifi(process.env.SSID, process.env.PSK);
devEv.on("discover", (rinfo: RemoteInfo, dev: DevSerial) => {
if (dev.devId in sessions) {
console.log(`ignoring ${dev.devId} - ${rinfo.address}`);
return;
}
console.log(`discovered ${dev.devId} - ${rinfo.address}`);
const s = makeSession(Handlers, dev, rinfo, onLogin, opts);
s.eventEmitter.on("disconnect", () => {
console.log("deleting from sessions");
sessions[dev.devId] = undefined;
});
sessions[dev.devId] = s;
});