当前位置:   article > 正文

[ 物联网篇 ] aws-iot-device-sdk-embedded-C Demo 测试_include directory '/home/tao/esp-aws-iot/aws-iot-d

include directory '/home/tao/esp-aws-iot/aws-iot-device-sdk-embedded-c/inclu

aws-iot-devices-sdk 是亚马逊针对物联网推出的一套解决方案,这里主要记录如何初步跑起来。

官方文档写的已经足够详细了,一定要看官网最新的英文版,看文档过程中,发现中文版已经落后很久了。

可以对比下AWS IoT SDK Tutorials,英文和中文描述就相差很大。 这里以英文版为主。

添加设备

这里主要登录AWS IoT添加一个设备,官方英文文档中的Connecting Your Raspberry Pi to AWS IoT写的已经很详细了,这里就不再复述,注册完成之后的界面:

在这里插入图片描述

在这里插入图片描述
注册过程中需要下载公钥和密钥

在这里插入图片描述
rootCA需要单独复制出来保存为rootCA.crt,选择图中高亮的CA即可
在这里插入图片描述

示例编译运行

下载源代码

git clone https://github.com/aws/aws-iot-device-sdk-embedded-C.git -b release
  • 1

编译源代码之前,需要安装CppUTestMbedtls第三方库,只需要把官方的源码复制到aws-iot-device-sdk-embedded-C/external_libs/ 对应的额目录即可

mbedtls 解压源码复制到aws-iot-device-sdk-embedded-C/external_libs/mbedTLS
https://tls.mbed.org/download/start/mbedtls-2.11.0-apache.tgz

cpputest 解压源码复制到aws-iot-device-sdk-embedded-C/external_libs/CppUTest
https://github.com/cpputest/cpputest/releases/tag/v3.6
  • 1
  • 2
  • 3
  • 4
  • 5

拷贝aws iot 后台创建设备时生成的证书到 aws-iot-device-sdk-embedded-C/certs

//证书如下
 certs git:(release)>ls 
47e9f5f0d6-certificate.pem.crt  47e9f5f0d6-private.pem.key  47e9f5f0d6-public.pem.key  README.txt  rootCA.crt
  • 1
  • 2
  • 3

这里以samples/linux/subscribe_publish_sample为例,编译之前,需要修aws_iot_config.h的配置,主要修改如下字段

// =================================================
#define AWS_IOT_MQTT_HOST              "a317ak53zstmeq-ats.iot.us-east-1.amazonaws.com" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow
#define AWS_IOT_MQTT_PORT              443 ///< default port for MQTT/S
#define AWS_IOT_MQTT_CLIENT_ID         "c-sdk-client-id" ///< MQTT client ID should be unique for every device
#define AWS_IOT_MY_THING_NAME 		   "MyRaspberryPI" ///< Thing Name of the Shadow this device is associated with
#define AWS_IOT_ROOT_CA_FILENAME       "rootCA.crt" ///< Root CA file name
#define AWS_IOT_CERTIFICATE_FILENAME   "47e9f5f0d6-certificate.pem.crt" ///< device signed certificate file name
#define AWS_IOT_PRIVATE_KEY_FILENAME   "47e9f5f0d6-private.pem.key" ///< Device private key filename
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

完成之后,编译成功运行如下:

➜  subscribe_publish_sample git:(release) ✗ >./subscribe_publish_sample 

AWS IoT SDK Version 3.0.1-

DEBUG:   main L#159 rootCA /home/zhaomm/Code/code/aws-iot-device-sdk-embedded-C/samples/linux/subscribe_publish_sample/../../../certs/rootCA.crt
DEBUG:   main L#160 clientCRT /home/zhaomm/Code/code/aws-iot-device-sdk-embedded-C/samples/linux/subscribe_publish_sample/../../../certs/47e9f5f0d6-certificate.pem.crt
DEBUG:   main L#161 clientKey /home/zhaomm/Code/code/aws-iot-device-sdk-embedded-C/samples/linux/subscribe_publish_sample/../../../certs/47e9f5f0d6-private.pem.key
Connecting...
DEBUG:   iot_tls_connect L#130 
  . Seeding the random number generator...
DEBUG:   iot_tls_connect L#138   . Loading the CA root certificate ...
DEBUG:   iot_tls_connect L#144  ok (0 skipped)

DEBUG:   iot_tls_connect L#146   . Loading the client cert. and key...
DEBUG:   iot_tls_connect L#159  ok

DEBUG:   iot_tls_connect L#161   . Connecting to a317ak53zstmeq-ats.iot.us-east-1.amazonaws.com/8883...
DEBUG:   iot_tls_connect L#180  ok

