Lookout Part 3 - Testing the Lookout Application Stack
The post describes how to test the Lookout lambda functions and how to use the AWS MQTT test client.
Even if your stack deployed without errors, learning how to test the stack will give you a better understanding of the AWS components and allow you to debug any issues you might run in to.
However … if you don’t want to learn how to test the stack now, you can skip ahead to Lookout Part 4 - Configure the Raspberry Pi Camera.
Testing Deployed Lambda Functions
The easiest way to test deployed functions is via the aws console.
- Log in to the console and navigate to services -> compute -> lambda.
- Click on the lambda that starts with “lookout-LookoutEvent-…” to open the detail view. If you don’t see your functions, remember to set your region from the region menu in the upper right corner.
- Click the test event dropdown and select “Configure Test Events”
- Copy and paste this json event into the editor:
{ "eventId": "t-generate", "s3Key": "img/test/mailman_gray.jpg", "thingName": "lo-iot-cam1", "captureSizeW": 560, "direction": { "direction": "SE", "dx": 10, "dy": 50 }, "motionSizeH": 420, "eventTime": 1506976560, "originalBoundingBox": { "Width": 0, "Top": 0, "Left": 0, "Height": 0, "CenterX": 0, "CenterY": 0 }, "motionSizeW": 560, "motionContourArea": 1, "captureSizeH": 420 }
- Name the event, click save, then click the “Test” button. Expand the execution results. You should see log output similar to this:
The lambda used aws Rekognition to detect labels in the image, the log shows that it found [‘Human’, ‘People’, ‘Person’], matched on the face “Bob” from the person in the image, and sent a notification about Bob to the lo/notify MQTT topic.
MQTT test client
The aws IoT console has a very handy web-based MQTT test client, so we can see exactly what a physical IoT device would by subscribing to the lo/notify topic.
- Leave the lambda test page open, in a new tab navigate to services -> internet of things -> AWS IoT. Make sure you are in the same region as your lambdas.
- Click on “get started”, then click “Test” in the left menu. This opens the MQTT web-based test client and establishes a connection to AWS IoT as a device.
- In the “Subscription topic” field type “lo/notify” and click Subscribe.
- Switch back to the lambda function and click test again.
- Now return to the IoT tab and you should see a new event with the message published by the lambda function.
You’ll notice that two MQTT messages are published. This is by design - the goal is to notify as fast as possible when any event happens. In this case the first notification tells us that Lookout sees people - this message is sent before facial recognition takes place. If no faces were detected this is the only message that would be sent:
{
"eventId": "t-e78e6b5b",
...
"labels": [
"Human",
"People",
"Person"
],
"has_person": true,
"has_car": false
}
Because Lookout also matched the face “Bob”, a second notification is sent telling our IoT devices about Bob:
{
"eventId": "t-e78e6b5b",
"detectedFace": {
"faceId": "df77a5cb-d98a-5282-b6a2-5e9cb4551811",
"name": "Bob"
},
...
"labels": [
"Human",
"People",
"Person"
],
"has_person": true,
"has_car": false
}
Related Posts
- Lookout, an AWS Rekognition Enabled Smart Camera
- Lookout Part 2 - Configure the AWS stack with CloudFormation
- this post » Lookout Part 3 - Testing the Lookout Application Stack
- Lookout Part 4 - Configure the Raspberry Pi Camera
- Lookout Part 5 - Configure the Raspberry Pi Notifier