diff --git a/src/daemon.js b/src/daemon.js index 5f7201a..ea9c600 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -7,7 +7,7 @@ export default class Daemon { apollo; express; - constructor(port = 80) { + constructor(port = 1969) { this.apollo = APOLLO; this.apollo.start(); diff --git a/src/main.js b/src/main.js index 59ce562..716e4fe 100644 --- a/src/main.js +++ b/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 - Connect to remote Apollo +remote - Get/Set Apollo address sensors - Display sensor data shutdown - Shutdown System start - 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)); diff --git a/src/sensor-suite.js b/src/sensor-suite.js index 4c4b2ed..df0fd64 100644 --- a/src/sensor-suite.js +++ b/src/sensor-suite.js @@ -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