sensors added
parent
1fbabbbfc8
commit
b676e91fea
@ -1,10 +1,51 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
const sensors = [
|
||||||
|
{
|
||||||
|
id: 'htu21d-01',
|
||||||
|
model: 'HTU21D',
|
||||||
|
quantities: ['temperature', 'humidity']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'htu21d-02',
|
||||||
|
model: 'HTU21D',
|
||||||
|
quantities: ['temperature', 'humidity']
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send('<h1> TEST </h1>');
|
res.send('<h1> TEST </h1>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Status//
|
||||||
|
app.get('/api/status', (req, res) => {
|
||||||
|
res.json({ status: 'online', application: 'sensor-api' });
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/info', (req, res) => {
|
||||||
|
res.json({ author: 'Leonard', version: 'v0.0' });
|
||||||
|
});
|
||||||
|
|
||||||
|
//SENSORS//
|
||||||
|
app.get('/api/sensors', (req, res) => {
|
||||||
|
res.json(sensors);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/sensors/:id', (req, res) => {
|
||||||
|
const sensor = sensors.find(
|
||||||
|
(item) => item.id === req.params.id
|
||||||
|
);
|
||||||
|
|
||||||
|
// if sensor not found
|
||||||
|
if (!sensor) {
|
||||||
|
return res.status(404).json({
|
||||||
|
error: 'sensor not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.json(sensor);
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(3030, () => {
|
app.listen(3030, () => {
|
||||||
console.log('Listen on port 3030');
|
console.log('Listen on port 3030');
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue