Using built-in example code
Recap
1. From server (node.js) to client (browser) using a WebSocket
3. Request API data and output in command line interface (CLI)
Task
Today we would like you to focus on visualising some data from an API in the browser.
The API data will be coming from a server hosted in the LCC Prototyping Lab. The data itself is being generated from sensors scattered around the room. Look at the following URLs to for examples:
http://lab.arts.local:2020/api/imac01/distance
http://lab.arts.local:2020/api/imac02/light
http://lab.arts.local:2020/api/imac03/pot
http://lab.arts.local:2020/api/imac04/btn
These links will only work within the UAL network whilst connected to the WiFi
In groups of 2 start by creating an empty project directory and some empty files with the following structure (changing 'project-name' to something relevant to you):
├── visualising-api-data/
├── client/
│ ├── index.html
└── server/
└── app.js
Before you start using API data in your code it is important to understand how it is structured.You can do this using using theAdvanced REST Client (ARC)or with simple API data you can just open the URL in a browser window.Now you understand the structure you can start by requesting the API data using a Node.js script and output it to the CLI/Terminal.You can use the server code fromExercise 2 from Week 1as a starting pointBecause we are now working with dynamic/changing data we want to check the API regularly for changes. To do this you will need to use asetIntervalfunction to repeatedly run the same code.For an example of usingsetIntervalseeExercise 1 (Server code) from Week 1or this simplifiedexample of usingsetIntervalon Codepen.Once we are successfully requesting API data at a regular interval you need to send the data to the browser using a WebSocketSeeExercise 3from Week 1 of this WorkshopNow the dynamic/changing data from the API is within your client/browser JavaScript use p5.js to visualise that in an interesting way.See therandom-ball.htmlfilefor an example of using p5.js