Lookout Part 5 - Configure the Raspberry Pi Notifier
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.
- Set up audio module
sudo apt-get install alsa-utils sudo modprobe snd_bcm2835 sudo amixer -c 0 cset numid=3 1
- Load snd_bcm2835 on boot:
vi /etc/modules
and add a new line withsnd_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.
- Install notifier python module
cd YOUR_PATH_TO_LOOKOUT_REPO/lookout/device/notifier sudo python3 setup.py install
- Configure example code
cd examples cp conf_example.json conf.json
vi conf.json
and copy the IoT thing values from the camera example- Copy certs from camera example to
lookout/device/notifier/examples/certs
- 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.
- In the AWS IoT console, open the MQTT test client
- Click “Publish to a topic”
- 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 }
- 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.
- 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"],
. - 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
- Lookout, an AWS Rekognition Enabled Smart Camera
- Lookout Part 2 - Configure the AWS stack with CloudFormation
- Lookout Part 3 - Testing the Lookout Application Stack
- Lookout Part 4 - Configure the Raspberry Pi Camera
- this post » Lookout Part 5 - Configure the Raspberry Pi Notifier