Last active
May 8, 2019 19:13
-
-
Save tom-a/22fbea59b3eba77bb5fe3881c43d50ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ambient = require('ambient-lib'); | |
const five = require('johnny-five'); | |
const board = new five.Board({ | |
port: '/dev/cuaU0' | |
}); | |
ambient.connect(00000,'xxxxxxxxxxxxxxx'); | |
board.on('ready', function() { | |
var multi = new five.Multi({ | |
controller: "BME280", | |
address: 0x76, | |
freq: 300000 | |
}); | |
multi.on('data', function() { | |
const c = this.thermometer.celsius; | |
const p = this.barometer.pressure; | |
const hum = this.hygrometer.relativeHumidity; | |
const now = new Date(); | |
const y = now.getFullYear(); | |
const m = ("00" + (now.getMonth()+1)).slice(-2); | |
const d = ("00" + now.getDate()).slice(-2); | |
const h = ("00" + now.getHours()).slice(-2); | |
const min = ("00" + now.getMinutes()).slice(-2); | |
const s = ("00" + now.getSeconds()).slice(-2); | |
const result = `${y}-${m}-${d}T${h}:${min}:${s} ${c}℃ ${hum}% ${p}hPa`; | |
console.log(result); | |
ambient.send({d1: c, d2: hum, d3: p}, (err, res, body) => { | |
if (err) { console.log(err); } | |
console.log(res.statusCode); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment