Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.
/ weather-station Public archive

Raspberry Pi Weather Station with Node/React webserver to display data

Notifications You must be signed in to change notification settings

batiyeh/weather-station

Repository files navigation

Weather Station

Raspberry Pi Weather Station with Node/React webserver to display data

How to Start the Development Server

  1. Navigate into the root of the project directory with your terminal and run:
npm run dev

How to Start the Production Server

  1. Generate a build of the React frontend
cd website/
npm run build
cd ../
  1. Run the production server
npm run prod

File Structure

  1. server
  • controllers/: Contains all routes for each controller type.
  • models/: Contains all bookshelf (our ORM) models for the database. Import these when accessing data.
  • migrations/: Contains all knex database migrations as well as our initial db setup file.
  • bookshelf.js & knex.js: Database configuration files
  • server.js: Starts the express server.
  • app.js: Maps controllers to urls on the server.
  1. client/
  • client.py: Runs the client code meant to go on the Raspberry Pi
  1. website/
  • components/: Component classes which will be individually styled and placed into containers
  • containers/: Full page container (such as the "Connected Stations" page) which combines our components
  • styles/: All of our .css files are placed here
  • images/: All of our images are placed here
  • test/: React test files are placed here

Installing New Dependencies

  1. If you want to install a new dependency to be used both in development and in production:
npm install packagename --save
  1. If you want to install a new dependency only in development for testing purposes:
npm install packagename --save-dev

Migrating Databases

  1. Install knex, our query builder globally
npm install knex -g
  1. Run latest migrations
npm run migrate
  1. If you have any issues, rollback the database to the beginning
npm run rollback
  1. Review the knex documentation for more information here

Install Node Server + Website

This project requires the following dependencies before continuing the install:

  1. Node v9.5.0 - Install here
  2. Yarn v1.3.2 - Install here
  3. MySQL (On Mac OS, install via homebrew. For Windows, go here)
# Mac OS X only
brew install mysql
brew services start mysql

Database Setup:

  1. Create a MySQL user with the name "weatherstation" and password "ws1234".
# Log into your MySQL shell. If you have a password on your root account 
# also add -p onto the end of the following command. 
mysql -u root
# Once logged in, create the user
mysql > CREATE USER 'weatherstation'@'localhost' IDENTIFIED BY 'ws1234';
# Grant all privileges to the new user you have created
mysql > GRANT ALL PRIVILEGES ON * . * TO 'weatherstation'@'localhost';
mysql > FLUSH PRIVILEGES;
  1. Create a database with the name weatherstation while logged into your MySQL shell.
mysql > CREATE DATABASE weatherstation;

After you have installed the above dependencies:

  1. Using your terminal, cd into where you want to store your project directory.
  2. Install nodemon globally and the server dependencies:
npm i nodemon -g
  1. Clone the git repository
git clone https://github.com/batiyeh/weather-station-site
  1. Navigate inside the weather-station directory:
cd weather-station-site
  1. Install all required dependencies for both the server and the website
npm install; cd website; npm install; cd ../
  1. Create all necessary database tables
npm run migrate
  1. Run the development server
npm run dev

Install Client Code on Raspberry Pi

This is meant to be used on a Raspberry Pi running Raspbian OS but can be installed for testing on Mac OS or Windows. We are officially supporting only Raspbian OS for now.

Raspberry Pi

This project requires the following dependencies before continuing the install:

  1. Python 3.5+ (included on Raspberry Pi 3 Model B)

After you have installed the above dependencies:

  1. Open up terminal and navigate to where you want to store this project
  2. Clone the repository and navigate inside it.
git clone https://github.com/batiyeh/weather-station-site
cd weather-station/client
  1. Install the requirements that come with the project:
sudo pip3 install -r pi-requirements.txt
  1. Go to the weather station website and obtain an API Key from the admin page
  2. Go back to your Raspberry Pi, run the program with sudo, and enter in your API Key when prompted
sudo python3 client.py

Build Client Binary

  1. Open up terminal and navigate to where you have stored this project
  2. Navigate into the client folder
cd client/
  1. Run Pyinstaller to generate a binary build from our config file
pyinstaller weatherstation.spec -F
  1. The new client build should be in the dist/ directory in the client folder.

Set Binary to Start on Reboot

  1. Add the following line to the bottom of your .bashrc file in your home directory on the Raspberry Pi
cd path/to/weatherstation/binary; ./weatherstation > /dev/null 2> /dev/null &
  1. Same thing with just the code itself (optional for test purposes)
/usr/bin/python /home/pi/dev/weather-station-site/client/weatherstation.py > /dev/null 2> /dev/null &

Sensors

GPS

  1. Ensure the GPS sensor and RPI is near a window or outside.

  2. Install the necessary GPS libraries for data retrieval

sudo apt-get install gpsd gpsd-clients python-gps
  1. Connect our device to the gpsd library socket
sudo gpsd /dev/ttyACM0 -F /var/run/gpsd.sock
  1. Open the gpsd.sock file
sudo nano /etc/default/gpsd
  1. Add the following lines to the bottom of the gpsd.sock file
# Other options you want to pass to gpsd
START_DAEMON="true"
GPSD_OPTIONS="/dev/ttyACM0"
DEVICE=""
USBAUTO="true"
GPSD_SOCKET="/var/run/gpsd.sock"
  1. Reboot the Raspberry Pi.
sudo reboot
  1. Test that it is working
cpgs -s
# Wait a minute or two for it to find a satellite
# If it is not working, try running step #2 again

Humidity and Temperature

  1. Make sure that the sensor is open and not being covered by anything.

  2. Connect the + wire to the 2 pin on the Pi which is for 5V of power.

  3. Connect the - wire to the 6 pin on the Pi which is for Ground.

  4. Connect the data wire to the 8 pin on the Pi which is for the GPIO 14.

For pin numbering check this website with the GPIO Pinout Diagram https://www.jameco.com/Jameco/workshop/circuitnotes/raspberry-pi-circuit-note.html

  1. Follow this tutorial for installing the proper software

Pressure

  1. Make sure that the sensor is open and not being covered by anything.

  2. Connect the female to female wires to the Vin, Gnd, Sck, and Sdi pins on the pressure sensor.

  3. Connect the Vin wire to the 1 pin on the Pi which is for 3V of power.

  4. Connect the Gnd wire to the 9 pin on the Pi which is for Ground.

  5. Connect the Sck wire to the 5 pin on the Pi which is for the I2C clock.

  6. Connect the Sdi wire to the 3 pin on the Pi which is for the I2c data.

  7. Once all wires have been connected go to the Raspberry Pi configuration and enable I2c.

  8. To make sure that the sensor has properly been connected you can run the command sudo i2cdetect -y 1

For more information about the sensor check this website https://learn.adafruit.com/adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout?view=all

Sense Hat

  1. Install the sense hat library
sudo apt-get update
sudo apt-get install sense-hat
  1. Reboot Raspberry Pi
sudo reboot

About

Raspberry Pi Weather Station with Node/React webserver to display data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •