forked from alaawahba13/IOT_project_healthmonitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensorsTest.html
148 lines (125 loc) · 4.66 KB
/
SensorsTest.html
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
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="Viewport" content="width=device-width" intial-scale="1.0">
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
<title>Organization task</title>
</head>
<body style="background-color:rgb(169, 169, 169);" >
<header>
<h1 class=" text-light text-center bg-dark " style="padding:0.4em;box-shadow: 5px 1px 10px 1px rgb(6, 223, 252)">Health monitoring system</h1>
</header>
<div class="container text-center text-light " style="padding: 2rem;">
<div class="row justify-content-center">
<div class="col-sm-6">
<div class="card text-bg-dark mx-auto" style="box-shadow: 5px 1px 10px 1px rgb(0, 0, 0);">
<div class="card-header">Temperature</div>
<div class="card-body">
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated" style="width:20%" id="prog1"></div>
</div>
Your temperature is <span id="lapel1">0</span>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-bg-dark mx-auto" style="box-shadow: 5px 1px 10px 1px rgb(0, 0, 0);">
<div class="card-header">Heart rate</div>
<div class="card-body">
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated" style="width:20%" id="prog2"></div>
</div>
Your heart rate is <span id="lapel2">0</span>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-bg-dark mx-auto" style="box-shadow: 5px 1px 10px 1px rgb(0, 0, 0);">
<div class="card-header">spO2 %</div>
<div class="card-body">
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated" style="width:0%" id="prog3"></div>
</div>
Your oxygen is <span id="lapel3">0</span>%
</div>
</div>
</div>
</div>
<hr>
<div>Heart Beat Plotter</div>
<div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js"></script>
<canvas id="chart"></canvas>
</div>
</div>
</body>
</html>
<script>
const Host = "ws://172.20.10.5:3000" ;
var ws = new WebSocket(Host) ;
ws.onopen=function(){
console.log('Connected to server')
}
ws.onmessage=function(event){
const data = JSON.parse(event.data);
const Temperature = data.value1;
const HeartRate = data.value2;
const SPO2 = data.value3;
console.log(Temperature);
console.log(HeartRate);
console.log(SPO2);
var progressBar1 = document.getElementById("prog1");
var progressBar2 = document.getElementById("prog2");
var progressBar3 = document.getElementById("prog3");
progressBar1.style.width = parseInt(Temperature) + "%";
lapel1.innerHTML = Temperature;
progressBar2.style.width = parseInt(HeartRate) + "%";
lapel2.innerHTML = HeartRate;
if(parseInt(SPO2)>=90){
progressBar3.style.width = parseInt(SPO2) + "%";
lapel3.innerHTML = SPO2;}
chart.data.labels.push(new Date().toLocaleTimeString());
chart.data.datasets[0].data.push(parseFloat(HeartRate));
chart.update();
function checkTemp() {
if (parseInt(Temperature) >= 40) {
sendTelegramMessage("Warning!!! , Temberature is : "+ Temperature +" , Heart rate is : "+HeartRate);
}
}
progressBar1.addEventListener("input", checkTemp());
}
function sendTelegramMessage(message) {
const telegramBotToken = "6140302269:AAG5rMISL5xamoIG5dnJcDuaJOK9qt1vWQU";
const chatId = "819635862";
const url = `https://api.telegram.org/bot${telegramBotToken}/sendMessage?chat_id=${chatId}&text=${message}`;
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error("Failed to send message");
}
})
.catch(error => {
console.error(error);
});
}
const chart = new Chart(document.getElementById('chart'), {
type: 'line',
data: {
labels: [],
datasets: [
{
label: 'Sensor Data',
data: [],
fill: false,
borderColor: 'black',
borderWidth: 0.5,
tension: 0,
pointRadius: 0,
pointHoverRadius: 1,
},
],
},
});
</script>