Switch + Light

In this section we will look at a practical case study for the usage of Scaffold in defining and deploying a city CPS application. We will develop and deploy a light switch application, whereby we make the nodes available on a locally run register and then develop the application based on it.

Backend

For the backend, we need to host scanner and start the communication broker. We can do so by typing on the host:

$ scn init
$ scnd

This will host the necessary broker and the scanner register.

Sensors

For the sensors, we will use the Intel Edison platform, and program the sensors individually. First of all, we need to define a driver for Scaffold to use. In this case, we will have installed an application for sending the commands. The scaffold driver can be selected in the configuration command for the node registration. We also advertise our capabilities, in this case that one of the Edison nodes will control a switch and the other will control a light

$ scn register -n <sensor ip> -s switch -d /bin/switch -u scaffold
$ scn register -n <actuator ip> -a turnOnLight -d /bin/turnOnLight -u scaffold
$ scn register -n <actuator ip> -a turnOffLight -d /bin/turnOffLight -u scaffold

Alternatively, these can be automatically done by using the Scaffold runtime. The three executables mentioned should provide the reading for the sensor as a numeric value on stdout or execute the command. This is all the necessary infrastructure setup for the sensors and actuators.

Application

As an application developer, we can now visualise all the resources available in the network:

$ scn display

After identifying the application we want to build, we can then define the network-wide code using Scale in example.sc as such:

main = switch[if (<) ?switch 500 then cmd turnOffLight else cmd turnOnLight]

In the code snippet, ?switch corresponds to a reading of the switch’s value and turnOnLight and turnOffLight correspond to command to activate and deactivate the light respectively. We can then compile this application:

$ scc example.sc

Compiling this program will produce three target platform artifacts: one for the sensing part (example.sc1), two for the actuation part (example.sc2 and example.sc3, for turning the light on and off respectively), and one for the computation part (example.sc4), which can reside in any elligible node.

We can then deploy the application. The default requirements in scaffold are for in-network processing:

$ scn deploy example.sc

If everything went well, the application should be deployed correctly. and we can then observe the messages exchanged by the application by listening on the broker.