Object detection demo by using QNAP AWS Greengrass, QIoT Suite Lite & QuAI

Object detection demo by using QNAP AWS Greengrass, QIoT Suite Lite & QuAI

In this tutorial, you will learn how to use QNAP AWS Greengrass, QIoT Suite Lite & QuAI to do object detection doem.


  • AWS Account
  • Raspberry Pi
  • USB webcam

There are two Scenario:

Scenario 1

Camera –> AWS Greengrass IoT device –> AWS Greengrass Core –> QIoT Suite Lite –> QuAI –> AWS Greengrass Core Lambda –> AWS Cloud –> AWS S3 bucket

Step 1. Prepare AWS Greengrass Core

  1. Go to APP Center > Install AWS Greengrass
  2. Setup AWS Greengrass Group & Core in QNAP AWS Greengrass App. Please refer this link for more details :
  3. Create SendGGImageToQIoT” & QIoTIntegration” AWS Greengrass Lambda functions as shown below. For this Demo we are using Node.js based Lmabda function. You should also update it’s configuration setting’s Memeory limit and timeout. Please find Demo Lambda source codes inside this folder AWS_Greengrass_Lambda. (Refer to this link to setup Lambda function: https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html)
  4. Create a new device inside Greengrass Group Devices section as shown in the below image. Reference : https://docs.aws.amazon.com/greengrass/latest/developerguide/device-group.html
    (Notes : Please keep your device certificates, unzip it and upload to your Raspberry Pi.)
  5. Prepare following 3 subscriptions lists:
    a. Greengrass IoT Device to SendGGImageToQIoT:9″ Lambda for Image Prediction. Setting infomation :

    • Source –> GG_Camera
    • Target –> SendGGImageToQIoT
    • Topic –> cameraImage

    b. QIoTIntegration” Lambda function to IoT Cloud for upload predicted image to S3 Bucket. Setting infomation :

    • Source –> QIoTIntegration
    • Target –> IoT Cloud
    • Topic –> #

    c. Greengrass IoT Device to “QIoTIntegration:16” Lambda is trigger Lambda to start. Setting infomation :

    • Source –> GG_Camera
    • Target –> QIoTIntegration
    • Topic –> cameraImage

      Please refer the following image for these 3 subscriptions list source, destination and topic details
  6. Deploy the AWS Greengrass Group
  7. Verify AWS Greengrass core daemon status in QNAP AWS Greengrass
  8. Trigger the QIoTIntegration Lambda function to receive QIoT Suite Lite message. So that, you have to download AWS IoT Python SDK –> basicDiscovery.py and execute the following command. Please use GG_Camera device certificate files to trigger this Lambda function
  9. Run the Command :
    python basicDiscovery.py -e <youtiothostname>.iot.<region>.amazonaws.com -r root-ca.pem -c XXXXXXXX.cert.pem -k XXXXXXXX.private.key -n GG_Camera -m publish -t triggerLambda -M "{'status':'start'}"

    a. -e : AWS IoT Endpoint (In IoT Core home page, under Settings, make a note of the value of Endpoint.)
    b. -r : Root CA Path (In here : https://docs.aws.amazon.com/iot/latest/developerguide/managing-device-certs.html)
    c. -c : Thing Ceritificate Path
    d. -k : Thing Private key Path
    e. -n : Thing Name

Step 2. Setup AWS Greengrass IoT Device

  1. Install AWSIoTPythonSDK package in your Raspberry Pi (Refer to the instructions here for installation : https://docs.aws.amazon.com/greengrass/latest/developerguide/IoT-SDK.html) and deploy the “send_image_AWSGG.py” source code from this folder RaspberryPi_side to Raspberry Pi and install capture software. Command is :

    sudo apt update && sudo apt install fswebcam

Step 3. Setup Demo QuAI

  1. Go to QNAP APP Cernter Container Station

  2. Click “Create” > Search for “qeekdev/aipredict”  > Click “Install
  3. Click “Advanced Settings
  4. Go to “Network” (Refer to below port setting, if your port have conflicted, please modify your port)
  5. Click “Create
  6. Click “Overview”, you may see the container you created (This container provide you to recognize photo)
  7. Enter “http://<IP>:8082/api/v1/” and you will see the:

    More information, refer to: https://hub.docker.com/r/qeekdev/aipredict/

Step 4. Setup QIoT Suite Lite

Create a new IoT Application in QIoT Suite Lite from the Application template file LiveDemo.json import to QIoT Suite Lite or you may create a new IoT Application by yourself. To do so, please follow following steps

(Notes : You need to install “node-red-contrib-file-upload” module to your QIoT Suite Lite Rule, Reference to : How to install other modules in QIoT Suite Lite NodeRED?)

  1. Create an IoT Application and 2 Things : “cameraPi” and “AWSgreengrass”


  2. Create Thing Resource : cameraPi–>”image” and AWSgreengrass–>”resolve”
  3. Import rulesJson.json in Node-Red rule engine using Rules tab –> Import –> Clipboard option. After import you can see the following 2 rules flow:
  4. Verify your dashboard:a. Click the left button of Test node to test if Dashbaord, AI Sample Container & AWS Greengrass work successfully
    b. View the right side debug, if show the log or not
    c. Go to Dashbaord to confirm if show the live data and photo as below:


Step 5. Setup AWS cloud S3 bucket & Rules

  1. Create MoveImageToS3 Node.js Lambda function in AWS Lambda service. (Please find Demo Lambda source codes inside this folder AWS_Greengrass_Lambda)
    (Create Lambda function, refer to link: https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html)

  2. Create a new S3 bucket “qiotquaiggdemo” in AWS S3 service
    (Create S3 bucket, refer to link: https://aws.amazon.com/s3/getting-started/?nc1=h_ls)
  3. According to your AWS IAM & S3 setting information fill in the accessKey, secretAccessKey & Bucket (Refer to below sample):
  4. Create a Act(rule) in AWS IoT to upload Image to S3 bucket using Rule’s action “Invoke a Lambda function passing the message data”

  5. Declare MoveImageToS3 in the function name drop down and update the changes

Step 6. Start the demo

Setup the camera in Raspberry Pi device and start the program by executing the following command :

python send_image_AWSGG.py -e <host>.iot.<region>.amazonaws.com -r root.ca.pem -c <GG_Camrea_Cert_pem_file> -k GG_Camrea_Cert_private_key_file -n GG_Camera -m publish -t "cameraImage" 

    a.  -e : Aws IoT Endpoint (In IoT Core home page, under Settings, make a note of the value of Endpoint.)
b. -r : Root CA Path
c.  -c : Thing Ceritificate Path
d.  -k : Thing Private key Path
e.  -n : Thing Name

Step 7. Verify the demo

  1. Go to QIoT Dashboard

  2. Go to AWS IoT Cloud
  3. Go to AWS S3

Scenario 2

Camera –> QIoT Suite Lite IoT device –> QIoT Suite Lite –> QuAI –> AWS Greengrass Core Lambda –> AWS Cloud –> S3 bucket


The steps in this scenario are same as Scenario-1, just that the application running on Raspberry Pi is different. Please refer QIoT_device_QuAI_Greengrass section to setup the device.


Step 1. Install dependency library and software

pip install paho-mqtt
sudo apt update && sudo apt install fswebcam

Step 2. Follow Scenario1:  “Step 1” to “Step5”

Step 3. Upload RaspberryPi_side floder to Raspberry Pi

Step 4. Download “resourceinfo.json” from QIoT Suite Lite cameraPi thing and put resourceinfo.json under the “/res” folder

Step 5. Run command :

python main.py

Step 6. Follow Scenario1: “Step-7”

Related posts

Leave a Reply