Skip to content

Repository files navigation

IOT Weather App

Project Description

My Raspberry Pi reads local temperature and humidity using the Sense HAT, read_env.py. It makes a GET request to the OpenWeather API to retrieve current temperature and humidity readings, openweather.py.
Data is then sent to a MQTT broker hosted on a cloud VM by the local_weather.py script. A python subscriber script, web_dashboard.py, then takes in the telemetry data from the MQTT broker and writes to a json file.
The script then parses that json file and sets the temperature and humidity return from both the sense HAT and OpenWeather API as variables passed to a HTML file.
The HTML file, dashboard.html is deployed on Render through a GitHub repository using web_dashboard.py to build the web service.
A python script, thingspeak_api, on the Raspberry Pi also sends the local and OpenWeather readings to the ThingSpeak MQTT broker. Channels for local and OpenWeather readings are configured on the ThingSpeak service.
Trending graphs produced by ThingSpeak are embedded in dashboard.html using iframes to display trending data for both services.
Email alerts are configured on ThingSpeak using local data as the input. Scheduling is configured to send emails based on high and low temperature readings at 08:00 GMT to provide information on the day's current weather.
On demand readings through the Raspberry Pi's Sense HAT LED board and joystick button press are generated by sense_display.py. These provide informational advice on what clothing is appropriate for the current temperature.

Considerations

As the SenseHAT sits ontop of the Raspberry Pi. Readings are inaccurate due to temperature generated by the CPU.
A potential solution to this is to use a microcontroller to gather reading and send them to the Raspberry Pi for processing. Or modify the senseHAT to create distance between it and the board so that temperature readings are more accurate.
OpenWeather API calls are limited to 60 per hours. Due to this I decided to only take readings from both sources once per hour to reduce the possibility of going above this limit. This also allows for further fine tuning in the future if required.
All processing currently is done on the Raspberry Pi. If I was to move forward with developing this process I may separate scripts sending data to the MQTT broker on my VM and subscriber scripts to increase separation of concerns as at the moment data is being sent from and retrieved from the same location.

Features

  • On Demand Reading
  • Web dashboard
  • Email alerts

Code Demo

https://youtu.be/ybyJ4K1NRzQ

Webdashboard

https://iot-weather-app.onrender.com

Getting Started

Clone repository and install Eleventy

git clone https://github.com/Nolbag/IOT_Weather_App
cd IOT_Weather_App

Activate python vertual environment and install requirements

python -m venv .venv --system-site-packages
source .venv/bin/activate
pip install -r requirements.txt

Project Structure

IOT_weather_app/
├── .env_example
├── .gitignore
├── IOTWeatherAppProjectGraphic.png
├── README.md
├── requirements.txt
├── proposal_PaulNolan.md
├── local_weather.py
├── web_dashboard.py
├── openweather.py
├── read_env.py
├── sense_display.py
├── thingspeak_api.py
├── images/
│   ├── favicon.png
│   └── logo.png
├── templates/
│   └── dashboard.html
├── readings/
├── readme_images/
│   ├── MQTT_conf.png
│   ├── ThingChannel.png
│   ├── ThingEmail.png
│   ├── ThingReact.png
│   ├── ThingTime.png
│   ├── buildInfo.png
│   ├── envDetails.png
│   ├── firewall_port.png
│   └── renderConfig.png

MQTT broker setup

I set up an MQTT broker on a headless VM to handle traffic between my Raspberry Pi and dashboard.

sudo apt install mosquitto mosquitto-clients

nano /etc/mosquitto/mosquitto.conf

Listener Port assigned to 1883. IP address is the address of the VM.

Mosquitto setup

Port 1883 opened on VM firewall to allow inbound MQTT traffic.

Firewall Port

ThingSpeak Setup

Channel setup on ThingSpeak for data coming from sense HAT and from the OpenWeather API with temperature and humidity to feed data to the trend graph on the web dashboard

ThingChannel

High and low email templates set up in MATLAB Analysis to be sent at 08:00AM if thresholds are met.

ThingEmail

React created to send email template when temperature breaches defined thresholds

ThingReact

Time control created to trigger daily moring emails based on high or low temperature thresholds to alert of weather conditions.

ThingTime

Render Setup

Render builds the web service from the project github repository

renderConfig

It rebuilds the server when a new commit occurs on the github repo

buildInfo

Environment details must be set which match those configured in the local .env file

envDetails

Technologies

References:

About

IOT weather application

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages