QNAP NAS
AIoT project example - Hybrid cloud object detection tutorial combine AWS and QNAP NAS (using AWS Greengrass + QNAP QIoT Suite + QNAP QuAI with Raspberry Pi Camera)
- Get link
- X
- Other Apps
You need to prepare :
AWS Account
Raspberry Pi
USB webcam
Scenario-1 Collect data to gateway and then make decision in public cloud
IoT device to Gateway(QNAP NAS):Step-1 : Prepare AWS Greengrass Core
Install AWS Greengrass App in QNAP NAS from App center
Setup your AWS Greengrass Group & Core in QNAP AWS Greengrass App. Please refer this link for more details :
https://www.qnap.com/en/how-to/tutorial/article/how-to-setup-aws-greengrass-on-qnap-nas/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. (建立Lambda function請參考AWS說明文件 : https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html)
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.Prepare following 3 subscriptions lists
Greengrass IoT Device to “SendGGImageToQIoT:9” Lambda for Image Prediction. Setting infomation :
- Source --> GG_Camera
- Target --> SendGGImageToQIoT
- Topic --> cameraImage
“QIoTIntegration” Lambda function to IoT Cloud for upload predicted image to S3 Bucket. Setting infomation :
- Source --> QIoTIntegration
- Target --> IoT Cloud
- Topic --> #
Greengrass IoT Device to “QIoTIntegration:16” Lambda is trigger Lambda to start. Setting infomation :
- Source --> GG_Camera
- Target --> QIoTIntegration
- Topic --> triggerLambda
Please refer the following image for these 3 subscriptions list source, destination and topic details
Deploy the Greengrass Group.
Verify Greengrass core daemon status in QNAP Greengrass App
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
Run this 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'}"
- -e : Aws IoT Endpoint (In IoT Core home page, under Settings, make a note of the value of Endpoint.)
- -r : Root CA Path (In here : https://docs.aws.amazon.com/iot/latest/developerguide/managing-device-certs.html)
- -c : Thing Ceritificate Path
- -k : Thing Private key Path
- -n : Thing Name
Step-2 : Setup AWS Greengrass IoT Device
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
Launch Container Station
Create -> search “qeekdev/aipredict”
Install
Advanced Settings
Setup Network
Container setup finished
Goto http://<IP>:8082/api/v1/ for testing:
reference - Dockerhub : 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?
Create an IoT App and 2 Things : “cameraPi” and “AWSgreengrass”
And create Thing Resource : cameraPi–>“image” and AWSgreengrass–>“resolve”
Import rulesJson.json in Node-Red rule engine using Rules tab --> Import --> Clipboard option. After import you can see the following 2 rules flow
Verify your dashboard
test Dashboard, AI Sample Container and AWS Greengrass
Debug
Go to Dashboard page
Step-5 : Setup AWS cloud S3 bucket & Rules
Create MoveImageToS3 Node.js Lambda function in AWS Lambda service. (Please find Demo Lambda source codes inside this folder AWS_Greengrass_Lambda)(建立Lambda function請參考AWS說明文件 : https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html)
Create a new S3 bucket “qiotquaiggdemo” in AWS S3 service (reference: : https://aws.amazon.com/s3/getting-started/?nc1=h_ls)
modify Lambda Function - S3 Bucket settings, please follow your AWS IAM and S3 settings (accessKeyId、secretAccessKey、Bucket).
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”
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"
- -e : Aws IoT Endpoint (In IoT Core home page, under Settings, make a note of the value of Endpoint.)
- -r : Root CA Path
- -c : Thing Ceritificate Path
- -k : Thing Private key Path
- -n : Thing Name
Step-7 : Verify the demo
In QIoT Suite Dashboard :
In AWS IoT Cloud :
In AWS S3 :
Scenario-2 Collect date and performance edge computing in gateway and then store/publish information to public cloud
Camera --> QIoT Suite 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.
Steps :
Install dependency library and software
pip install paho-mqtt sudo apt update && sudo apt install fswebcam
Follow in Scenario-1–> “Step-1” to “Step-5”
Upload RaspberryPi_side floder to Raspberry Pi
Download “resourceinfo.json” from QIoT Suite Lite cameraPi thing and put resourceinfo.json under the “/res” folder
Run command :
python main.py
Follow in Scenario-1–> “Step-7”
Comments
Post a Comment