-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (25 loc) · 792 Bytes
/
script.js
File metadata and controls
29 lines (25 loc) · 792 Bytes
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
// Firebase configuration
const firebaseConfig = {
apiKey: "xx",
authDomain: "xx",
databaseURL: "xx",
projectId: "xx",
storageBucket: "xx",
messagingSenderId: "xx",
appId: "xx"
};
firebase.initializeApp(firebaseConfig);
// Get a reference to the database service
const database = firebase.database();
// Create database reference
const tempRef = database.ref("events/temperature");
// Sync on any updates to the DB. THIS CODE RUNS EVERY TIME AN UPDATE OCCURS ON THE DB.
tempRef.limitToLast(1).on("value", function (reading) {
reading.forEach(function (readingTemp) {
const event = readingTemp.val()["event"];
const temp = readingTemp.val()["temperature"];
document.getElementById(
"events"
).innerText += `Event: ${event}, Temp: ${temp}\n`;
});
});