PervasiveComputing/Brightnest — pull request #3 by Aldream (2013-11-28 19:51:52+00:00)
Title: Web Services

This PR contains a basic REST API, based on the Models of PR #2

## REST API
Through a (hopefully) clear routing, it allows:

- CRUD operations on each model (*Sensor, *Actuator*, *Measure*, *Rule*, *SensorRule*, *ActuatorRule*) and their fields
- Some more complex and useful operations:
- GET Measures for a given Sensor, generated after a given Date
- GET SensorRules for a given Rule
- GET ActuatorRules for a given Rule

So it should now be possible to implement the Ajax part of the front-end.

The next step will be to offer some of the services through a Socket.io connection, to allow instant update of the webpages when something happens (*pushing* instead of *pulling*).

## Devices Driver
A system has been implemented to allow the webserver to communicate with the devices (sensors & actuators).

For each kind of devices (*Sunspot*, *Hue*, *NRC*, ...), a *node* module, a ***driver***, should be implemented and put in the `web/drivers/...` directory. Each driver will be loaded by the webserver at launching time, and should allow it to deal with the sensor.

A driver should export the following operations:

- **add(customId, cb)**
- Add the device to the system.
- Parameters:
- customId (String):	Custom ID of the new device for the driver
- cb (Function(error)):	Callback with an error or *null* as parameter

- **update(prevCustomId, newCustomId, cb)**
- Change the custom ID of the device.
- Parameters:
- prevCustomId (String):	Previous ID
- newCustomId (String):	New ID
- cb (Function(error)):	Callback with an error or *null* as parameter

- **remove(customId, cb)**
- Remove a device.
- Parameters:
- customId (String):	ID
- cb (Function(error)):	Callback with an error or *null* as parameter

For instance, we can imagine that the driver wll use this functions to communicate the credentials of the DB to the sensor (or sensors server), so it will be able to push directly its measures in it...

The actuators drivers will probably have to implement some other functions (`activate(customId, value)` maybe) to control them. The interface will be defined during the implemntation of the inference engine.

## Script

A script has been written to install and launch the service: `sh ./installAndRun.sh`.

It will install the required packets for the DB and servers, then configure and launch them.