Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-driver.js
More file actions
Latest commit
103 lines (84 loc) · 2.15 KB
/
Copy pathexample-driver.js
File metadata and controls
103 lines (84 loc) · 2.15 KB
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
constGrow=require('Grow.js');
constraspio=require('raspi-io');
constfive=require('johnny-five');
// Create a new board object
constboard=newfive.Board({
io: newraspio()
});
// When board emits a 'ready' event run this start function.
board.on('ready',functionstart(){
// Declare needed variables.
varemit_data;
try{
varmulti=newfive.Multi({
controller: 'BME280'
});
}catch(err){
console.log('BME280 sensor not connected. Emitting random data.');
this.emit('message','BME280 sensor not connected.');
}
vargrowHub=newGrow({
uuid: '732db76b-7d92-4c6c-995f-ec0d34acf6f2',
token: '5qL8nsFpqDf7m4cY9u6uFoXDKMfGJHf2',
component: 'ClimateSensor',
properties: {
interval: 6000,
growfile: {
targets: {
temperature: {
min: 10,
max: 25
},
humidity: {
min: 10,
max: 80
},
}
}
},
start: function(){
console.log('Grow-Hub initialized.');
varinterval=this.get('interval');
emit_data=setInterval(()=>{
this.temp_data();
this.hum_data();
},interval);
if(multi){
letgrowfile=this.get('growfile');
this.registerTargets(growfile.targets);
}
},
stop: function(){
clearInterval(emit_data);
this.removeAllListeners();
this.removeTargets();
},
restart: function(){
this.stop();
this.start();
},
temp_data: function(){
if(multi){
varcurrentTemp=multi.thermometer.celsius;
this.emit('temperature',currentTemp);
console.log('Temperature: '+currentTemp);
}else{
this.emit('temperature',Math.random());
}
},
hum_data: function(){
if(multi){
varcurrentHumidity=multi.hygrometer.relativeHumidity;
this.emit('humidity',currentHumidity);
console.log('Humidity: '+currentHumidity);
}else{
this.emit('humidity',Math.random());
}
}
});
growHub.connect({
host: 'grow.commongarden.org',
port: 443,
ssl: true
});
});