Time to test the connection

Believe it or not, our real-time database service is up and running; now we just want to test our connection by writing a single value to the database from our AR Web app. Open up spawn-at-surface.html in a text editor and follow along:

  1. Scroll down to the Firebase script we added earlier. Add the following code after the last line:
var database = firebase.database();
  1. The preceding line creates a reference to the database. Now, let's set some data using the following code:
firebase.database().ref('pose/' + 1).set({x: 12,y: 1,z: 0});
  1. Save the file.
Various versions of the spawn-at-surface.html page can be found in the book's downloaded source code at Chapter_5/Examples.
  1. Run the page on your desktop using the http://localhost:9999/three.ar.js/examples/spawn-at-surface.html URL. At this stage, we are just setting a single point of data when the page starts, as a test, so we don't need AR. Of course, ensure that you start http-server before running any tests.
  2. After the page loads, you will see the ARCore warning message, but not to worry, this is just a test of the real-time database service.
  3. Go back to the Firebase Console (https://console.firebase.google.com/u/0/?pli=1) window we left open. Ensure that you are looking at the Database page and DATA tab, as shown:
Checking the data that was set on the Firebase database
  1. Expand the pose and its child objects, as shown in the preceding excerpt. If everything is working correctly, you should see the values we set for a simulated pose (position).

We now have a service in place, with the ability to track any data we want. Firebase allows us to model our data and schema on the fly, which is very useful in prototyping. It also has the extra benefit of being free, public, and accessible from the other platforms we will work with later. In the next section, we will put our tracking service to use by tracking the user in real time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.108.22