vinuthna parim
Published © GPL3+

Gas Leakage Notificaction System. Using SMS, Twitter, Telegram

Have you ever wondered about saving lives when there was a gas leak. Thought of a device that would notify you at any time when there is leak

BeginnerFull instructions provided3 hours780
Gas Leakage Notificaction System. Using SMS, Twitter, Telegram

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
MQ-135 Air quality sensor
×1
Breadboard (generic)
Breadboard (generic)
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API
Integromat
Telegram
Twitter
Twitter

Story

Read more

Schematics

circuit connections

Code

Code for gas leakage notification system

Python
"""bolt_api_key ="# This is your Bolt Cloud API Key"
device_id = "# This is the device ID and will be similar to BOLTXXXX where XXXX is some numbers"
telegram_chat_id ="# This is the channel ID of the created Telegram channel. Paste after @"
telegram_bot_id = "# This is the bot ID of the created Telegram Bot. Paste after bot"
SID = 'You can find SID in your Twilio Dashboard' 
AUTH_TOKEN = 'You can find  on your Twilio Dashboard' 
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
threshold=" set threshold now 500 here;
"""
import requests                 # for making HTTP requests
import json                     # library for handling JSON data
import time                     # module for sleep operation

from boltiot import Bolt,Sms    # importing Bolt from boltiot module
import conf                     # config file where you write above mentioned data

mybolt = Bolt(conf.bolt_api_key, conf.device_id)#create a mybolt object
sms=Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)

def get_sensor_value_from_pin(pin):
    """Returns the sensor value. Returns -999 if request fails"""
    try:
        response = mybolt.analogRead(pin)
        data = json.loads(response)
        res = mybolt.digitalWrite('0', 'LOW')# for buzzer
        if data["success"] != 1:
            print("Request not successfull")
            print("This is the response->", data)
            return -999
        sensor_value = int(data["value"])
        return sensor_value
    except Exception as e:
        print("Something went wrong when returning the sensor value")
        print(e)
        return -999


def send_telegram_message(message):# function to send telegram message
    """Sends message via Telegram"""
    url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
    data = {
        "chat_id": conf.telegram_chat_id,
        "text": message
    }
    try:
        response = requests.request(
            "POST",
            url,
            params=data
        )
        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 integromat_twitter():# function used to create tweet integromat
    URL ="paste the correct url here from integromat"
    response = requests.request("GET", URL)
    print(response.text)



while True:
    # Step 1
    print("getting sensor value")
    sensor_value = get_sensor_value_from_pin("A0")    
    print("The current sensor value is:", sensor_value)
    
    # Step 2
    if sensor_value == -999:
        print("Request was unsuccessfull. Skipping.")
        time.sleep(10)
        continue
    
    # Step 3
    if sensor_value >= conf.threshold:

        print("Sensor value has exceeded threshold")
        print("Making request to Twilio to send a SMS")
        res = mybolt.digitalWrite('0', 'HIGH')# to get buzzer sound
        response = sms.send_sms("The Current gas sensor value is " +str(sensor_value))# to get sms messge for specified number
        print("Response received from Twilio is: " + str(response))
        print("Status of SMS at Twilio is :" + str(response.status))
        
        message = "Alert! Sensor value has exceeded threshold" + \
                  ". The current value is " + str(sensor_value)
        telegram_status = send_telegram_message(message)# to get message from telegram bot
        print("This is the Telegram status:", telegram_status)
        integromat_twitter()
        
       

    # Step 4
    time.sleep(10)

Credits

vinuthna parim
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.