-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbloods.js
138 lines (117 loc) · 3.73 KB
/
bloods.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const axios = require('axios');
const { send } = require('process');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function send_iot_gateway(data, op){
if(op == 1) { //BP
send_bloodpressure(data, "63001416")
}else if(op == 2){ //BG
send_bloodglucose(data, "6300142F")
}
}
function gen_bloodpressue(){
return {
sys: Math.round(getRandomArbitrary(110, 120)),
dia: Math.round(getRandomArbitrary(70, 80)),
pul: Math.round(getRandomArbitrary(60, 100))
}
// return {sys: 20, dia: 50, pul: 100}
}
function gen_bloodglucose(){
return {
glu: Math.round(getRandomArbitrary(170, 200)),
meal: Math.round(getRandomArbitrary(0, 4))
}
// return {glu: 1, meal: 2}
}
function send_bloodpressure(input, mac){
var body = {
"Content-Type": "application/json",
"X-Signature": "XSIG",
mac: mac,
data: [
{
type: "190002",
values: {
sys: input.sys,
dia: input.dia,
pul: input.pul
}
}
]
}
var config = {
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer VzltaDd3PT06U0dlb2hQdzQ4dTUyZjIwN3kwSmJzNFF2aWJ6SkxISzRpZkxPQ2s2c0NmWg=="
}
}
var api_body = {
message: "Systolic: " + input.sys + "\nDiastolic: " + input.dia + "\nPulse: " + input.pul,
token: "SGeohPw48u52f207y0Jbs4QvibzJLHK4ifLOCk6sCfZ"
}
axios.post("http://localhost/bloodpressure", body)
.then(res => {
// console.log(res.statusText)
axios.post("https://docareportal.com/api/line/notify/send", api_body, config)
// .then(result => console.log(result.statusText))
.catch(err => console.log(err))
})
.catch(err => console.log("ERROR GEN TEMP"))
}
function send_bloodglucose(input, mac){
var body = {
"Content-Type": "application/json",
"X-Signature": "XSIG",
mac: mac,
data: [
{
type: "190003",
values: {
glu: input.glu,
meal: input.meal
}
}
]
}
var _meal = ''
if(input.meal == 0) _meal = "Before"
else if(input.meal == 1) _meal = "After"
else if(input.meal == 2) _meal = "Fasting"
else if(input.meal == 3) _meal = "Others"
else if(input.meal == 4) _meal = "Unspecified"
var config = {
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer VzltaDd3PT06U0dlb2hQdzQ4dTUyZjIwN3kwSmJzNFF2aWJ6SkxISzRpZkxPQ2s2c0NmWg=="
}
}
var api_body = {
message: "Glucose: " + input.glu + "\nMeal: " + _meal,
token: "SGeohPw48u52f207y0Jbs4QvibzJLHK4ifLOCk6sCfZ"
}
axios.post("http://localhost/bloodglucose", body)
.then(res => {
// console.log(res.statusText)
axios.post("https://docareportal.com/api/line/notify/send", api_body, config)
// .then(result => console.log(result.statusText))
.catch(err => console.log(err))
})
.catch(err => console.log("ERROR GEN TEMP"))
}
function recursive(){
rl.question('What Operation (1.BP 2.BG): ', (op) => {
console.log("You answered: " + op);
recursive()
if(op == 1) send_iot_gateway(gen_bloodpressue(), 1)
else if(op == 2) send_iot_gateway(gen_bloodglucose(), 2)
// rl.close();
});
}
recursive()