-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (31 loc) · 904 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var config = {
apiKey: "AIzaSyCukfTz_VLbn148FQFgvxj1eulGMzCgr6g",
authDomain: "newshss-c303e.firebaseapp.com",
databaseURL: "https://newshss-c303e.firebaseio.com",
projectId: "newshss-c303e",
storageBucket: "newshss-c303e.appspot.com",
messagingSenderId: "132420302545"
};
firebase.initializeApp(config);
$(document).ready(function(){
var database = firebase.database();
var ledStatus;
database.ref().on("value", function(snap){
ledStatus = snap.val().ledStatus;
if(ledStatus == 1){
$(".lightStatus").text("The light is on");
} else {
$(".lightStatus").text("The light is off");
}
});
$(".lightButton").click(function(){
var firebaseRef = firebase.database().ref().child("ledStatus");
if(ledStatus == 1){
firebaseRef.set(0);
ledStatus = 0;
} else {
firebaseRef.set(1);
ledStatus = 1;
}
});
});