Game DevFest 2015
Jakarta, Oct 17, 2015 | Surabaya, Oct 18, 2015
Firebase
Realtime backend for mobile app and IoT
Andri Yadi
@andri_yadi | a at dycode dot com
http://andriyadi.me | google.com/+AndriYadi
CEO of
Been coding in awesome
languages/Frameworks
for 18 years
QBasic, Pascal, c, C++, Java, PHP, Bash,
C#, Visual Basic, HTML, JavaScript,
Python, Objective-C, Swift
.NET, Qt/QML, Java ME/EE/SE, Android
SDK, iOS SDK, Node.js, Arduino
Who am I around Firebase?
How dare I am talking here…
I’m the user of firebase long before
Firebase has order & Limit feature
I’ve been using it since Jan 2014
Disclaimer
30 minutes won’t be enough to show
how cool Firebase is
What is Firebase?
Let’s see a Real-World demo
Rather than theoritise about it
Take a photo with #DevFest2015
Shared photo will be automatically shown here

http://story.jepret.in/Jepret/gdgdevfest2015
Firebase delivers that photo
object to browser in realtime
Jepret Cloud Jepret Allegra Jepret Story
Firebase Firebase
Node.js + MongoDB

Deployed on Microsoft Azure
Architecture
Firebase
Realtime Gallery Allegra Machine Jepret Story app
Jepret Cloud
More about #Jepret?
http://jepret.in
Let’s see another demo
Typical Firebase 

Demo
Let’s Try something different
today…
Let’s Get Physical
today…
Let’s light up the LED
My Setup
Circuit
Code
var wpi = require('wiring-pi');
wpi.setup('gpio');
var ledPin = 26; //26 is GPIO pin to LED
wpi.pinMode(ledPin, wpi.OUTPUT);
//Turn off/on the LED directly
var ledValue = 1; //0 to switch off
wpi.digitalWrite(ledPin, ledValue);
Let’s light up the LED via browser
Architecture
Raspberry Pi 2 Web app
HTTP

(LAN)
Light up the LED via Firebase
Architecture
Raspberry Pi 2 Web app
Internet
Firebase data
The trick
Raspberry Pi 2
Firebase
//if	state	==	true,	write	1	
//if	state	==	false,	write	0	
wpi.digitalWrite(LED_PIN,	1)
Firebase
Code
function setState(state) {

ledValue = +state; //convert true/false to appropriate integer

wpi.digitalWrite(ledPin, ledValue);

}
var deviceId = "smartlamp1";
var myFirebaseRef = new Firebase(“https://[YOUR_FIREBASE].firebaseio.com/devices”);

var deviceRef = myFirebaseRef.child(deviceId);
var myDevParamsRef = deviceRef.child("parameters");

myDevParamsRef.on("child_changed", function(snapshot) {

console.log(snapshot.key());

console.log(snapshot.val());



if (snapshot.key() == "state") {

setState(snapshot.val());

}

});
Now we can turn on the Led from Mars
….or from anywhere connected to internet
Let there be a light
Using the same principle, now we
can turn on/off an AC light bulb
Q1
TRIAC
U1
OPTOTRIAC_1
R2
1K
R1
470
LAMP
AC PLUG
GPIO
AC solid state switch
To RPi2
GPIO 5
My Setup
Let there be a light from App
Architecture
Raspberry Pi 2 Web app Mobile app
Sending Telemetry
what about…
Complete Circuit C
B
A
Q1
TRIAC
U1
OPTOTRIAC_1
R2
1K
R1
470
LAMP
AC PLUG
GPIO
Architecture
Raspberry Pi 2 Mobile app
Bonus: Automation
Turn on light bulb automatically using a LDR
https://github.com/andriyadi/FireSmartLamp
All code is here:
as Summary…
WELL DOCUMENTED
Education
http://edu.dycode.co.id | edu@dycode.com
a bit of ads…
We contribute
Education
100+ seminars, workshops, trainings delivered
Delivered to 20+ communities, organisations,
campuses
Next, could be yours…



Just drop us a message:
http://edu.dycode.co.id | edu@dycode.com
We teach
+ + [Obj-C]
+
Education
Opening soon…
Education
+
https://github.com/andriyadi/FireSmartLamp
Again, all code is here:
DyCode
www.dycode.com
office at dycode dot com | @dycode
Thanks

Firebase - realtime backend for mobile app and IoT