-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (37 loc) · 1.39 KB
/
app.js
File metadata and controls
48 lines (37 loc) · 1.39 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
'use strict';
var awsIot = require('aws-iot-device-sdk');
var Chance = require('chance'); // used to randomize bool values
var chance = new Chance();
// used to add linebreaks to cert strings
var pattern = /#####/g;
var device = awsIot.device({
privateKey: new Buffer(process.env.AWS_PRIVATE_KEY.replace(pattern, '\n')),
clientCert: new Buffer(process.env.AWS_CERT.replace(pattern, '\n')),
caCert: new Buffer(process.env.AWS_ROOT_CA.replace(pattern, '\r\n')),
clientId: process.env.RESIN_DEVICE_UUID,
region: process.env.AWS_REGION
});
var path = 'rotated/images/'
var spawn = require('child_process').spawn;
device.on('connect', function() {
console.log('connect');
device.subscribe('sensor');
// publish data
// setInterval(function () {
// var reading = chance.floating({min: 0, max: 200});
// device.publish('sensor', JSON.stringify({ reading: reading }));
// }, process.env.INTERVAL || 3000);
});
device.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
var ls = spawn('fbi', ['-d', '/dev/fb1', '-T', '1', '-noverbose', '-a', path + payload.toString() + '.png']);
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
ls.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
});