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.

  1. Log in to the console and navigate to services -> compute -> lambda.
  2. 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.
  3. Click the test event dropdown and select “Configure Test Events”
  4. 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
    }
    
  5. Name the event, click save, then click the “Test” button. Expand the execution results. You should see log output similar to this:
START RequestId: cf2651b4-ca0d-11e7-9efb-55a0dd377d43 Version: $LATEST
processing lookout-s3bucket-u4zd17l2nsjh/img/test/mailman_gray.jpg for event t-e39c1baa
labels found: ['Human', 'People', 'Person']
publishing label event to lo/notify for event t-e39c1baa
face found: {'faceId': 'df77a5cb-d98a-5282-b6a2-5e9cb4551811', 'name': 'Bob'}
notifying detection of Bob to lo/notify
END RequestId: cf2651b4-ca0d-11e7-9efb-55a0dd377d43
REPORT RequestId: cf2651b4-ca0d-11e7-9efb-55a0dd377d43	Duration: 3844.67 ms	Billed Duration: 3900 ms 	Memory Size: 512 MB	Max Memory Used: 36 MB

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.

  1. 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.
  2. 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.
  3. In the “Subscription topic” field type “lo/notify” and click Subscribe.
  4. Switch back to the lambda function and click test again.
  5. 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