Joe Hanson
Published

Publishing Temperature Data in Realtime with Tessel Climate

How to collect and publish temperature and humidity data in realtime using the Tessel Climate module.

BeginnerFull instructions provided893
Publishing Temperature Data in Realtime with Tessel Climate

Things used in this project

Story

Read more

Code

File 1

JavaScript
GitHub gist: https://gist.github.com/ToeJamson/5f014147a08d47a39ba7
(function() {
  var PUBNUB, channel, climate, climatelib, tessel, uuid;
  tessel = require('tessel');
  climatelib = require('climate-si7020');
  climate = climatelib.use(tessel.port['D']);

File 2

JavaScript
  channel = process.argv[2];
  uuid = tessel.deviceId();

File 3

JavaScript
  PUBNUB = require("pubnub").init({
    publish_key: "publish_key_here",
    subscribe_key: "subscribe_key_here",
    uuid: uuid
  });

File 4

JavaScript
  climate.on('ready', function(version) {
    console.log('Ready to read climate sensor');

File 5

JavaScript
    return setInterval(function() {
      return climate.readTemperature(function() {
        var temp_args;
        temp_args = arguments;
        return climate.readHumidity(function() {
          var humid_args;
          humid_args = arguments;
          console.log("Temp in C : ", JSON.stringify(temp_args[1].toFixed(4)), " ",
                      "Humidity: ", JSON.stringify(humid_args[1].toFixed(4)), "%RH");
          return PUBNUB.publish({
            channel: channel,
            message: {
              temperature: temp_args,
              humidity: humid_args
            }
          });
        });
      });
    }, 2000);
  });

File 6

JavaScript
  climate.on('error', function(err) {
    return console.error(err);
  });
}).call(this);

Credits

Dani Dewitt

Posted by Joe Hanson

Comments

Add projectSign up / Login