Skip to content

Commit

Permalink
save press button to local DB
Browse files Browse the repository at this point in the history
  • Loading branch information
saoron committed Nov 21, 2017
1 parent 5558a04 commit 2b6f567
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions daemons/bluetooth/characteristic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var util = require('util');
var spawn = require("child_process").spawn;
var fs = require("fs");

var bleno = require('bleno');

Expand Down Expand Up @@ -40,24 +41,35 @@ buttonStream.prototype.onSubscribe = function (maxValueSize, updateValueCallback
gpio.on('change', function (channel, value) {

if (value) {
var currentTimeStamp = parseInt(new Date().getTime() / 1000).toString();

// save currentTimestamp in the db
var savedVideosPath = '/home/Cardigan/modules/video/savedVideos.json'
fs.appendFile(savedVideosPath, ',' + currentTimeStamp, function (err) {
if (err) throw err;
console.log('Saved!');
});

// push videoId to app
var process = spawn('python',["/home/Cardigan/modules/indicators/python/states/buttonPress.py"]);

if (ex){
var process = spawn('python',["/home/Cardigan/modules/indicators/python/states/standalone.py", "buttonPress"]);

var currentTimeStamp = parseInt(new Date().getTime() / 1000).toString();
var data = new Buffer(Buffer.byteLength(currentTimeStamp, 'utf8') + 2);
var data = new Buffer(Buffer.byteLength(currentTimeStamp, 'utf8') + 2);

data.writeUInt32LE(currentTimeStamp, 0);
data.writeUInt32LE(currentTimeStamp, 0);

console.log('NotifyOnlyCharacteristic update value: ' + currentTimeStamp);
ex(data);
console.log('NotifyOnlyCharacteristic update value: ' + currentTimeStamp);
ex(data);
}else{
var process = spawn('python',["/home/Cardigan/modules/indicators/python/states/standalone.py", "buttonPressOffline"]);
}

}

});

buttonStream.prototype.onUnsubscribe = function () {
this._updateValueCallback = null;
ex = null
};


Expand Down

0 comments on commit 2b6f567

Please sign in to comment.