This exercise will be achieved partly as homework (see questions below) and partly in a pair-programming style (on a follow-up call).
The building you are in possesses a few sensor nodes (devices). These devices measure the temperature and humidity of the room they are in, and the data can be collected through a Gateway. This Gateway exposes a JSON-based REST API with a few endpoints (see the full documentation of this API below). Your goal will be to write a small program that interacts with the Gateway API in order to retrieve data from the devices.
In the questions below, the command is just a string passed as an argument to your program. For example, it is expected for the version command to be called by typing ./yourExecutable version (or similar) into a terminal.
- Write a program that prints “1.0.0” when the
versioncommand is given. - Implement a command
device-countthat shows the number of devices in the building. - Implement a command
timeout-devices <threshold>that list the UUIDs of all the devices that have a response time above the given threshold. - Implement a command
register-device <device-uuid> <room-uuid>that assigns a device to a room.
Room {
uuid: String
label: String
floor: Int
devices: [ Device ]
}
Device {
uuid: String
status: "RUNNING" | "STOPPED"
responseTime: Float
room: Room
temperature: Float
humidity: Float
}
GET /devices
GET /devices/<uuid>
GET /rooms
## Private API
The endpoints listed below are only accessible after authentication with a Bearer token.
POST /rooms/<room-uuid>/devices
Input:
{ "uuid": "<device-uuid>" }
PUT /devices/<device-uuid>/status
Input:
{ "status": "RUNNING" | "STOPPED" }
Only stopped devices can be removed.
DELETE /devices/<device-uuid>