-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_temp.html
160 lines (130 loc) · 6.19 KB
/
index_temp.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
149
150
151
152
153
154
155
156
157
158
159
160
<!doctype html>
<html>
<head>
<title>Tempareture show</title>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
console.log('Sajal');
$(function () {
var socket = io.connect("http://localhost:3000");
socket.on('temperature', function(temperature) {
$("#termometer").val(temperature + "°C");
//console.log(temperature);
// var cel = temperature;
// var uid = firebase.database().ref().child('users').push().key;
// var data = {
// Celsius: cel
// }
// var updates = {};
// updates['/Temp/' + uid] = data;
// firebase.database().ref().update(updates);
});
console.log('In the function --> Finding value');
socket.on('temperature1', function(temperature1) {
$("#termometer1").val(temperature1 + "K");
});
socket.on('temperature2', function(temperature2) {
$("#termometer2").val(temperature2 + "°F");
});
socket.on('temperature', function(temperature) {
var cel = temperature;
var kel = temperature+273.15;
var far = (cel*1.8) +32 ;
var uid = firebase.database().ref().child('users').push().key;
var data = {
Celsius: cel,
Kelvin : kel,
fahrenheit: far
}
var updates = {};
updates['/Temper/' + uid] = data;
firebase.database().ref().update(updates);
});
$("#light_button").click(function() {
changeBtnState("#light_button", "#light_status");
socket.emit('light_status', $("#light_status").val());
console.log($("#light_button").val());
});
socket.on('light_status', function() { changeBtnState("#light_button", "#light_status") });
socket.on('c_msg', function(c_msg){
$("#connection_status").val(c_msg);
});
socket.on('reconnecting', () => {
$("#connection_status").val("Reconnectting....");
});
socket.on('disconnect', () => {
$("#connection_status").val("Disconnected.");
});
function changeBtnState(btn, input) {
var btnClass = $(btn).attr('class');
var text, state, newBtnClass, oldBtnClass;
if(btnClass === "btn btn-success") {
oldBtnClass = 'btn-success';
newBtnClass = 'btn-danger';
text = 'off';
state = "On";
}
else if(btnClass === "btn btn-danger") {
oldBtnClass = 'btn-danger';
newBtnClass = 'btn-success';
text = 'on';
state = "Off";
}
$(btn).removeClass(oldBtnClass);
$(btn).addClass(newBtnClass);
$(btn).text("Turn " + text);
// console.log(btn + " is " + state);
$(input).val(state);
}
});
</script>
</head>
<body>
<h2>Temperature</h2>
<p>
<label>Connection is: </label>
<input type="text" id="connection_status" style="border: 0;color: #0339fc" value="Not connected" ><br>
</p>
<p>
<label style="padding-left: 50px;">In celsius: </label>
<input type="text" id="termometer" readonly style="border:0; color:#0339fc; font-weight:bold; margin: 5px" value="31°C">
</p>
<p>
<label style="padding-left: 50px;">In fahrenheit: </label>
<input type="text" id="termometer1" readonly style="border:0; color:#0339fc; font-weight:bold; margin: 5px">
</p>
<p>
<label style="padding-left: 50px;">In kelvin: </label>
<input type="text" id="termometer2" readonly style="border:0; color:#0339fc; font-weight:bold; margin: 5px">
</p>
<p style="padding-left: 50px;">
<label>Light is: </label>
<input type="text" id="light_status" style="border: 0;color: #0339fc" value="off" ><br>
<button type="button" class="btn btn-success" id="light_button" href="#">LED ON/OFF</button>
</p>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.4.0/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.4.0/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script>
<script>
//console.log("Firebase here.")
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyDLgFOUVcpwdJlFbdkuBHzEnjPJjee5Pts",
authDomain: "project-temp-e7a54.firebaseapp.com",
databaseURL: "https://project-temp-e7a54.firebaseio.com",
projectId: "project-temp-e7a54",
storageBucket: "project-temp-e7a54.appspot.com",
messagingSenderId: "355226341693",
appId: "1:355226341693:web:6971fbce0a39e970d53554",
measurementId: "G-H8LKD98FMZ"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
</body>
</html>