Skip to content
bigkevmcd edited this page Oct 16, 2012 · 1 revision

A simple script to upload the temperature and humidity to Cosm using my node cosm api.

var rfxcom = require('rfxcom'),
    cosm = require('cosm');

var rfxtrx = new rfxcom.RfxCom('/dev/ttyUSB0', {debug: true}),
    client = new cosm.Cosm('!!insert API key here!!'),
    feed = new cosm.Feed(cosm, {id: 12345}); // replace with a created feed id
    humidity = new cosm.Datastream(client, feed, {id: 1}),  // replace 1 with a created stream id
    temperature = new cosm.Datastream(client, feed, {id: 2});  // replace 2 with a created stream id
  
var OUTSIDE_SENSOR = "0xAF01";

rfxtrx.on("th3", function (evt) {
  if (evt.id === OUTSIDE_SENSOR) {
    temperature.addPoint(evt.temperature);
    humidity.addPoint(evt.humidity);
  };
});

rfxtrx.initialise(function (error) {
  if (error) {
    throw new Error("Unable to initialise the rfx device");
  };
});
Clone this wiki locally