Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Yeshas M P
Published © GPL3+

Air Quality Monitoring System Using Bolt IoT

A System designed to alert the user about possible Air Quality condition of particular city.

IntermediateFull instructions provided2 hours1,557
Air Quality Monitoring System Using Bolt IoT

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Buzzer
Buzzer
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Bolt Python Library
Air Quality Programmatic APIs
Telegram API
Snappy Ubuntu Core
Snappy Ubuntu Core

Story

Read more

Schematics

Buzzer and Bolt IoT connection

Circuit connection for buzzer and Bolt IoT

Code

aqi_alert.py

Python
This is the python script to alert the Air Quality condition of a particular location periodically.
import json
import requests
import time
from boltiot import Bolt

API_KEY = "your_bolt_api_key"
DEVICE_ID = "your_bolt_device_id"
telegram_bot_id = "bot_your_telegram_bot_id"
telegram_chat_id = "@aqi_alert"
bolt = Bolt(API_KEY,DEVICE_ID)

def aqi_check():
	url = "https://api.waqi.info/feed/mysore/?token=your_generated_api_token"
	response = requests.get(url)
	data = response.json()
	current_aqi = data['data']['aqi']
	city_name = data['data']['city']['name']
	status = data['status']
	return current_aqi,city_name,status;

def send_telegram_alert(message):
	url = "https://api.telegram.org/" + telegram_bot_id + "/sendMessage"
	data = {
		"chat_id": telegram_chat_id,
		"text": message
	}
	try:
		response = requests.request(
			"POST",
			url,
			params = data
		)
		print("This is the telegram url")
		print(url)
		print("This is the telegram response")
		print(response.text)
		telegram_data = json.loads(response.text)
		return telegram_data["ok"]
	except Exception as e:
		print("An error occurred in sending the alert message via Telegram")
		print(e)
		return False
def alarm():
	bolt.digitalWrite("0","HIGH")
	time.sleep(10)
	bolt.digitalWrite("0","LOW")

while True:
	aqi,city,status = aqi_check()
	if status != "ok":
		print("Response was unscessful")
		time.sleep(10)
		continue
	if (aqi >= 0 and aqi <= 50):
		message = f"Current Air Quality Index is {aqi} in {city}\nAir Quality is considered satisfactory"
		print(message)
		send_telegram_alert(message)
		alarm()
	elif (aqi >= 51 and aqi <= 100):
		message = f"Warning! Air Quality Index is {aqi} in {city}\nAir Quality is acceptable; However, for some reason there may be a moderate health concern"
		print(message)
		send_telegram_alert(message)
		alarm()
	elif (aqi >= 101 and aqi <= 150):
		message = f"Warning! Air Quality Index is {aqi} in {city}\nMembers of sensitve groups may experience health effects"
		print(message)
		send_telegram_alert(message)
		alarm()
	elif (aqi >= 151 and aqi <= 200):
		message = f"Warning! Air Quality Index is {aqi} in {city}\nEveryone may begin to experience health effects."
		print(message)
		send_telegram_alert(message)
		alarm()
	elif (aqi >= 201 and aqi <= 300):
		message = f"Warning! Air Quality Index is {aqi} in {city}\nHealth alert! Everyone may experience more serious health effects."
		print(message)
		send_telegram_alert(message)
		alarm()
	elif (aqi >= 301 and aqi <= 500):
		message = f"Warning! Air Quality Index is {aqi} in {city}\nEmergency! The entire population is more likely to be affected."
		print(message)
		send_telegram_alert(message)
		alarm()
	time.sleep(900)

Credits

Yeshas M P
1 project • 0 followers
code, coffe and contribute
Contact

Comments

Please log in or sign up to comment.