Fixes
This commit is contained in:
parent
02a533358e
commit
2144d7ef69
@ -7,7 +7,7 @@ export default class Daemon {
|
||||
apollo;
|
||||
express;
|
||||
|
||||
constructor(port = 80) {
|
||||
constructor(port = 1969) {
|
||||
this.apollo = APOLLO;
|
||||
this.apollo.start();
|
||||
|
||||
|
22
src/main.js
22
src/main.js
@ -1,18 +1,19 @@
|
||||
import {ask} from './misc.js';
|
||||
import Daemon from './daemon.js';
|
||||
|
||||
const command = process.argv[2];
|
||||
let remote = 'localhost';
|
||||
const command = process.argv.slice(2).join(' ');
|
||||
let remote = 'localhost:1969';
|
||||
|
||||
function help() {
|
||||
return `
|
||||
Apollo v0.0.0
|
||||
Remote: ${remote}
|
||||
|
||||
Commands:
|
||||
exit - Exit CLI
|
||||
help - Display this manual
|
||||
reboot - Reboot System
|
||||
remote <addr> - Connect to remote Apollo
|
||||
remote <addr> - Get/Set Apollo address
|
||||
sensors - Display sensor data
|
||||
shutdown - Shutdown System
|
||||
start <port> - Start Apollo server
|
||||
@ -22,15 +23,22 @@ status - Apollo Subsystems status
|
||||
}
|
||||
|
||||
function run(cmd) {
|
||||
try {
|
||||
if(cmd.toLowerCase() === 'exit') process.exit();
|
||||
else if(cmd === 'help') return this.help();
|
||||
else if(cmd.startsWith('remote')) remote = cmd.split(' ').pop();
|
||||
else if(cmd.startsWith('start')) new Daemon(+cmd.split(' ').pop() || 80);
|
||||
else if(cmd === 'help') return help();
|
||||
else if(cmd === 'remote') return remote;
|
||||
else if(cmd.startsWith('remote')) {
|
||||
remote = cmd.split(' ').pop();
|
||||
return `Remote Set: ${remote}`;
|
||||
} else if(cmd.startsWith('start')) new Daemon(+cmd.split(' ').pop() || 1969);
|
||||
else return fetch(`${remote.startsWith('http') ? '' : 'http://'}${remote}/api/${cmd}`).then(resp => {
|
||||
if(resp.ok && resp.headers['Content-Type'].includes('json'))
|
||||
if(resp.ok && resp.headers['Content-Type']?.includes('json'))
|
||||
return resp.json();
|
||||
else return resp.text();
|
||||
}).catch(err => err.message);
|
||||
} catch(err) {
|
||||
return err.message || err;
|
||||
}
|
||||
}
|
||||
|
||||
if(command) console.log(run(command));
|
||||
|
@ -27,7 +27,7 @@ export default class SensorSuite {
|
||||
async start() {
|
||||
this.intervals.push(adjustedInterval(async () => {
|
||||
this.data.environment = await this.statusWrapper(bme(), 'bme280');
|
||||
if(this.data.environment.pressure != null)
|
||||
if(this.data.environment?.pressure != null)
|
||||
this.data.environment.altitude = SensorSuite.#hPaToAltitude(this.data.environment.pressure);
|
||||
}, 1000));
|
||||
await sleep(500); // Offset reading sensor data
|
||||
|
Loading…
Reference in New Issue
Block a user