AWS-IOT套件使用介绍

AWS-IOT套件使用介绍

Amazon IOT有一套完整的SDK,涉及到IOT设备端,IOT服务器(当然是Amazon的特长),以及包括手机,网页平台的开发SDK。Amazon真有一套,它也有全家桶,只是Level更高一些吧。来让我们一探全貌。

1,Overview

申请Amazon的开发者账户(非剁手账户),进入console就能看到所提供的服务
 
 公司的数据管理,开发工具,网络服务等等,方方面面都有。这也是现在做云平台服务提供商的特点。我在几个月前申请了EC2服务,即免费使用云主机一年。今天我们要讨论的是IOT套件,已经人工智能的Polly,先看IOT。

2,IOT设备端配置

2.1,先连接->配置设备的开始使用
AWS IoT按钮:是一个Amazon的硬件设备,好像是几十刀
AWS IoT初学者工具包:学习包。
我们选择配置设备项。
就开始配置一种方式与Amazon的服务器进行通信了,具体在什么平台与什么语言运行,都是可选的。
2.2,选择Linux平台,使用Python语言
 
2.3,然后下载sdk包,解压
zip包里面包含了一些认证的公钥和一个start.sh的脚本文件,该文件是用于下载sdk包,以及启动测试。
  1. $ ls
  2. connect_device_package.zip kf-iot-2-python.cert.pem kf-iot-2-python.private.key kf-iot-2-python.public.key start.sh
2.4,增加权限之后,切换到root用户,运行./start.sh
能看到一些与服务器通信的debug信息输出
  1. 2017-06-19 19:00:55,422 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Try to put a publish request 4 in the TCP stack.
  2. 2017-06-19 19:00:55,422 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Publish request 4 succeeded.
  3. Received a new message:
  4. New Message 2
  5. from topic:
  6. sdk/test/Python
  7. --------------
  8. 2017-06-19 19:00:56,424 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Try to put a publish request 5 in the TCP stack.
  9. 2017-06-19 19:00:56,424 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Publish request 5 succeeded.
  10. Received a new message:
  11. New Message 3
  12. from topic:
  13. sdk/test/Python
  14. --------------
  15. 2017-06-19 19:00:57,426 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Try to put a publish request 6 in the TCP stack.
  16. 2017-06-19 19:00:57,427 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Publish request 6 succeeded.
  17. Received a new message:
  18. New Message 4
  19. from topic:
  20. sdk/test/Python
其中,不难看出服务器是基于mqtt服务器。这样iot的设备端就运行起来了。

 3,服务器端管理

回到网页管理的console,选择测试,连接成功之后,就会有一些简单的测试
 当然还有其它的项,都可以自己玩的。

4,客户端的处理

设备连接到云服务器了,我们还需要通过手机,网页等客户端来获取IoT设备的状态,这样才是物联网的典型架构,我们导航到软件栏。
 我们打开IoT设备软件开发工具包,都有什么,
又是一个全家桶:
 
当然Android狗,先只关注Android栏目。这里面就有SDK(托管到github上),开发指南,以及示例。使用SDK最好的方法,就是跑通客户提供的示例。

5,SDK示例试运行

5.1,下载示例项目
git clone https://github.com/awslabs/aws-sdk-android-samples
5.2,包含哪些子项目
在根目录的Readme里面,详细列出来
  1. List of Samples
  2. CognitoSyncDemo. This is a sample mobile application that demonstrates how to use Amazon Cognito. Involved AWS Services are:
  3. Amazon Cognito Identity
  4. Amazon Cognito Sync
  5. S3TransferUtilitySample. This is a sample mobile application that demonstrates how to use Amazon S3 Transfer Utility to download and upload files to Amazon S3. Involved AWS Services are:
  6. Amazon Cognito Identity
  7. Amazon S3
  8. DynamoDBMapper. This is a sample mobile application that demonstrates how to use Amazon DynamoDB Object Mapper. Involved AWS Services are:
  9. Amazon Cognito Identity
  10. Amazon DynamoDB
  11. AndroidPubSub. This sample demonstrates use of the AWS IoT APIs to securely publish to and subscribe from MQTT topics with TLS and IoT certificates. Involved AWS Services are:
  12. Amazon Cognito Identity
  13. AWS IoT
  14. AndroidPubSubWebSocket. This sample demonstrates use of the AWS IoT APIs to securely publish to and subscribe from MQTT topics with WebSockets. Involved AWS Services are:
  15. Amazon Cognito Identity
  16. AWS IoT
  17. CreateIotCertWithCSR. This sample demonstrates use of the AWS IoT APIs to create an AWS IoT certificate. Involved AWS Services are:
  18. Amazon Cognito Identity
  19. AWS IoT
  20. TemperatureControl. This sample demonstrates use of the AWS IoT device shadow APIs. Involved AWS Services are:
  21. Amazon Cognito Identity
  22. AWS IoT
  23. PollyDemo. This is a sample mobile application that demonstrates how to use Amazon Polly. Involved AWS Services are:
  24. Amazon Cognito Identity
  25. Amazon Polly
  26. Lex Sample. This is a sample mobile application that demonstrates how to use Amazon Lex. Involved AWS Services are:
  27. Amazon Cognito Identity
  28. Amazon Lex
5.3,拟运行PollyDemo项目,根据官方的文档这是一个文字转读音的项目(Lifelike Text-to-Speech),类似Google的TTS项目。打开AS,选择导入项目,设置好SDK版本,编译工具版本,应该能编译通过。但正常的使用还需要做两个件事。
  • 新建开发者ID

进入https://console.aws.amazon.com/cognito/

填写好名字之后,然后就能看到自己的ID码了
  1. // Initialize the Amazon Cognito credentials provider
  2. CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
  3. getApplicationContext(),
  4. "us-west-2:664aa7f7-8352-49dd-96f2-05734eafxxxx", // Identity Pool ID
  5. Regions.US_WEST_2 // Region
  6. );
  • 添加授权
 
这两步完成之后就是修改源码
5.4,修改MainActivity.java
  1. // Amazon Polly permissions.
  2. private static final String COGNITO_POOL_ID = "us-west-2:664aa7f7-8352-49dd-96f2-05734eafxxxx";
  3. // Region of Amazon Polly.
  4. private static final Regions MY_REGION = Regions.US_WEST_2;

6,编译安装调试

这样就整个流程走了一遍,当然其它更多,更有意义的服务就等你去挖掘,比如机器人项目,祝你好运。
 
Comments are closed.
TOP