Compare commits

..

No commits in common. "8d30c10f18e2dbcf92523ae6b5c6e52ceaafc203" and "a242439c4745265d62c7f5b4e14aa754f36e2f55" have entirely different histories.

3 changed files with 17 additions and 43 deletions

View File

@ -1,19 +0,0 @@
import i2c from 'i2c-bus';
async function bmsStatus(address = 0x57) {
const i2cBus = await i2c.openPromisified(1);
const data = await Promise.all([
i2cBus.readByte(address, 0x02),
i2cBus.readByte(address, 0x04),
i2cBus.readByte(address, 0x22),
i2cBus.readByte(address, 0x23),
i2cBus.readByte(address, 0x2a),
]);
return {
charging: !!((data[0] >> 7) & 1),
percentage: data[4] / 100,
temperature: data[1] - 40,
voltage: ((data[2] << 8) | data[3]) / 1000,
}
}
console.log(await bmsStatus());

View File

@ -9,20 +9,17 @@ export default class Http extends Controller {
constructor(apollo, port = 8000) {
super(apollo);
this.express = express();
this.express.get('/api/*', async (req, res) => {
const cmd = req.params['0'];
console.log(cmd);
res.json(await this.run(cmd));
});
this.express.get('*', (req, res) => {
let p = req.params['0'];
if(!p || p == '/') p = 'index.html';
const absolute = path.join(import.meta.url, '/../../ui/', p).replace('file:', '');
res.sendFile(absolute);
});
this.express.get('/api/*', async (req, res) => {
const cmd = req.params['0'];
console.log(cmd);
res.json(await this.run(cmd));
});
this.express.listen(port);
}
}

View File

@ -21,17 +21,16 @@ export default class SensorSuite {
set data(d) { this._data = d; }
get data() { return {timestamp: new Date().getTime(), ...this._data}; }
_env_sensor = false;
get status() { return { env_sensor: this._env_sensor ? 'ok' : 'failed' }; }
get status() { return { sensors: 'ok' }; }
constructor() {
this.bme280 = new BME280({i2cBusNo: 1, i2cAddress: 0x76});
}
start() {
return this.bme280.init().then(() => {
async start() {
await this.bme280.init();
// Poll environmental data
this._env_sensor = true;
this.stopBme280 = poll(async () => {
const d = await this.bme280.readSensorData();
this._data.humidity = d.humidity / 100;
@ -39,9 +38,6 @@ export default class SensorSuite {
this._data.pressure = d.pressure_hPa;
this._data.altitude = BME280.calculateAltitudeMeters(this.data.pressure);
}, 1000);
}).catch(err => {
this._env_sensor = false;
});
}
stop() {