-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFirebase_Led.html
97 lines (76 loc) · 2.07 KB
/
Firebase_Led.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Firebase Led</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase.js"></script>
<script>
// Initialize Firebase
// Cambiar por sus credenciales
var config = {
apiKey: "AIzaSyD2QEHR9JO2KcrtQvjypI6iFIznX_Dc_Wg",
authDomain: "testled-eb6bb.firebaseapp.com",
databaseURL: "https://testled-eb6bb.firebaseio.com",
storageBucket: "testled-eb6bb.appspot.com",
messagingSenderId: "909652007958"
};
firebase.initializeApp(config);
</script>
</head>
<body>
<br>
<br>
<br>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-success">
<div class="panel-heading">Firebase Led</div>
<div class="panel-body">
<div class="checkbox">
<label>
<input type="checkbox" id="checkLed1">LED 1
</label>
<div class="checkbox">
<label>
<input type="checkbox" id="checkLed2">LED 2
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
/*
Esqueleto de la BD
var db = firebase.database().ref('home').set({
led1:true,
led2:true
});
*/
var db = firebase.database().ref('home');
// último estado
db.on('value', function(data){
console.log("data: ", data.val());
$("#checkLed1").prop('checked', data.val().led1);
$("#checkLed2").prop('checked', data.val().led2);
});
$("#checkLed1").click(function(){
var estado = $(this).is(':checked');
db.update({
led1:estado
});
});
$("#checkLed2").click(function(){
var estado = $(this).is(':checked');
db.update({
led2:estado
});
});
</script>
</body>
</html>