Skip to content

Commit

Permalink
[UPDATE] register start method
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Brandimarti committed May 25, 2020
1 parent e9b4cc4 commit 3ad087b
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions src/arduino/register.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
const { Board, Thermometer } = require("johnny-five");
const fs = require('fs');
const path = require('path');

const { Board, Thermometer } = require('johnny-five')
const fs = require('fs')
const path = require('path')

const board = new Board()


board.on("ready", () => {

const thermometer = new Thermometer({
controller: "TMP36",
pin: "A0"
});

thermometer.on("change", () => {

const ts = Date.now();
const date = new Date(ts);
let day = date.getDate();
let month = date.getMonth() + 1;
let hours = date.getUTCHours() +2;
let year = date.getFullYear()
const {celsius} = thermometer;
let record = day + ',' + month + ',' + year + ',' + hours + ',' + celsius;

console.log("Thermometer");
console.log(" day : ", day);
console.log(" month : ", month);
console.log(" year : ", year)
console.log(" hours : ", hours);
console.log(" celsius : ", celsius);
console.log("--------------------------------------");

var fs = require('fs');
var logStream = fs.createWriteStream(path.resolve('./src/database/log.csv'), {flags: 'a'});
logStream.write(record);
logStream.end('\n');
sleep(1000);

});


function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}

});


module.exports = {board};

function start() {
board.on('ready', () => {
const thermometer = new Thermometer({
controller: 'TMP36',
pin: 'A0',
})

thermometer.on('change', () => {
const ts = Date.now()
const date = new Date(ts)
let day = date.getDate()
let month = date.getMonth() + 1
let hours = date.getUTCHours() + 2
let year = date.getFullYear()
const { celsius } = thermometer
let record = day + ',' + month + ',' + year + ',' + hours + ',' + celsius
save(day,month,hours,year,celsius,record);
})
})
}

function save(day,month,hours,year,celsius,record) {

console.log('Thermometer')
console.log('day: ', day)
console.log('month: ', month)
console.log('year: ', year)
console.log('hours: ', hours)
console.log('celsius: ', celsius)
console.log('--------------------------------------')

var fs = require('fs')
var logStream = fs.createWriteStream(path.resolve('./src/database/log.csv'), {
flags: 'a',
})
logStream.write(record)
logStream.end('\n')
sleep(60000);
}

function sleep(milliseconds) {
const date = Date.now()
let currentDate = null
do {
currentDate = Date.now()
} while (currentDate - date < milliseconds)
}


module.exports = { board, start }

0 comments on commit 3ad087b

Please sign in to comment.