Skip to content

Latest commit

 

History

History
78 lines (50 loc) · 6.33 KB

README.md

File metadata and controls

78 lines (50 loc) · 6.33 KB

weather-station

This project creates a weather station using two Raspberry Pis and a DHT11 sensor. The end product runs a python script that uses sensor readings from the DHT11 sensor to get the temperature and humidity. To learn more about this, check out my post Building a Weather Station with a Raspberry Pi and Firebase.

NOAA APIs

The project also calls the National Weather Service APIs (available here) to provide local forecast data. If you want to use this in your area, you'll need to first call https://api.weather.gov/points/{<latitude>,<longitude>} and then you can get the assoicated forecast and forecastHourly endpoints in the JSON response. You can learn more in my post here. For the purposes of this project, you just need to update the forecastEndpoint and forecastHourlyEndpoint values in the file at /frontend/src/app.js.

Orchestration

One Raspberry Pi runs two python scripts in the "sensors" folder (I recommend using cronjobs to set them up to repeat). The two python scripts are:

  1. weather.py runs every 4 minutes and collections the current temperature and humidity and calls the api/weather function to update those values in Firebase.
  2. noaa.py runs every 12 hours and calls the NOAA endpoints to get the forecast and hourly temperatures and then class the api/noaa function to update those values in Firebase.

A second Raspberry Pi runs the node server in the server.js file at the project root. This serves up a React App that can be reached on port 1122. So if you run localhost:1122 on the browser on the Raspberry Pi running the frontend you should see the weather station successfully. The frontend calls the api/results endpoint every 5 minutes to update the screen to reflect the values retrieved from Firebase.

Hardware

To run this project, you'll need:

Software

For this to run on the Raspberry Pi, you need a desktop environment (recommend the Raspbian OS with Desktop. As of 07/20/2020 Raspberry Pi offers a downloader that streamlines this process and can be seen here.

Once you've got the initial desktop OS setup, I recommend using SSH to do most of the work with the pi directly.

  • To copy files from remote to local system I followed this scp -r <pi_user>@<pi_address>:<pi_folder> <local_directory_to_upload>
  • To copy files from local to remote system: scp -r <local_directory_to_upload> <pi_user>@<pi_address>:<pi_folder>

You'll need to setup the pi with the following:

  • Depending on the OS you may need to install pip with sudo apt install python-pip
  • In order for the DHT11 to work with your python program, you'll need to follow the instructions here

Then you can run the whole project by first running ./start.sh and then open the browser to [http://localhost:1122(http://localhost:1122) and you're good to go!

Firebase

In order to interact with Firebase's Firestore Database, I created an API that you can see in the functions folder. This API has endpoints for saving and retrieving the Firestore information. If you want to build this project, you first deploy that to Firebase and then add the HTTP endpoints to the Python scripts in the sensors folder and the useEffect hook in the React project.

To learn more about this I recommend reading my post Building an API with Firebase.

Project Setup

If you want to run this for your own setup, you'll need to do a few things to get everything in order first.

  1. Create a Firebase account and deploy the serverless API within the functions folder (see Building an API with Firebase)
  2. Modify the noaa_endpoint variable in the sensors/noaa.py Python Script to be the hosted endpoint for the Firebase Function /api/noaa route
  3. Modify the weather_endpoint variable in the sensors/weather.py Python Script to be the hosted endpoint for the Firebase Function /api/weather route
  4. Modify the results_endpoint variable in the src/App.js file to be the hosted endpoint for the Firebase Function /api/results route
  5. Push the Python scripts in the sensors folder to a Raspberry Pi that is hooked up to a DHT11 sensor and run them with cronjobs (noaa.py every 12 hours, weather.py every 4 hours)
  6. Push this project to a Raspberry Pi that is hooked up to an HDMI monitor and has Node installed and then run the start.sh shell script that is in the project root
  7. Go to localhost:1122 on the Raspberry Pi hooked up to an HDMI monitor and you're all setup!

Helpful Links

I found the following very helpful when building this project: