-
Notifications
You must be signed in to change notification settings - Fork 2
/
sensorMonitor.js
43 lines (34 loc) · 1.52 KB
/
sensorMonitor.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
var temperatureReading = 28;
var moistureReading = 30;
var humidityReading = 50;
var ambientlightReading = 50;
readSensor() // initial value
function readSensor(){
$.getJSON("https://things.ubidots.com/api/v1.6/devices/demo/soil/lv?token=A1E-###########################",function(data){
moistureReading = data;
updates();
});
$.getJSON("https://things.ubidots.com/api/v1.6/devices/demo/temp/lv?token=A1E-###########################",function(data){
temperatureReading = data;
updates();
});
$.getJSON("https://things.ubidots.com/api/v1.6/devices/demo/humidity/lv?token=A1E-###########################",function(data){
humidityReading = data;
updates();
});
$.getJSON("https://things.ubidots.com/api/v1.6/devices/demo/ambientlight/lv?token=A1E-###########################",function(data){
ambientlightReading = data;
updates();
});
}
setInterval(readSensor,100);
function updates(){
var soilMoist = 100-parseInt(moistureReading*(100/1024));
$("#PreviewGaugeMeter_1").gaugeMeter({text:soilMoist,percent:soilMoist});
if (temperatureReading >100) { temperatureReading = 0;}
$("#PreviewGaugeMeter_2").gaugeMeter({text:temperatureReading,percent:temperatureReading});
if (humidityReading >=100) { humidityReading = 0;}
$("#PreviewGaugeMeter_3").gaugeMeter({text:humidityReading,percent:humidityReading});
var ambiLight = parseInt(ambientlightReading*(100/1024));
$("#PreviewGaugeMeter_4").gaugeMeter({text:ambiLight,percent:ambiLight});
}