"Application - AWS IoT" 修訂間的差異
(已建立頁面,內容為 " Reference https://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/getting_started_espressif.html") |
(→lambda) |
||
(未顯示同一使用者於中間所作的 13 次修訂) | |||
行 1: | 行 1: | ||
− | [[ | + | == Setup your AWS CLI installation == |
+ | ** sudo apt install awscli | ||
+ | * Go to IAM service to get the Access keys | ||
+ | ** aws configure | ||
+ | <pre> | ||
+ | $ aws configure | ||
+ | AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE | ||
+ | AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY | ||
+ | Default region name [None]: us-west-2 | ||
+ | Default output format [None]: json | ||
+ | </pre> | ||
+ | * AWS development package - boto3 | ||
+ | ** pip install tornado nose | ||
+ | ** pip install boto3 | ||
+ | * Get AWS FreeRTOS | ||
+ | ** https://github.com/aws/amazon-freertos | ||
+ | * Create IoT thing | ||
+ | ** vim freertos/tools/aws_config_quick_start/configure.json | ||
+ | ** cd freertos/tools/aws_config_quick_start | ||
+ | ** python SetupAWS.py setup | ||
+ | * Toolchain version(5.2.0 is better) | ||
+ | <pre> | ||
+ | $ xtensa-esp32-elf-gcc --version | ||
+ | xtensa-esp32-elf-gcc (crosstool-NG crosstool-ng-1.22.0-80-g6c4433a) 5.2.0 | ||
+ | Copyright (C) 2015 Free Software Foundation, Inc. | ||
+ | This is free software; see the source for copying conditions. There is NO | ||
+ | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
+ | </pre> | ||
+ | * Build | ||
+ | <pre> | ||
+ | cd freertos | ||
+ | mkdir build | ||
+ | cmake -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 -DCMAKE_BUILD_TYPE=Debug -S . -B build | ||
+ | cd build | ||
+ | make all -j4 | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | == lambda == | ||
+ | * <span style="color:red">Note that if you use Alexa-hosted skill for lambda, you may not configure the permission for AWSIoTFullAccess</span> | ||
+ | *Function example(node.js) | ||
+ | <pre> | ||
+ | |||
+ | var AWS = require('aws-sdk'); | ||
+ | |||
+ | var iotdata = new AWS.IotData({endpoint:"a1q79ntmqqqssy-ats.iot.us-west-2.amazonaws.com"}); | ||
+ | |||
+ | exports.handler = function(event, context, callback) { | ||
+ | |||
+ | console.log("found iotdata",iotdata); | ||
+ | |||
+ | var params = { | ||
+ | topic: 'iotdemo/topic/2', | ||
+ | payload: 'on', | ||
+ | qos: 0 | ||
+ | }; | ||
+ | |||
+ | |||
+ | iotdata.publish(params, function(err, data){ | ||
+ | if(err){ | ||
+ | console.log("Error occured : ",err); | ||
+ | } | ||
+ | else{ | ||
+ | console.log("success....."); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | callback(); | ||
+ | }; | ||
+ | </pre> | ||
+ | * Trigger | ||
+ | ** Allow Alexa skill kit with ARN | ||
+ | * IAM Permission | ||
+ | ** AWSIoTFullAccess | ||
+ | |||
+ | * Reference | ||
https://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/getting_started_espressif.html | https://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/getting_started_espressif.html |
於 2020年7月16日 (四) 11:11 的最新修訂
Setup your AWS CLI installation
- sudo apt install awscli
- Go to IAM service to get the Access keys
- aws configure
$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-west-2 Default output format [None]: json
- AWS development package - boto3
- pip install tornado nose
- pip install boto3
- Get AWS FreeRTOS
- Create IoT thing
- vim freertos/tools/aws_config_quick_start/configure.json
- cd freertos/tools/aws_config_quick_start
- python SetupAWS.py setup
- Toolchain version(5.2.0 is better)
$ xtensa-esp32-elf-gcc --version xtensa-esp32-elf-gcc (crosstool-NG crosstool-ng-1.22.0-80-g6c4433a) 5.2.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Build
cd freertos mkdir build cmake -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 -DCMAKE_BUILD_TYPE=Debug -S . -B build cd build make all -j4
lambda
- Note that if you use Alexa-hosted skill for lambda, you may not configure the permission for AWSIoTFullAccess
- Function example(node.js)
var AWS = require('aws-sdk'); var iotdata = new AWS.IotData({endpoint:"a1q79ntmqqqssy-ats.iot.us-west-2.amazonaws.com"}); exports.handler = function(event, context, callback) { console.log("found iotdata",iotdata); var params = { topic: 'iotdemo/topic/2', payload: 'on', qos: 0 }; iotdata.publish(params, function(err, data){ if(err){ console.log("Error occured : ",err); } else{ console.log("success....."); } }); callback(); };
- Trigger
- Allow Alexa skill kit with ARN
- IAM Permission
- AWSIoTFullAccess
- Reference
https://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/getting_started_espressif.html