Skip to content

BME280 Barometric Pressure, Temperature, Humidity sensor

Jake Hartnell edited this page Nov 9, 2016 · 4 revisions
// Require the Grow.js build and johnny-five library.
var GrowInstance = require('Grow.js');
var five = require('johnny-five');
var ascii = require('ascii-codes');

// Create a new board object
var board = new five.Board();

// When board emits a 'ready' event run this start function.
board.on('ready', function start() {
    // Create a new grow instance.
    var grow = new GrowInstance({
        uuid: 'PASTE_UUID_HERE',
        token: 'PASTE_TOKEN_HERE',
        properties: {
            name: {
                type: String,
                value:'BME280'
            }
        },

        start: function () {
            var multi = new five.Multi({
                controller: "BME280"
            });

            setInterval(function() {
                grow.call('temp_data');
                grow.call('barometric_data');
                grow.call('humidity_data')
            }, 2000);
        },

        temp_data: function () {
            // Send value to Grow-IoT
            grow.emit({
              type: 'temperature',
              value: multi.temperature.celsius
            });
        },

        barometric_data: function () {
            // Send value to Grow-IoT
            grow.log({
              type: 'barometric',
              value: multi.barometer.pressure
            });
        },
        
        humidity_data: function () {
            // Send value to Grow-IoT
            grow.log({
              type: 'humidity',
              value: multi.hygrometer.relativeHumidity
            });
        }
    });
});