In this tutorial of IOT with Firebase we’ll create python script for sending automated IOT with Firebase Sensor Alert Automated Push Notification if fire sensor detects any fire which is connected to Adruino NodeMCU ESP8266. We’ll finish up the tutorial with demo of our project in which we will see working of smart led and sensor alert notification, on which we are working from last 4 tutorials.
I hope you enjoy this tutorial. All of the code and a transcript of the video follows the video below.
Transcript / Cheat-sheet :
Installing Required Libraries
Installing Pyrebase
Pyrebase is a Python interface to Firebase’s REST API. In layman’s terms, it allows you to use Python to manipulate your Firebase database. The documentation for Pyrebase can be found at https://github.com/thisbejim/Pyrebase
We will install the Pyrebase and its dependencies using pip
sudo pip3 install Pyrebase
Installing Pusher Push Notifications
Push Notifications makes it easy to send push notifications to iOS and Android apps. It takes the hassle out of managing device tokens and interacting with Apple and Google’s messaging services. WithInterestsubscriptions to notify segmented devices in each request and delivery SLAs offered on premium plans, it’s built to scale. The documentation for Pusher Push Notification can be found
at https://docs.pusher.com/push-notifications/reference/server-sdk-python
The Pusher Notifications Python server SDK is available on PyPi here.
We can install this SDK by using pip:
sudo pip3 install pusher_push_notifications
Python Script Code :
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Arduino Code :
#include <FirebaseArduino.h> |
||
// Set these to run example. | ||
#define FIREBASE_HOST “esri-eea51.firebaseio.com“ | ||
#define FIREBASE_AUTH “qULRQbnuzJ3qkAdYunMasgcLlKtpXic1UQ1FxHvM“ | ||
#define WIFI_SSID “kavin“ | ||
#define WIFI_PASSWORD “1123581321“ | ||
float fire; | ||
void setup() { | ||
Serial.begin(9600); | ||
pinMode(D1, OUTPUT); | ||
pinMode(D5, OUTPUT); | ||
pinMode(A0, INPUT); | ||
// connect to wifi. | ||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | ||
Serial.print(“connecting“); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print(“.“); | ||
delay(500); | ||
} | ||
Serial.println(); | ||
Serial.print(“connected: “); | ||
Serial.println(WiFi.localIP()); | ||
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); | ||
Firebase.set(“LED_STATUS“, 0); | ||
} | ||
int n = 0; | ||
void loop() { | ||
// get value | ||
fire = analogRead(A0); | ||
Serial.println(fire); | ||
if(fire<250){ | ||
digitalWrite(D5,HIGH); | ||
Firebase.setInt(“fire_sensor_status“,1); | ||
} | ||
n = Firebase.getInt(“LED_STATUS“); | ||
// handle error | ||
if (n==1) { | ||
Serial.println(“LED ON“); | ||
digitalWrite(D1,HIGH); | ||
return; | ||
delay(10); | ||
} | ||
else { | ||
Serial.println(“LED OFF“); | ||
digitalWrite(D1,LOW); | ||
digitalWrite(D5,LOW); | ||
Firebase.setInt(“fire_sensor_status“,0); | ||
return; | ||
} | ||
} | ||
For Android App code visit Previous Tutorial : IOT with Firebase Part 4
So, guys that’s end up with great tutorial on IOT with Firebase for sending automated Push Notification for Sensor Alert using Pusher, FCM to Android App. I hope you guy’s enjoyed it 🙂
though i followed each and every steps you told,I couldnot Get PushUp notification in my android application..please help me to send it …..