-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
53 lines (48 loc) · 1.39 KB
/
test.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'dotenv/config';
const { ID, IP, GROUP} = process.env;
import axios from "axios";
console.log(await getMinDeviceValue());
console.log(await getMaxDeviceValue());
async function getMinDeviceValue() {
//return minvalue from database using axios
return new Promise(async (resolve, reject) => {
await axios
.get(`http://${IP}/api/stations/${ID}`)
.then((val) => {
resolve(val.data.minDeviceValue);
})
.catch((err) => {
reject(err);
});
});
}
async function getMaxDeviceValue() {
//return minvalue from database using axios
return new Promise(async (resolve, reject) => {
await axios
.get(`http://${IP}/api/stations/${ID}`)
.then((val) => {
resolve(val.data.maxDeviceValue);
})
.catch((err) => {
reject(err);
});
});
}
let lantern = await getLantern()
console.log(lantern);
async function getLantern() {
console.log('Getting Lantern...');
let lantern;
try {
lantern = await axios.get(`http://${IP}/api/lanterns/randomUser/${GROUP}`);
console.log(`Got: ${lantern.data.id}`);
lantern= lantern.data.id
} catch (error) {
console.log("🚀 ~ file: test.js ~ line 46 ~ getLantern ~ error", error.data);
await axios.put(`http://${IP}/api/stations/${ID}`, { rgb: '50, 50, 50, 255', lantern: null });
// await getLantern();
}
return lantern;
}
console.log(await getLantern());