Sky showed me Particle’s javascript library, and I thought I would post what I had to do to get it working.

Particle’s documentation can be found at: https://docs.particle.io/reference/javascript/

My updated files are at: https://github.com/arathorn593/IDeATePhysCompProject03-Cardboard

  1. From the terminal, run:   npm install particle-api-js
  2. To allow you to use the library in the main script.js file, you must add this line to your index.html file: <script type="text/javascript" src="//cdn.jsdelivr.net/particle-api-js/5/particle.min.js"></script>. This line needs to go before you import the script.js file, so you should have your new line followed by the existing line that includes the script:
  3. Next, add the code to login at the top of your init function. Make sure to save your token to a global variable and don’t include the var Particle = require('particle-api-js');  line that the particle documentation says to include. Thus, the top of your init file should look something like:
  4. Now, you are set up and you can use the functions in the library. The only one I am using right now is the callFunction function. I call it whenever the default stool object is selected (check out the picker function in script.js). To call a function on your photon, you also need to register the function to the cloud within you photon code (see https://docs.particle.io/reference/firmware/photon/).
    • My photon code:
    • The code to call the light function:

       

Let me know if I need to add anything to this post.