element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Blog How to Build Your Own Weather Station Using a Raspberry Pi
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Internet of Things to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: anpivey
  • Date Created: 3 Aug 2018 9:00 AM Date Created
  • Views 1122 views
  • Likes 3 likes
  • Comments 3 comments
  • tutorial
  • raspberri pi
  • weather station
  • node.js
  • iot
  • diy electronics
Related
Recommended

How to Build Your Own Weather Station Using a Raspberry Pi

anpivey
anpivey
3 Aug 2018

image

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

This is an updated version of our old tutorial. There have been several changes to the Wia dashboard and code since our last tutorial.

What You Will Need

  • Raspberry Pi 2 or Model 3 B+
  • Raspberry Pi Sense HAT
  • Node.js and NPM must both be installed on the raspberry pi.

If you do not have it already installed, learn how to install node.js here.

Setting up the Raspberry Pi

First, you have to set up the Raspberry Pi. Our tutorial will walk you through it! Be sure to follow each step carefully. When you're ready, run ssh pi@('RASPBERRY-PI-IP-ADDRESS'). This will allow you to begin working in the raspberry pi terminal through your computer.

Setting up the Wia Node.js SDK

First, we need to create a folder on the raspberry pi to store our files. Create a new folder called wia-wether-device.

Next, initialize the package by creating a packackge.json file using the command line npm init. Hit enter for each of the prompts, right now they are not important.

Once you are through that, you can install the Wia SDK onto the raspberry pi. Install the Wia SDK by using the command line npm install --save wia.

Using the Sense HAT with Node.js

Next, we must install nodeimu so that we can use the sensors. Use the command npm install --save nodeimu.

Now, your package.json file should look like this:
image

Create Your Weather Device

Go to the Wia Dashboard and select Create a New Space then select Devices. Add a device and give it a name. Now, in the Configuration tab for your device, you will find device_secret_key which should begin with d_sk. This will be important later on.

The Code

Create a file called index.js. Then, copy the code from the example below and paste it into the index.js file.

Replace the device_secret_key with your device's secret key.

'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();

To test your program, run node index.js

Now, you should see events appearing in the Events tab for your device in the Wia Dashboard.

The App

Next, we will make a few widgets through Wia to present the data that the weather station collects. Log in to the Wia dashboard, and navigate to your device. Select the widgets tab and create a new widget. Name it Humidity. For the event box, type humidity exactly as it appears in the node.js code that you copy and pasted before. Select done and you will see the latest update! Follow these steps for temperature and pressure to finish your Weather Station project.

image

Web Page

Next, we will create a webpage and host it on GitHub so that we can check the weather from our weather station any time!

If you don't have a github account already, you can make one here.

Once you are set up with github, create a new repository and name it your-username.github.io. Check the box to initialize with a README.

Now, navigate to your new repository and create a new file. It must be named index.html. Copy and paste the following block of code:

  <!DOCTYPE html>

<html>

  <head>

    <meta charset="UTF-8">

  </head>

  <body>

 

    <h1>Wia Weather Station</h1>

 

  </body>

</html>

So far, our webpage is pretty blank. Navigate back to your Wia Dashboard. In the overview for your device, you can see your widgets. In the upper right hand corner of the widget, there should be a box with an arrow. Click the box. A screen like this should pop up.

image

 

Change the settings so that Anyone can view this widget and embed it in any website. You should also see Embed code, which will start with <iframe> and end with </iframe>. Copy the entire code and paste it below the <h1>Wia Weather Station</h1> line and above the </body> line. Your full code should look something like this:

 

  <!DOCTYPE html>

<html>

  <head>

    <meta charset="UTF-8">

  </head>

  <body>

 

    <h1>Wia Weather Station</h1>

 

    <iframe> YOUR WIDGET </iframe>

 

 

  </body>

</html>

Do this again with each widget.

Click commit changes. Now, visit your site at https://github.com/username/username.github.io

Now, you should see the weather from your raspberry pi appear on your own webpage!

image

  • Sign in to reply

Top Comments

  • anpivey
    anpivey over 6 years ago in reply to snidhi +2
    Hey Nidhi- We are using a Raspberry pi 3B+ then a sense hat which is the LED screen attached to the top of it. So the code above is for Raspberry Pi's Let me know if you have any other questions about…
  • snidhi
    snidhi over 6 years ago +1
    Please also mention which hardware sensors you are using for this weather station.I see that the blog is only written from a software perspective. Clearly all the hardware sensors will not be compatible…
  • snidhi
    snidhi over 6 years ago in reply to anpivey +1
    great thanks
  • snidhi
    snidhi over 6 years ago in reply to anpivey

    great thanks

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • anpivey
    anpivey over 6 years ago in reply to snidhi

    Hey Nidhi-

    We are using a Raspberry pi 3B+ then a sense hat which is the LED screen attached to the top of it. So the code above is for Raspberry Pi's image  Let me know if you have any other questions about the tutorial!

     

    Cheers

    Austin

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • snidhi
    snidhi over 6 years ago

    Please also mention which hardware sensors you are using for this weather station.I see that the blog is only written from a software perspective.

    Clearly all the hardware sensors will not be compatible with this code or will they be compatible?

     

    Cheers image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube