forked from ruuvi/ruuvi-sensor-protocols
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
273 lines (272 loc) · 11.6 KB
/
index.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!doctype html>
<html lang="fi">
<head>
<meta charset="UTF-8">
<link href='https://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, minimum-scale=1.0, user-scalable=1" />
<meta name="HandheldFriendly" content="true">
<meta name="format-detection" content="telephone=no">
<title>Ruuvi Weather Station</title>
<meta name="author" content="Ruuvi Innovations Ltd">
<meta name="description" content="Open the link to see the measurements" />
<meta name="author" content="">
<meta name="keywords" content="" />
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="css/ruu-vi-styles.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="js/respond.js"></script>
<![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="http://peterolson.github.com/BigInteger.js/BigInteger.min.js"></script>
<script>
/* Base91 - LICENSE: https://raw.githubusercontent.com/mscdex/base91.js/master/LICENSE */
(function() {
var hasNode = (typeof process !== 'undefined' && process.versions && process.versions.node),
hasTypedArray = (typeof Uint8Array !== 'undefined');
if (hasNode && require('fs').existsSync(__dirname + '/../build/Release/base91encdec.node')) {
module.exports = require(__dirname + '/../build/Release/base91encdec.node');
return;
}
var AVERAGE_ENCODING_RATIO = 1.2297,
ENCODING_TABLE = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';',
'<', '=', '>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~',
'"'
],
DECODING_TABLE = [
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 62, 90, 63, 64, 65, 66, 91, 67, 68, 69, 70, 71, 91, 72, 73,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 74, 75, 76, 77, 78, 79,
80, 0, 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, 81, 91, 82, 83, 84,
85, 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, 86, 87, 88, 89, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91
];
var i = 0;
var base91 = {
encode: function(data) {
var len = data.length,
output = '', ebq = 0, en = 0, ev = 0, j = 0, byte = 0;
if (typeof data === 'string') {
for (i = 0; i < len; ++i) {
byte = data.charCodeAt(i);
j = 0;
var lenj = (byte < 128
? 1
: (byte > 127 && byte < 2048
? 2
: 3));
for (; j < lenj; ++j) {
if (lenj === 1)
ebq |= byte << en;
else if (lenj === 2) {
if (j === 0)
ebq |= ((byte >> 6) | 192) << en;
else
ebq |= ((byte & 63) | 128) << en;
} else {
if (j === 0)
ebq |= ((byte >> 12) | 224) << en;
else if (j === 1)
ebq |= (((byte >> 6) & 63) | 128) << en;
else
ebq |= ((byte & 63) | 128) << en;
}
en += 8;
if (en > 13) {
ev = ebq & 8191;
if (ev > 88) {
ebq >>= 13;
en -= 13;
} else {
ev = ebq & 16383;
ebq >>= 14;
en -= 14;
}
output += ENCODING_TABLE[ev % 91];
output += ENCODING_TABLE[(ev / 91) | 0];
}
}
}
} else {
for (i = 0; i < len; ++i) {
ebq |= (data[i] & 255) << en;
en += 8;
if (en > 13) {
ev = ebq & 8191;
if (ev > 88) {
ebq >>= 13;
en -= 13;
} else {
ev = ebq & 16383;
ebq >>= 14;
en -= 14;
}
output += ENCODING_TABLE[ev % 91];
output += ENCODING_TABLE[(ev / 91) | 0];
}
}
}
if (en > 0) {
output += ENCODING_TABLE[ebq % 91];
if (en > 7 || ebq > 90)
output += ENCODING_TABLE[(ebq / 91) | 0];
}
return output;
},
decode: function(data) {
var len = data.length,
estimatedSize = ((len / AVERAGE_ENCODING_RATIO) | 0),
dbq = 0, dn = 0, dv = -1, i = 0, o = -1, byte = 0,
output = new Array(estimatedSize);
if (typeof data === 'string') {
for (i = 0; i < len; ++i) {
byte = data.charCodeAt(i);
if (DECODING_TABLE[byte] === 91)
continue;
if (dv === -1)
dv = DECODING_TABLE[byte];
else {
dv += DECODING_TABLE[byte] * 91;
dbq |= dv << dn;
dn += ((dv & 8191) > 88 ? 13 : 14);
do {
if (++o >= estimatedSize)
output.push(dbq & 0xFF);
else
output[o] = dbq & 0xFF;
dbq >>= 8;
dn -= 8;
} while (dn > 7);
dv = -1;
}
}
} else {
for (i = 0; i < len; ++i) {
byte = data[i];
if (DECODING_TABLE[byte] === 91)
continue;
if (dv === -1)
dv = DECODING_TABLE[byte];
else {
dv += DECODING_TABLE[byte] * 91;
dbq |= dv << dn;
dn += ((dv & 8191) > 88 ? 13 : 14);
do {
if (++o >= estimatedSize)
output.push(dbq & 0xFF);
else
output[o] = dbq & 0xFF;
dbq >>= 8;
dn -= 8;
} while (dn > 7);
dv = -1;
}
}
}
if (dv !== -1) {
if (++o >= estimatedSize)
output.push(dbq | dv << dn);
else
output[o] = (dbq | dv << dn);
}
if (o > -1 && o < estimatedSize - 1)
output = output.slice(0, o + 1);
var ret;
if (hasNode)
ret = new Buffer(output);
else if (hasTypedArray) {
ret = new Uint8Array(output.length);
for (i = 0, len = output.length; i < len; ++i)
ret[i] = output[i];
} else
ret = output;
return ret;
}
};
if (hasNode)
module.exports = base91;
else
window.base91 = base91;
})();
</script>
<script type="text/javascript">
if(window.location.hash) {
$( document ).ready(function() {
var variables = window.location.hash.substr(1);
console.log("parsed hash = " + variables);
var decoded = base91.decode(variables);
console.log(decoded);
/*
0: uint8_t format; // (0x01 = realtime sensor readings)
1: uint8_t humidity; // one lsb is 0.5%
2-3: uint16_t temperature; // Signed 8.8 fixed-point notation.
4-5: uint16_t pressure; // (-50kPa)
6-7: uint16_t time; // seconds (now from reset, later maybe from last movement)
*/
var humidity = decoded[1] * 0.5;
//The bytes are swaped during the encoding, thus read byte 3 as first byte, byte 2 as 2nd
//Same goes for pressure and time
var uTemp = (((decoded[3] & 127) << 8) | decoded[2]);
var tempSign = (decoded[3] >> 7) & 1;
var temp = tempSign === 0 ? uTemp/256.0 : -1 * uTemp/256.0;
var air_pressure = ((decoded[5] << 8) + decoded[4]) + 50000;
var time_elapsed = (decoded[7] << 8) + decoded[6];
var time_formats = ['seconds', 'minutes', 'hours', 'days'];
$("#temperature").text(temp.toFixed(1));
$("#humidity").text(humidity);
$("#air_pressure").text(air_pressure/100);
$("#time_elapsed").text(time_elapsed);
});
} else {
window.location.replace("http://ruuvi.com");
}
</script>
</head>
<body>
<div class="container">
<header class="header">
<div class="branding">Ruuvi Innovations Ltd</div>
<h1>Measurements</h1>
</header>
<div class="content">
<ul class="measurements">
<li class="temperature">
<div class="measurement"><h3 id="temperature"></h3></div>
<div class="info"><p>Temperature<span>°C</span></p></div>
</li>
<li class="humidity">
<div class="measurement"><h3 id="humidity"></h3></div>
<div class="info"><p>Humidity<span>%</span></p></div>
</li>
<li class="air-pressure">
<div class="measurement"><h3 id="air_pressure"></h3></div>
<div class="info"><p>Air pressure<span>hPa</span></p></div>
</li>
<li class="time">
<div class="measurement"><h3 id="time_elapsed"></h3></div>
<div class="info"><p>Time elapsed<span class="small">Seconds after<br />last movement</span></p></div>
</li>
</ul>
</div>
</div>
</body>
</html>