-
Notifications
You must be signed in to change notification settings - Fork 0
/
device7.js
30 lines (26 loc) · 818 Bytes
/
device7.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
25
26
27
28
29
30
// this file is for random testing to demonstrate the api connection
const needle = require('needle');
// buiding id for this devide is 7, it is hardcorded
const id = 7;
const data = {id};
let val = 0;
// check random number to decide that the building will increase or decrease
const check = () => {
val = parseInt(Math.random()*100) %2;
if (val === 0) {
needle('put', 'https://peoplecounting-server-api.herokuapp.com/countplus', data, {json: true})
.then((res) => {
console.log('message: ', res.body);
}).catch((err) => {
console.error(err);
});
} else {
needle('put', 'https://peoplecounting-server-api.herokuapp.com/countminus', data, {json: true})
.then((res) => {
console.log('message: ', res.body);
}).catch((err) => {
console.error(err);
});
}
};
setInterval(check , 3000);