-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws-soilsensor.js
More file actions
66 lines (48 loc) · 1.45 KB
/
Copy pathaws-soilsensor.js
File metadata and controls
66 lines (48 loc) · 1.45 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
'use strict';
var Cylon = require('cylon');
var awsIot = require('aws-iot-device-sdk');
var fs = require('fs');
var args = require('minimist')(process.argv.slice(2));
//console.log(argv);
var privateKey = fs.readFileSync(args['private-key']);
var clientCertificate = fs.readFileSync(args['client-certificate']);
var caCertificate = fs.readFileSync(args['ca-certificate']);
var device = awsIot.device({
keyPath: args['private-key'],
certPath: args['client-certificate'],
caPath: args['ca-certificate'],
clientId: args['client-id'],
host: args['host-name']
});
device
.on('connect', function() {
console.log('connect');
device.subscribe('topic_1');
});
device
.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});
Cylon.robot({
connections: {
edison: {
adaptor: 'intel-iot'
}
},
devices: {
soilSensorPin0: {
driver: 'analog-sensor',
pin: 0
}
},
work: function(my) {
var soilMoisture0 = 0;
var voltage = 0;
var temperature = 0;
every((5).seconds(), function() {
soilMoisture0 = my.soilSensorPin0.analogRead();
console.log(new Date().toLocaleString() + " ==> " + soilMoisture0);
device.publish('value', JSON.stringify({id:"soilSensor0",value: soilMoisture0 , date: new Date()}));
});
}
}).start();