This post describes how to configure a “notifier thing” to play audio alerts when lookout detects vehicles or people.

The notifier thing follows the same pattern as the camera thing (it is an AWS IoT thing that runs a python script). New events are announced with a chime, and details about the objects or people are announced with text-to-speech generated by AWS Polly.

Requirements

This example uses speaker connected to the 3.5mm audio jack - any raspi model should work.

To keep it simple you can set up the speaker on the same raspi as the camera if your physical layout allows. You can re-use the AWS Iot thing definition and certs from the camera for the notifier scripts (entirely fine since it’s the same physical device; best practice for different devices is to create a thing definition for each device).

Configure 3.5mm audio output

Steps tested on raspi3 with clean DietPi image.

  1. Set up audio module
    sudo apt-get install alsa-utils
    sudo modprobe snd_bcm2835
    sudo amixer -c 0 cset numid=3 1
    
  2. Load snd_bcm2835 on boot: vi /etc/modules and add a new line with snd_bcm2835

Install python modules

sudo apt-get install -y python3-dev libasound2-dev
sudo pip3 install AWSIoTPythonSDK simpleaudio

Configure lookout notifier example

These steps assume that the camera thing has been configured (Lookout Part 4 - Configure the Raspberry Pi Camera). If you’re setting up the notifier on a different device, use the steps from the camera post to configure AWS credentials (for Polly), clone the repo and set up a new AWS IoT thing.

  1. Install notifier python module
    cd YOUR_PATH_TO_LOOKOUT_REPO/lookout/device/notifier
    sudo python3 setup.py install
    
  2. Configure example code
    cd examples
    cp conf_example.json conf.json
    
  3. vi conf.json and copy the IoT thing values from the camera example
  4. Copy certs from camera example to lookout/device/notifier/examples/certs
  5. Run the example - python3 notifierThingExample.py -c conf.json

If everything is set up correctly you should see some diagnostic log messages.

Test the notifier

You can test the notifier by posting a test message to the lo/notify MQTT queue.

  1. In the AWS IoT console, open the MQTT test client
  2. Click “Publish to a topic”
  3. Publish the following JSON to lo/notify:
    {
      "eventId": "t-test123",
      "has_person": true,
      "has_car": false,
      "detectedFace": {
      "name": "Bob the mailman"
      },
      "thingName": "lo-iot-cam1",
      "captureSizeW": 560,
      "captureSizeH": 420,
      "direction": {
        "direction": "SE",
        "dx": 10,
        "dy": 50
      },
      "eventTime": 1506976560
    }
    
  4. To test more notifications, change the eventId value - the notifier thing tracks the value and will not announce duplicate notifications.

Optional settings

The notifier thing conf.json file contains a couple settings you can modify to change notification behavior.

  1. directionFilter - an array of cardinal directions to limit notification (empty be default, allows all directions). For example, you could limit notifications to only objects moving towards the camera: "directionFilter": ["S", "SW", "SE"],.
  2. pollyVoiceId - sets the voice used by the AWS Polly service. Defaults to “Joey”. For a list of all Polly voices, see AWS Polly available voices

Run Lookout Notifier Thing as a Service

The notifier can be installed as a service using a shell script - for a more detailed explanation see the install as a service section in (Lookout Part 4 - Configure the Raspberry Pi Camera).

sudo apt-get install runit
cd lookout/device/notifier/examples
./installAsService.sh

Related Posts