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
Send A Notification When On Mq2 Gas Sensor Detection
Step 1
First, go to the Pushetta website "http://www.pushetta.com/my/dashboard " and then log into this site to get the API.
Send A Notification When On Mq2 Gas Sensor Detection
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".
Send A Notification When On Mq2 Gas Sensor Detection
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.
Send A Notification When On Mq2 Gas Sensor Detection
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")
}
  1. sendNotification("7230ffbdd10f0db0a740a6b3865f9082105e58d7", "RaviIoT", "Ravi your home leaked out the LPG Gas be alert !!!!!")
Full Package Code
  1. import RPi.GPIO as GPIO
  2. import time
  3. import urllib2
  4. import json
  5. GPIO.setmode(GPIO.BCM)
  6. GPIO.setwarnings(False)
  7. GPIO.setup(26, GPIO.IN)
  8. #GPIO.setup(3, GPIO.OUT)
  9. def sendNotification(token, channel, message):
  10. data = {
  11. "body" : message,
  12. "message_type" : "text/plain"
  13. }
  14. req = urllib2.Request('http://api.pushetta.com/api/pushes/{0}/'.format(channel))
  15. req.add_header('Content-Type', 'application/json')
  16. req.add_header('Authorization', 'Token {0}'.format(token))
  17. response = urllib2.urlopen(req, json.dumps(data))
  18. while True:
  19. i=GPIO.input(26)
  20. if i==0: #When output from LPG sensor is LOW
  21. print("No Gas Leakage Detected",i)
  22. #GPIO.output(3, 0) #Turn OFF LED
  23. time.sleep(0.5)
  24. elif i==1: #When output from LPG sensor is HIGH
  25. #print("Intruder detected",i)
  26. print("LPG Detect",i)
  27. sendNotification("7230ffbdd10f0db0a740a6b3865f9082105e58d7", "RaviIoT", "Ravi your home leaked out the LPG Gas be alert!)
  28. #GPIO.ocdutput(3, 1) #Turn ON LED
  29. time.sleep(0.5)
Raspberry Pi and Mq2 Sensor Connection
Send A Notification When On Mq2 Gas Sensor Detection
Step 4
Next, we need to update the Raspberry Pi. So, install the latest packages. You can do that using the following commands.
  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install python3
Run the program,
  1. sudo python Program/gas/gas.py
Send A Notification When On Mq2 Gas Sensor Detection
When the sensor is detected immediately send the alert notification to channel subscribers.
Send A Notification When On Mq2 Gas Sensor Detection
Output
Get alert notifications. The alert message is Ravi your home leaked out the LPG Gas be alert !!!
Send A Notification When On Mq2 Gas Sensor Detection

Summary

Finally, we have successfully sent a notification for an mq2 gas sensor detection using Pushetta.