call configureWifi after scanning to include the channel
This commit is contained in:
@@ -2,7 +2,8 @@ import { RemoteInfo } from "dgram";
|
||||
|
||||
import { config } from "./settings.js";
|
||||
import { discoverDevices } from "./discovery.js";
|
||||
import { DevSerial, SendReboot, SendWifiSettings } from "./impl.js";
|
||||
import { WifiListItem } from "./handlers.js";
|
||||
import { DevSerial, SendListWifi } from "./impl.js";
|
||||
import { Handlers, makeSession, Session, configureWifi } from "./session.js";
|
||||
import { logger } from "./logger.js";
|
||||
|
||||
@@ -16,15 +17,10 @@ export const pair = ({ ssid, password }: { ssid: string; password: string }) =>
|
||||
}
|
||||
|
||||
const onLogin = (s: Session) => {
|
||||
logger.info(`Configuring camera ${s.devName}`);
|
||||
configureWifi(ssid, password)(s);
|
||||
logger.info(`WiFi config for camera ${s.devName} is done`);
|
||||
logger.info(`Scanning for Wifi networks on ${s.devName} -- this may time out`);
|
||||
|
||||
logger.info(`Validating WiFi settings on ${s.devName}`);
|
||||
s.send(SendWifiSettings(s));
|
||||
|
||||
logger.info(`Asking ${s.devName} to reboot`);
|
||||
s.send(SendReboot(s));
|
||||
// configureWifi(ssid, password, 0)(s);
|
||||
s.send(SendListWifi(s));
|
||||
};
|
||||
|
||||
devEv.on("discover", (rinfo: RemoteInfo, dev: DevSerial) => {
|
||||
@@ -33,13 +29,35 @@ export const pair = ({ ssid, password }: { ssid: string; password: string }) =>
|
||||
return;
|
||||
}
|
||||
logger.info(`Discovered camera ${dev.devId} at ${rinfo.address}`);
|
||||
const s = makeSession(Handlers, dev, rinfo, onLogin);
|
||||
const s = makeSession(Handlers, dev, rinfo, onLogin, 10000);
|
||||
let configured = {};
|
||||
|
||||
s.eventEmitter.on("disconnect", () => {
|
||||
logger.info(`Camera ${dev.devId} disconnected`);
|
||||
logger.info("Press CONTROL+C if you're done setting up your cameras");
|
||||
if (configured[dev.devId]) {
|
||||
logger.info("Press CONTROL+C if you're done setting up your cameras");
|
||||
}
|
||||
delete sessions[dev.devId];
|
||||
delete configured[dev.devId];
|
||||
});
|
||||
sessions[dev.devId] = s;
|
||||
|
||||
s.eventEmitter.on("ListWifi", (items: WifiListItem[]) => {
|
||||
const matches = items.filter((i) => i.ssid == ssid);
|
||||
if (matches.length == 0) {
|
||||
logger.error(`Camera could not find SSID '${ssid}'`);
|
||||
return;
|
||||
}
|
||||
if (configured[dev.devId]) {
|
||||
logger.info(`Got two answers from camera, ignoring second`);
|
||||
return;
|
||||
}
|
||||
const match = matches[0];
|
||||
logger.info(`Configuring camera ${s.devName} on ${JSON.stringify(match)}`);
|
||||
configureWifi(ssid, password, match.channel)(s);
|
||||
configured[dev.devId] = true;
|
||||
logger.info(`WiFi config for camera ${s.devName} is done`);
|
||||
logger.info(`Camera should reboot now`);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user