-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
24 lines (16 loc) · 894 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const express = require('express');
const bodyParser = require('body-parser');
const needle = require('needle');
const app = express()
app.use(bodyParser.json())
const port = 3000
app.post('/', (req, res) => {
let speed = (req.body[0].speed != null) ? req.body[0].speed : 0; // to standardize the speed readings
let data = `position,device=device1 lat=${req.body[0].latitude},lon=${req.body[0].longitude},speed=${speed},provider="${req.body[0].provider}",accuracy=${req.body[0].accuracy} ${req.body[0].time}`; //check this out as influx is super picky with the line protocol
console.log(data)
needle('post','http://influx:8086/api/v2/write?bucket=geodata&precision=ms', data)
.then(res => console.log(res.body))
.then(res.sendStatus(200))
.catch(console.log)
})
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))