Skip to content

rtdtwo/pws-backend

Repository files navigation

🌤️ Rishabh's PWS - Backend

A lightweight, robust Flask-based REST API designed for a DIY personal weather station. It bridges the gap between the Arduino-based hardware sensors and the web frontend.

Part of my full-stack DIY Personal Weather Station project:

  • Frontend - The web interface to visualize the data.
  • Backend - The REST API to store and retrieve data from a SQL server (you are here).
  • Arduino - The sensor hardware logic.

Key Features

  • PostgreSQL Integration: Relational storage for long-term climate data analysis.
  • Caching Layer: GET requests are cached to reduce database load and improve latency.
  • Rate Limiting: Protects the server from accidental loops or malicious traffic.
  • Wunderground API Integration: Sends data to Wunderground PWS network for data crowdsourcing.

High-level architecture

PWS Architecture

Installation & Setup

  1. Clone the repository:
git clone https://github.com/rtdtwo/pws-backend.git
cd pws-backend
  1. Set up a Virtual Environment:
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
  1. Install Dependencies:
pip install -r requirements.txt
  1. Environment Variables: Create a .env file in the root directory:
PWS_DB_HOST=db.host.name # Postgres DB hostname
PWS_DB_PORT=5432 # Postgres DB port 
PWS_DB_NAME=database_name # Postgres DB name
PWS_DB_USER=database_user # Postgres DB user
PWS_DB_PASSWORD=database_password # Postgres DB password
DEBUG=true # Controls Flask debug logs when running locally
WU_PWS_ID=KMAABCDE123 # Wunderground PWS ID
WU_PWS_PASSWORD=abc1234 # Wunderground PWS Password
SENTRY_DSN=https://[email protected]/123456 # Sentry DSN for monitoring
  1. Run the Application:
python app.py

Security & Performance Notes

  • API Keys: Write requests are protected by API key authentication. The hashed API key is stored in the database.
  • Rate Limiting: Default limits are applied to prevent the Arduino or Frontend from spamming the server. Adjust these in app.py based on your sensor frequency.
  • Database Efficiency: By utilizing Flask-Caching, identical GET requests within the cache window (e.g., 5 minutes) return instantly without hitting the PostgreSQL instance.

🐛 Feedback & Bug Reports

This project is currently a personal showcase and is not open for public feature contributions at this time. However, feedback is always welcome!

If you encounter a bug or have a suggestion on how to improve the code:

  • Check the Issues tab to see if it has already been reported.
  • If not, please open a new issue with a clear description of the problem and steps to reproduce it.

👨‍💻 Author

Rishabh Tatiraju

Portfolio: rishabh.blog

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Languages