-
Notifications
You must be signed in to change notification settings - Fork 0
/
beacon.js
42 lines (35 loc) · 1.06 KB
/
beacon.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
36
37
38
39
40
41
42
// Get a reference to the database service
var database = firebase.database();
main();
// gets user input to create the beacon
function main()
{
host = "adsf00dfd0f2df";
course = "cp123";
// randomly generate position and start / end time for convenience
lat = 43.4724 + (Math.random()-0.5);
lng = -80.526 + (Math.random()-0.5);
startTime = 3 + Math.floor(Math.random() * 8) + ":00AM";
endTime = 1 + Math.floor(Math.random() * 8) + ":00PM";
// passes the user data to create a beacon
Beacon(host, lat, lng, startTime, endTime, course);
// updates page to show beacon was created
document.body.innerHTML = "beacon created successfully!";
}
// creates the beacon
// inserting using .push() means key is automatically generated
function Beacon(host, lat, lng, startTime, endTime, course) {
// get unique baconId
var myBeacon = database.ref().push();
var id = myBeacon.key;
// save Beacon into database
database.ref('/beacon/').push({
beaconId : id,
host: host,
lat: lat,
lng: lng,
startTime: startTime,
endTime: endTime,
course: course
});
}