DEBUG:   iot_tls_connect L#182   . Setting up the SSL/TLS structure...
DEBUG:   iot_tls_connect L#223 

SSL state connect : 0 
DEBUG:   iot_tls_connect L#226  ok

DEBUG:   iot_tls_connect L#228 

SSL state connect : 0 
DEBUG:   iot_tls_connect L#229   . Performing the SSL/TLS handshake...
DEBUG:   _iot_tls_verify_cert L#49 
Verify requested for (Depth 2):

DEBUG:   _iot_tls_verify_cert L#51 cert. version     : 3
serial number     : 06:6C:9F:CF:99:BF:8C:0A:39:E2:F0:78:8A:43:E6:96:36:5B:CA
issuer name       : C=US, O=Amazon, CN=Amazon Root CA 1
subject name      : C=US, O=Amazon, CN=Amazon Root CA 1
issued  on        : 2015-05-26 00:00:00
expires on        : 2038-01-17 00:00:00
signed using      : RSA with SHA-256
RSA key size      : 2048 bits
basic constraints : CA=true
key usage         : Digital Signature, Key Cert Sign, CRL Sign

DEBUG:   _iot_tls_verify_cert L#54   This certificate has no flags

DEBUG:   _iot_tls_verify_cert L#49 
Verify requested for (Depth 1):

DEBUG:   _iot_tls_verify_cert L#51 cert. version     : 3
serial number     : 06:7F:94:57:85:87:E8:AC:77:DE:B2:53:32:5B:BC:99:8B:56:0D
issuer name       : C=US, O=Amazon, CN=Amazon Root CA 1
subject name      : C=US, O=Amazon, OU=Server CA 1B, CN=Amazon
issued  on        : 2015-10-22 00:00:00
expires on        : 2025-10-19 00:00:00
signed using      : RSA with SHA-256
RSA key size      : 2048 bits
basic constraints : CA=true, max_pathlen=0
key usage         : Digital Signature, Key Cert Sign, CRL Sign

DEBUG:   _iot_tls_verify_cert L#54   This certificate has no flags

DEBUG:   _iot_tls_verify_cert L#49 
Verify requested for (Depth 0):

DEBUG:   _iot_tls_verify_cert L#51 cert. version     : 3
serial number     : 06:66:B4:8C:67:DF:2F:E7:A9:A2:26:55:3E:71:EE:24
issuer name       : C=US, O=Amazon, OU=Server CA 1B, CN=Amazon
subject name      : CN=*.iot.us-east-1.amazonaws.com
issued  on        : 2018-08-02 00:00:00
expires on        : 2019-08-02 12:00:00
signed using      : RSA with SHA-256
RSA key size      : 2048 bits
basic constraints : CA=false
subject alt name  : iot.us-east-1.amazonaws.com, *.iot.us-east-1.amazonaws.com
key usage         : Digital Signature, Key Encipherment
ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication

DEBUG:   _iot_tls_verify_cert L#54   This certificate has no flags

DEBUG:   iot_tls_connect L#246  ok
    [ Protocol is TLSv1.2 ]
    [ Ciphersuite is TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384 ]

DEBUG:   iot_tls_connect L#248     [ Record expansion is 29 ]

DEBUG:   iot_tls_connect L#253   . Verifying peer X.509 certificate...
DEBUG:   iot_tls_connect L#262  ok

DEBUG:   iot_tls_connect L#272   . Peer certificate information    ...

DEBUG:   iot_tls_connect L#274       cert. version     : 3
      serial number     : 06:66:B4:8C:67:DF:2F:E7:A9:A2:26:55:3E:71:EE:24
      issuer name       : C=US, O=Amazon, OU=Server CA 1B, CN=Amazon
      subject name      : CN=*.iot.us-east-1.amazonaws.com
      issued  on        : 2018-08-02 00:00:00
      expires on        : 2019-08-02 12:00:00
      signed using      : RSA with SHA-256
      RSA key size      : 2048 bits
      basic constraints : CA=false
      subject alt name  : iot.us-east-1.amazonaws.com, *.iot.us-east-1.amazonaws.com
      key usage         : Digital Signature, Key Encipherment
      ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication


Subscribing...
-->sleep
Subscribe callback
sdkTest/sub	hello from SDK QOS0 : 0 
Subscribe callback
sdkTest/sub	hello from SDK QOS1 : 1 
-->sleep

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112

进入亚马逊IOT云端提供的测试页面

双方订阅一样的消息

在这里插入图片描述
客户端和云端实际通讯的界面

在这里插入图片描述

参考
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号