Working on linux host

This commit is contained in:
watsonb8 2020-12-12 00:14:56 -05:00
parent ddf37d6f18
commit 3d73ddf4d5
5 changed files with 60 additions and 28 deletions

View File

@ -18,7 +18,6 @@
#restart service #restart service
ssh -t ssh -t
ssh -t $remote_user@$remote_server "sudo systemctl restart homebridge.service" ssh -t $remote_user@$remote_server "sudo systemctl restart homebridge.service"
ssh -t $remote_user@$remote_server "sudo systemctl status homebridge.service"
echo done echo done
exit exit

View File

@ -15,34 +15,48 @@ export const getFaceDetectorOptions = (net: faceapi.NeuralNetwork<any>) => {
: new faceapi.TinyFaceDetectorOptions({ inputSize, scoreThreshold }); : new faceapi.TinyFaceDetectorOptions({ inputSize, scoreThreshold });
}; };
export function saveFile( export const saveFile = async (
basePath: string, basePath: string,
fileName: string, fileName: string,
buf: Buffer buf: Buffer
): Promise<void> { ): Promise<void> => {
const writeFile = (): Promise<void> => {
return new Promise((resolve, reject) => {
fs.writeFile(path.resolve(basePath, fileName), buf, "base64", (err) => {
if (err) {
return reject(err);
}
resolve();
});
});
};
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
if (!fs.existsSync(basePath)) { try {
fs.mkdir(basePath, async (err) => { //Create directory if it does not exist
await makeDirectory(basePath);
} catch (err) {
return reject(err);
}
//Write file to directory
try {
const asdf = fs.writeFileSync(
path.join(basePath, fileName),
buf,
"base64"
);
} catch (err) {
return reject(err);
}
return resolve();
});
};
export const makeDirectory = (path: string): Promise<void> => {
return new Promise(async (resolve, reject) => {
if (!fs.existsSync(path)) {
fs.mkdir(path, async (err) => {
if (err) { if (err) {
return reject(err); return reject(err);
} }
resolve(await writeFile());
return resolve();
}); });
} else {
resolve(await writeFile());
} }
return resolve();
}); });
} };
export const delay = (ms: number): Promise<void> => { export const delay = (ms: number): Promise<void> => {
return new Promise((resolve) => { return new Promise((resolve) => {

View File

@ -175,7 +175,7 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
if (!mimeType || !mimeType.startsWith("image")) { if (!mimeType || !mimeType.startsWith("image")) {
return; return;
} }
console.log(path.join(this.config.refImageDirectory, dir, file)); this.log.info(path.join(this.config.refImageDirectory, dir, file));
try { try {
const referenceImage = (await canvas.loadImage( const referenceImage = (await canvas.loadImage(
@ -193,7 +193,7 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
const faceDescriptors = [descriptor.descriptor]; const faceDescriptors = [descriptor.descriptor];
return new faceapi.LabeledFaceDescriptors(dir, faceDescriptors); return new faceapi.LabeledFaceDescriptors(dir, faceDescriptors);
} catch (err) { } catch (err) {
console.log( this.log.info(
"An error occurred loading image at path: " + "An error occurred loading image at path: " +
path.join(this.config.refImageDirectory, dir, file) path.join(this.config.refImageDirectory, dir, file)
); );
@ -217,10 +217,10 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
"utf8", "utf8",
(err) => { (err) => {
if (err) { if (err) {
console.log(`An error occurred while writing data model to file`); this.log.info(`An error occurred while writing data model to file`);
} }
console.log(`Successfully wrote data model to file`); this.log.info(`Successfully wrote data model to file`);
} }
); );

View File

@ -155,7 +155,6 @@ export class Monitor {
if (this._config.writeOutput) { if (this._config.writeOutput) {
await saveFile(this._config.outputDirectory, room + ".jpg", args.data); await saveFile(this._config.outputDirectory, room + ".jpg", args.data);
} }
for (const res of resultsQuery) { for (const res of resultsQuery) {
const bestMatch = this._matcher.matchDescriptor(res.descriptor); const bestMatch = this._matcher.matchDescriptor(res.descriptor);
const old = this._state[bestMatch.label]; const old = this._state[bestMatch.label];
@ -183,6 +182,8 @@ export class Monitor {
connectionString: connectionString, connectionString: connectionString,
}; };
connectionString = this.getRedactedConnectionString(connectionString);
//Subscribe to rtsp events //Subscribe to rtsp events
stream.rtsp.dataEvent.push((sender: Rtsp, args: IStreamEventArgs) => stream.rtsp.dataEvent.push((sender: Rtsp, args: IStreamEventArgs) =>
this.onData(roomName, stream, args) this.onData(roomName, stream, args)
@ -223,4 +224,13 @@ export class Monitor {
); );
stream.rtsp.start(); stream.rtsp.start();
}; };
private getRedactedConnectionString(connectionString: string) {
const pwSepIdx = connectionString.lastIndexOf(":") + 1;
const pwEndIdx = connectionString.indexOf("@");
return (
connectionString.substring(0, pwSepIdx) +
connectionString.substring(pwEndIdx)
);
}
} }

View File

@ -93,11 +93,20 @@ export class Rtsp {
} }
this._childProcess.stdout?.on("data", this.onData); this._childProcess.stdout?.on("data", this.onData);
this._childProcess.stdout?.on("error", (err) =>
console.log("And error occurred" + err) this._childProcess.stdout?.on("error", (error: Error) =>
this._errorEvent.fire(this, { err: error })
);
this._childProcess.stdout?.on("close", () =>
this._closeEvent.fire(this, {
message: "Stream closed",
})
);
this._childProcess.stdout?.on("end", () =>
this._closeEvent.fire(this, {
message: "Stream ended",
})
); );
this._childProcess.stdout?.on("close", () => console.log("Stream closed"));
this._childProcess.stdout?.on("end", () => console.log("Stream ended"));
//Only register this event if there are subscribers //Only register this event if there are subscribers
if (this._childProcess.stderr && this._messageEvent.length > 0) { if (this._childProcess.stderr && this._messageEvent.length > 0) {