Spivey
Published © MIT

How to Build Your Own Weather Station Using a Raspberry Pi

In this tutorial, we will go over how to create a weather station using a raspberry pi and send events to Wia.

BeginnerFull instructions provided1 hour6,286
How to Build Your Own Weather Station Using a Raspberry Pi

Things used in this project

Story

Read more

Code

Index.js

JavaScript
'use strict';
var wia = require('wia')('device-secret-key');
var util = require('util')
var nodeimu  = require('nodeimu');
var IMU = new nodeimu.IMU();
var tic = new Date();
var callback = function (error, data) {
 var toc = new Date();
 if (error) {
   console.log(error);
   return;
 }
 // Send temperature data
 wia.events.publish({
   name: "temperature",
   data: data.temperature.toFixed(4) // data received from temperature sensor
 });
 // Send pressure data
 wia.events.publish({
   name: "pressure",
   data: data.pressure.toFixed(4) // data received from pressure sensor
 });
 // Send humidity data
 wia.events.publish({
   name: "humidity",
   data: data.humidity.toFixed(4) // data received from humidity sensor
 });
 setTimeout(function() { tic = new Date(); IMU.getValue(callback); } , 250 - (toc - tic));
}
// Using the MQTT stream
wia.stream.on('connect', function() {
 IMU.getValue(callback);
});
wia.stream.connect();

Credits

Spivey
82 projects • 59 followers
Tourist in a Tutu || US Born || Melbourne/Mexico/California Raised || New Yorker at ❤️ || SF to Dublin to be COO of Wia the best IoT startup

Comments