Introduction
This article demonstrates how to make a fire alarm working sample based on IoT using Pushetta Service, working with MQ2 Gas Sensor. The MQ-2 Gas Sensor module detects a gas leak in the home and industry. They are sensitive to a range of gases and are used indoors at room temperature. The output is an analog signal and can be read with an analog input of the Raspberry Pi.
Pushetta
Pushetta is made to make it simple to broadcast communications to groups of subscribers. It works in a really simple way: As a publisher, you create a thematic group and every user that subscribes to this group receives a notification every time you push a message. It can be compared to SMS with many advantages.
Installation
You can learn
Raspberry Pi installation from my previous article.
Pin Diagram
Step 1
First, go to the Pushetta website "http://www.pushetta.com/my/dashboard " and then log into this site to get the API.
After that, create a new channel for subscribers. This channel is used to identify my API. I have already created and subscribed to my channel "RaviIoT".
Step 2
Next, go to install the mobile app "https://play.google.com/store/apps/details?id=com.gumino.pushetta". Go to the search bar to search for the channel name and click the subscribe button.
Step 3
Open the python IDE 3.0, File >> New save the name as gas.py, then follow the given code.
Syntax
{
sendNotification ("Your API","Channel Name","Alert Message")
}
- sendNotification("7230ffbdd10f0db0a740a6b3865f9082105e58d7", "RaviIoT", "Ravi your home leaked out the LPG Gas be alert !!!!!")
Full Package Code
- import RPi.GPIO as GPIO
- import time
- import urllib2
- import json
-
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
-
- GPIO.setup(26, GPIO.IN)
-
-
- def sendNotification(token, channel, message):
- data = {
- "body" : message,
- "message_type" : "text/plain"
- }
-
- req = urllib2.Request('http://api.pushetta.com/api/pushes/{0}/'.format(channel))
-
- req.add_header('Content-Type', 'application/json')
- req.add_header('Authorization', 'Token {0}'.format(token))
-
- response = urllib2.urlopen(req, json.dumps(data))
-
- while True:
-
- i=GPIO.input(26)
- if i==0:
- print("No Gas Leakage Detected",i)
-
- time.sleep(0.5)
- elif i==1:
-
- print("LPG Detect",i)
- sendNotification("7230ffbdd10f0db0a740a6b3865f9082105e58d7", "RaviIoT", "Ravi your home leaked out the LPG Gas be alert!)
-
- time.sleep(0.5)
-
Raspberry Pi and Mq2 Sensor Connection
Step 4
Next, we need to update the Raspberry Pi. So, install the latest packages. You can do that using the following commands.
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install python3
Run the program,
- sudo python Program/gas/gas.py
When the sensor is detected immediately send the alert notification to channel subscribers.
Output
Get alert notifications. The alert message is Ravi your home leaked out the LPG Gas be alert !!!
Summary
Finally, we have successfully sent a notification for an mq2 gas sensor detection using Pushetta.