-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (21 loc) · 685 Bytes
/
app.js
File metadata and controls
26 lines (21 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const express = require('express');
const Daly2Bt = require('./domain/Daly2Bt');
const app = express();
const PORT = 3000;
const bms = new Daly2Bt();
app.get('/bms', async (req, res) => {
try {
const data = await bms.getData();
res.json(data);
} catch (error) {
res.status(500).json({ error: `Failed to fetch BMS data: ${error.message}` });
}
});
app.get('/status', async (req, res) => {
const status = bms.peripheral && bms.peripheral.state === 'connected';
res.json({ status: status ? 'Connected' : 'Disconnected' });
});
// Start the server
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});