-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (34 loc) · 1.17 KB
/
server.js
File metadata and controls
38 lines (34 loc) · 1.17 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
const express=require("express");
const cors=require("cors");
const fs = require("fs");
const path = require('path');
const app=express();
const port=3000;
app.use(cors());
function getsensordata(){
return {
lim_temperature: Math.random() *30 +50,
acceleration:Math.random() *50+30,
voltage: Math.random() *40+30,
high_battery_temp:Math.random() *40+30,
high_battery_voltage:Math.random() *40+30,
high_battery_power:Math.random() *40+30,
high_battery_current:Math.random() *40+30,
low_battery_temp:Math.random() *40+30,
low_battery_voltage:Math.random() *40+30,
low_battery_power:Math.random() *40+30,
low_battery_current:Math.random() *40+30,
proximity:Math.random() *40+30,
gap_height:Math.random() *40+30,
pressure:Math.random() *40+30,
};
}
app.get("/",(req,res)=>{
const sensordata=getsensordata();
// const filePath = path.join(__dirname, 'sensordata.json');
// fs.appendFileSync(filePath, JSON.stringify(sensordata, null, 2));
res.json(sensordata);
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});