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