This is the summary.

A simple alarm app

In this application, an alarm can be triggered by one or more accelerometers. The alarm is displayed in a browser frontend, of which any number of instances can be run concurrently.

Alarm app hardware

Extensions to this are

The Basics

There is more than one way of running this application. Following are brief descriptions of the basic components required.

The technical requirements are:

The Backend

The backend receives a live stream of accelerometer data when the alarm is armed and determines whether any changes here should trigger an alarm. It centrally distributes alarm events and changes in the armed state to all frontends.

The backend as is is written for Node.js, but would be trivial to adapt for other languages with a WAMP library.

With the default Crossbar.io configuration for this app, the backend is launched automatically by Crossbar.io.

The Web Frontend

The Web frontend displays the current alarm state (armed or disarmed), as well as a triggered alarm. It allows arming, disarming, manually triggering an alarm, and stopping a triggered alarm.

If a camera is connected to the alarm system, it also displays the photo taken once the alarm is triggered, and allows requesting an image at any time.

With the default Crossbar.io configuration for this app, the frontend is served by Crossbar.io.

The Accelerometers

The accelerometer publishes its state.

Code for two hardware platforms is currently provided, with code for both in the accelerometer directory of this app. In each case, transfer the code over to the device, with the accelerometer connected to it, and run it. More information about any additional setup which may be required can be found in the description of the respective component:

Tessel with accelerometer module

Launching it all

Launch Crossbar.io from the app directory. This also starts the backend and serves the frontend.

crossbar start

Start one or more microcontrollers with accelerometers.

Open the frontend in a browser (served at: http://<IP-of-System-running-Crossbar.io>:8080).

Arm the alarm and move an accelerometer to test.

The Extras

The alarm app can be easily extended with additional hardware. One of these does not require any modificactions to the basic app code: the Hardware Controls. This just uses existing events and procedures which the browser frontend already utilizes.

The Photos and Robo-Voice require additional code, with the former also requiring an extension of the browser frontend.

Hardware Controls

The Hardware Controls can be added using any microcontroller which can trigger LEDs or other lights based on WAMP messages, and receive trigger events from buttons. We currently offer code for this for the Arduino Yun.

No changes to the backend are required when using Hardware Controls - they use the same events and procedures that the browser frontend does.

Yun with Tinkerkit controls

The hardware requirements on the Yun are two Tinkerkit buttons and two Tinkerkit LEDs. The buttons need to be connected to pin 0 (arm/disarm the alarm) and 1 (trigger/cancel the alarm). The LEDS need to be connected to pin 11 (armed state indicator) and pin 10 (alarm state indicator).

You need to set up the Yun for using AutobahnJS. Then put hardware_controls_yun.js in the hardware_controls folder onto the yun.

Once you have your hardware connected, run the script

node hardware_controls_yun.js

which should log

Alarm App - Arduino Yun Hardware Controls starting ...
Arduino connected (over /dev/ttyATH0, board version 2.3)
Connecting to router ...
Router connected. Session ID: 196598121
...

Taking Photos

We currently offer code to use the camera module on the Tessel and a webcam connected to the Pi.

When you use a camera module you need to

Tessel

The Tessel camera module somewhat works, but the encoding of the image and its transfer are slow. The default resolution for testing this is therefore QQVGA (yes, this low, but try how long a VGA image takes!). Regard this more as a proof-of-concept than anything else. But then, when you already have a Tessel with a camera module, it's at least something you can do with it!

The code you need to run on the Tessel with the camera module is in the camera directory - camera_tessel.js. More information about this component and how to get it working can be found in the component documentation.

Raspberry Pi

The Pi supports most webcams, and works much faster than the Tessel.

The code you need is camera_pi.js. For instructions on how to get this working in general see the Pi Camera Component documentation.

Robo-Voice the Intruder

We currently offer code for a text-to-speech message using the Raspberry Pi.

The code you need to run the Raspberry Pi is in the speech directory. More information about how to set up this component can be found in the component documentation.

The short version: first, get speechsynth_adapter.py onto the Pi (e.g. scp speechsynth_adapter.py pi@<IP of your Pi>:~/). Then, start speechsynth_adapter.py by doing

python speechsynth_adapter.py --router 'ws://192.168.1.134:8080/ws' --realm 'iot_cookbook'

When you use this extra, you also need to replace the standard backend code with backend_speech.js - best by editing the Crossbar.io config to run this. Within this file, you need to set the correct ID for the Raspberry Pi you are using (search for piSerial and replace the value with the device ID of your Pi).

You may additionally want to adapt the text which is spoken (alertText) and the number of times this is repeated (repetitions).

Note: If you want to use both a camera and speech synthesis, then you should use backend_complete.js and the camera frontend.