yh Tang
/
NuMaker-mbed-AWS-IoT-example
NuMaker connection with AWS IoT thru MQTT/HTTPS
README.md@6:7ef096085ca7, 2018-02-01 (annotated)
- Committer:
- ccli8
- Date:
- Thu Feb 01 17:39:19 2018 +0800
- Revision:
- 6:7ef096085ca7
- Parent:
- 5:2a70e217325f
- Child:
- 19:b8191f21eeaf
Update README.md for timeout configuration over ESP8266 WiFi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ccli8 |
1:5ffad9f24d63 | 1 | # Example for Connection with AWS IoT thru MQTT/HTTPS on Mbed OS |
ccli8 |
1:5ffad9f24d63 | 2 | |
ccli8 |
1:5ffad9f24d63 | 3 | This is an example to demonstrate connection with [AWS IoT](https://aws.amazon.com/iot) |
ccli8 |
1:5ffad9f24d63 | 4 | on Nuvoton Mbed-enabled boards. |
ccli8 |
1:5ffad9f24d63 | 5 | |
ccli8 |
1:5ffad9f24d63 | 6 | ## Supported platforms |
ccli8 |
1:5ffad9f24d63 | 7 | On Mbed OS, connection with AWS IoT requires Mbed TLS. It requires more than 64 KB RAM. |
ccli8 |
1:5ffad9f24d63 | 8 | Currently, the following Nuvoton Mbed-enalbed boards can afford such memory footprint: |
ccli8 |
1:5ffad9f24d63 | 9 | - [NuMaker-PFM-NUC472](https://developer.mbed.org/platforms/Nuvoton-NUC472/) |
ccli8 |
1:5ffad9f24d63 | 10 | - [NuMaker-PFM-M487](https://developer.mbed.org/platforms/NUMAKER-PFM-M487/) |
ccli8 |
1:5ffad9f24d63 | 11 | |
ccli8 |
1:5ffad9f24d63 | 12 | ## Access and manage AWS IoT Service |
ccli8 |
1:5ffad9f24d63 | 13 | To run the example, you need to register one [AWS account](https://aws.amazon.com/) |
ccli8 |
1:5ffad9f24d63 | 14 | to access and manage AWS IoT Service for your device to connect with. |
ccli8 |
1:5ffad9f24d63 | 15 | This [link](https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html) gives detailed |
ccli8 |
1:5ffad9f24d63 | 16 | information about it. |
ccli8 |
1:5ffad9f24d63 | 17 | |
ccli8 |
1:5ffad9f24d63 | 18 | 1. Sign in to [AWS Management Console](https://aws.amazon.com/console/). |
ccli8 |
1:5ffad9f24d63 | 19 | 1. Enter AWS IoT Service. |
ccli8 |
1:5ffad9f24d63 | 20 | 1. In AWS IoT Service, create a thing. |
ccli8 |
1:5ffad9f24d63 | 21 | The Console may prompt you to also create a certificate and a policy. Skip for creating them later. |
ccli8 |
1:5ffad9f24d63 | 22 | 1. In AWS IoT Service, create a policy. A workable example would be below. |
ccli8 |
1:5ffad9f24d63 | 23 | Note that you need to replace **REGION** and **ACCOUNT** to match your case. |
ccli8 |
1:5ffad9f24d63 | 24 | |
ccli8 |
1:5ffad9f24d63 | 25 | <pre> |
ccli8 |
1:5ffad9f24d63 | 26 | { |
ccli8 |
1:5ffad9f24d63 | 27 | "Version": "2012-10-17", |
ccli8 |
1:5ffad9f24d63 | 28 | "Statement": [ |
ccli8 |
1:5ffad9f24d63 | 29 | { |
ccli8 |
1:5ffad9f24d63 | 30 | "Effect": "Allow", |
ccli8 |
1:5ffad9f24d63 | 31 | "Action": "iot:Connect", |
ccli8 |
1:5ffad9f24d63 | 32 | "Resource": "arn:aws:iot:<b>REGION</b>:<b>ACCOUNT</b>:client/*" |
ccli8 |
1:5ffad9f24d63 | 33 | }, |
ccli8 |
1:5ffad9f24d63 | 34 | { |
ccli8 |
1:5ffad9f24d63 | 35 | "Effect": "Allow", |
ccli8 |
1:5ffad9f24d63 | 36 | "Action": "iot:Subscribe", |
ccli8 |
1:5ffad9f24d63 | 37 | "Resource": ["arn:aws:iot:<b>REGION</b>:<b>ACCOUNT</b>:topicfilter/*"] |
ccli8 |
1:5ffad9f24d63 | 38 | }, |
ccli8 |
1:5ffad9f24d63 | 39 | { |
ccli8 |
1:5ffad9f24d63 | 40 | "Effect": "Allow", |
ccli8 |
1:5ffad9f24d63 | 41 | "Action": ["iot:Publish", "iot:Receive"], |
ccli8 |
1:5ffad9f24d63 | 42 | "Resource": "arn:aws:iot:<b>REGION</b>:<b>ACCOUNT</b>:topic/*" |
ccli8 |
1:5ffad9f24d63 | 43 | }, |
ccli8 |
1:5ffad9f24d63 | 44 | { |
ccli8 |
1:5ffad9f24d63 | 45 | "Effect": "Allow", |
ccli8 |
1:5ffad9f24d63 | 46 | "Action": ["iot:UpdateThingShadow", "iot:GetThingShadow", "iot:DeleteThingShadow"], |
ccli8 |
1:5ffad9f24d63 | 47 | "Resource": "arn:aws:iot:<b>REGION</b>:<b>ACCOUNT</b>:thing/*" |
ccli8 |
1:5ffad9f24d63 | 48 | } |
ccli8 |
1:5ffad9f24d63 | 49 | ] |
ccli8 |
1:5ffad9f24d63 | 50 | } |
ccli8 |
1:5ffad9f24d63 | 51 | </pre> |
ccli8 |
1:5ffad9f24d63 | 52 | |
ccli8 |
1:5ffad9f24d63 | 53 | 1. In AWS IoT Service, create a certificate. You would get 4 security credential files from it. |
ccli8 |
1:5ffad9f24d63 | 54 | Download them for later use. |
ccli8 |
1:5ffad9f24d63 | 55 | - AWS IoT's CA certificate |
ccli8 |
1:5ffad9f24d63 | 56 | - User certificate |
ccli8 |
1:5ffad9f24d63 | 57 | - User private key |
ccli8 |
1:5ffad9f24d63 | 58 | - User public key |
ccli8 |
1:5ffad9f24d63 | 59 | |
ccli8 |
1:5ffad9f24d63 | 60 | After creating the certificate, do: |
ccli8 |
1:5ffad9f24d63 | 61 | 1. Activate the certificate |
ccli8 |
1:5ffad9f24d63 | 62 | 1. Attach the thing created above to the certificate |
ccli8 |
1:5ffad9f24d63 | 63 | 1. Attach the policy created above to the certificate |
ccli8 |
1:5ffad9f24d63 | 64 | |
ccli8 |
1:5ffad9f24d63 | 65 | ## Configure your device with AWS IoT |
ccli8 |
1:5ffad9f24d63 | 66 | Before connecting your device with AWS IoT, you need to configure security credential and |
ccli8 |
1:5ffad9f24d63 | 67 | protocol dependent parameters into your device. These configurations are all centralized in `main.cpp`. |
ccli8 |
1:5ffad9f24d63 | 68 | |
ccli8 |
1:5ffad9f24d63 | 69 | ### Configure certificate into your device |
ccli8 |
1:5ffad9f24d63 | 70 | From above, you've got 4 security credential files: CA certificate and user certificate/private key/public key. |
ccli8 |
1:5ffad9f24d63 | 71 | Configure CA certificate, user certificate, and user private key into your device. |
ccli8 |
1:5ffad9f24d63 | 72 | User public key has been included in user certificate and is not used here. |
ccli8 |
1:5ffad9f24d63 | 73 | 1. Replace CA certificate with downloaded from the Console. |
ccli8 |
1:5ffad9f24d63 | 74 | ``` |
ccli8 |
1:5ffad9f24d63 | 75 | const char SSL_CA_CERT_PEM[] = "-----BEGIN CERTIFICATE-----\n" |
ccli8 |
1:5ffad9f24d63 | 76 | "MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB\n" |
ccli8 |
1:5ffad9f24d63 | 77 | "yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL\n" |
ccli8 |
1:5ffad9f24d63 | 78 | ``` |
ccli8 |
1:5ffad9f24d63 | 79 | |
ccli8 |
1:5ffad9f24d63 | 80 | 1. Replace user certificate with downloaded from the Console. |
ccli8 |
1:5ffad9f24d63 | 81 | ``` |
ccli8 |
1:5ffad9f24d63 | 82 | const char SSL_USER_CERT_PEM[] = "-----BEGIN CERTIFICATE-----\n" |
ccli8 |
1:5ffad9f24d63 | 83 | "MIIDWjCCAkKgAwIBAgIVALN/H7tr8cgpl2zwg0JjEE106XilMA0GCSqGSIb3DQEB\n" |
ccli8 |
1:5ffad9f24d63 | 84 | "CwUAME0xSzBJBgNVBAsMQkFtYXpvbiBXZWIgU2VydmljZXMgTz1BbWF6b24uY29t\n" |
ccli8 |
1:5ffad9f24d63 | 85 | ``` |
ccli8 |
1:5ffad9f24d63 | 86 | |
ccli8 |
1:5ffad9f24d63 | 87 | 1. Replace user private key with downloaded from the Console. |
ccli8 |
1:5ffad9f24d63 | 88 | ``` |
ccli8 |
1:5ffad9f24d63 | 89 | const char SSL_USER_PRIV_KEY_PEM[] = "-----BEGIN RSA PRIVATE KEY-----\n" |
ccli8 |
1:5ffad9f24d63 | 90 | ``` |
ccli8 |
1:5ffad9f24d63 | 91 | |
ccli8 |
4:dc23eeba885a | 92 | **NOTE:** The credential hard-coded in source code is deactivated or deleted. |
ccli8 |
4:dc23eeba885a | 93 | Use your own credential for connection with AWS IoT. |
ccli8 |
4:dc23eeba885a | 94 | |
ccli8 |
1:5ffad9f24d63 | 95 | ### Connect through MQTT |
ccli8 |
1:5ffad9f24d63 | 96 | To connect your device with AWS IoT through MQTT, you need to configure the following parameters. |
ccli8 |
1:5ffad9f24d63 | 97 | |
ccli8 |
1:5ffad9f24d63 | 98 | 1. Enable connection through MQTT. |
ccli8 |
1:5ffad9f24d63 | 99 | ``` |
ccli8 |
1:5ffad9f24d63 | 100 | #define AWS_IOT_MQTT_TEST 1 |
ccli8 |
1:5ffad9f24d63 | 101 | ``` |
ccli8 |
1:5ffad9f24d63 | 102 | |
ccli8 |
1:5ffad9f24d63 | 103 | 1. Replace server name (endpoint). **Endpoint** has the following format and you just |
ccli8 |
1:5ffad9f24d63 | 104 | need to modify **IDENTIFIER** and **REGION** to match your case. |
ccli8 |
1:5ffad9f24d63 | 105 | <pre> |
ccli8 |
1:5ffad9f24d63 | 106 | #define AWS_IOT_MQTT_SERVER_NAME "<b>IDENTIFIER</b>.iot.<b>REGION</b>.amazonaws.com" |
ccli8 |
1:5ffad9f24d63 | 107 | </pre> |
ccli8 |
1:5ffad9f24d63 | 108 | |
ccli8 |
1:5ffad9f24d63 | 109 | 1. Server port number is fixed. Don't change it. |
ccli8 |
1:5ffad9f24d63 | 110 | ``` |
ccli8 |
1:5ffad9f24d63 | 111 | #define AWS_IOT_MQTT_SERVER_PORT 8883 |
ccli8 |
1:5ffad9f24d63 | 112 | ``` |
ccli8 |
1:5ffad9f24d63 | 113 | |
ccli8 |
1:5ffad9f24d63 | 114 | 1. Replace **THINGNAME** to match your case. The **THINGNAME** is just the name of the thing you've created above. |
ccli8 |
1:5ffad9f24d63 | 115 | <pre> |
ccli8 |
1:5ffad9f24d63 | 116 | #define AWS_IOT_MQTT_THINGNAME "<b>THINGNAME</b>" |
ccli8 |
1:5ffad9f24d63 | 117 | </pre> |
ccli8 |
1:5ffad9f24d63 | 118 | |
ccli8 |
1:5ffad9f24d63 | 119 | 1. Replace **CLIENTNAME** to match your case. If you adopt the example policy above, |
ccli8 |
1:5ffad9f24d63 | 120 | you can modify it arbitrarily because the policy permits any client name bound to your account. |
ccli8 |
1:5ffad9f24d63 | 121 | <pre> |
ccli8 |
1:5ffad9f24d63 | 122 | #define AWS_IOT_MQTT_CLIENTNAME "<b>CLIENTNAME</b>" |
ccli8 |
1:5ffad9f24d63 | 123 | </pre> |
ccli8 |
1:5ffad9f24d63 | 124 | |
ccli8 |
1:5ffad9f24d63 | 125 | AWS IoT MQTT protocol supports topic subscribe/publish. The example demonstrates: |
ccli8 |
1:5ffad9f24d63 | 126 | - Subscribe/publish with user topic |
ccli8 |
1:5ffad9f24d63 | 127 | - Subscribe/publish with reserved topic (starting with $) to: |
ccli8 |
1:5ffad9f24d63 | 128 | - Update thing shadow |
ccli8 |
1:5ffad9f24d63 | 129 | - Get thing shadow |
ccli8 |
1:5ffad9f24d63 | 130 | - Delete thing shadow |
ccli8 |
1:5ffad9f24d63 | 131 | |
ccli8 |
1:5ffad9f24d63 | 132 | ### Connect through HTTPS |
ccli8 |
1:5ffad9f24d63 | 133 | To connect your device with AWS IoT through HTTPS, you need to configure the following parameters. |
ccli8 |
1:5ffad9f24d63 | 134 | |
ccli8 |
1:5ffad9f24d63 | 135 | 1. Enable connection through HTTPS. |
ccli8 |
1:5ffad9f24d63 | 136 | ``` |
ccli8 |
1:5ffad9f24d63 | 137 | #define AWS_IOT_HTTPS_TEST 1 |
ccli8 |
1:5ffad9f24d63 | 138 | ``` |
ccli8 |
1:5ffad9f24d63 | 139 | |
ccli8 |
1:5ffad9f24d63 | 140 | 1. Replace server name (endpoint). **Endpoint** has the following format and you just |
ccli8 |
1:5ffad9f24d63 | 141 | need to modify **IDENTIFIER** and **REGION** to match your case. |
ccli8 |
1:5ffad9f24d63 | 142 | <pre> |
ccli8 |
1:5ffad9f24d63 | 143 | #define AWS_IOT_HTTPS_SERVER_NAME "<b>IDENTIFIER</b>.iot.<b>REGION</b>.amazonaws.com" |
ccli8 |
1:5ffad9f24d63 | 144 | </pre> |
ccli8 |
1:5ffad9f24d63 | 145 | |
ccli8 |
1:5ffad9f24d63 | 146 | 1. Server port number is fixed. Don't change it. |
ccli8 |
1:5ffad9f24d63 | 147 | ``` |
ccli8 |
1:5ffad9f24d63 | 148 | #define AWS_IOT_HTTPS_SERVER_PORT 8443 |
ccli8 |
1:5ffad9f24d63 | 149 | ``` |
ccli8 |
1:5ffad9f24d63 | 150 | |
ccli8 |
1:5ffad9f24d63 | 151 | 1. Replace **THINGNAME** to match your case. The **THINGNAME** is just the name of the thing you've created above. |
ccli8 |
1:5ffad9f24d63 | 152 | <pre> |
ccli8 |
1:5ffad9f24d63 | 153 | #define AWS_IOT_HTTPS_THINGNAME "<b>THINGNAME</b>" |
ccli8 |
1:5ffad9f24d63 | 154 | </pre> |
ccli8 |
1:5ffad9f24d63 | 155 | |
ccli8 |
1:5ffad9f24d63 | 156 | AWS IoT HTTPS protocol supports topic publish-only and RESTful API. The example demonstrates: |
ccli8 |
1:5ffad9f24d63 | 157 | - Publish to user topic |
ccli8 |
1:5ffad9f24d63 | 158 | - Publish to reserved topic (starting with $) to: |
ccli8 |
1:5ffad9f24d63 | 159 | - Update thing shadow |
ccli8 |
1:5ffad9f24d63 | 160 | - Get thing shadow |
ccli8 |
1:5ffad9f24d63 | 161 | - Delete thing shadow |
ccli8 |
1:5ffad9f24d63 | 162 | - RESTful API to: |
ccli8 |
1:5ffad9f24d63 | 163 | - Update thing shadow RESTfully through HTTPS/POST method |
ccli8 |
1:5ffad9f24d63 | 164 | - Get thing shadow RESTfully through HTTPS/GET method |
ccli8 |
1:5ffad9f24d63 | 165 | - Delete thing shadow RESTfully through HTTPS/DELETE method |
ccli8 |
1:5ffad9f24d63 | 166 | |
ccli8 |
1:5ffad9f24d63 | 167 | ## Patch MQTT library |
ccli8 |
1:5ffad9f24d63 | 168 | Currently, MQTT library has one issue with unsubscribe from topic multiple times. Fix it: |
ccli8 |
1:5ffad9f24d63 | 169 | |
ccli8 |
1:5ffad9f24d63 | 170 | In `MQTT/MQTTClient.h` > `MQTT::Client<Network, Timer, MAX_MQTT_PACKET_SIZE, b>::cycle`, |
ccli8 |
1:5ffad9f24d63 | 171 | <pre> |
ccli8 |
1:5ffad9f24d63 | 172 | switch (packet_type) |
ccli8 |
1:5ffad9f24d63 | 173 | { |
ccli8 |
1:5ffad9f24d63 | 174 | default: |
ccli8 |
1:5ffad9f24d63 | 175 | // no more data to read, unrecoverable. Or read packet fails due to unexpected network error |
ccli8 |
1:5ffad9f24d63 | 176 | rc = packet_type; |
ccli8 |
1:5ffad9f24d63 | 177 | goto exit; |
ccli8 |
1:5ffad9f24d63 | 178 | case 0: // timed out reading packet |
ccli8 |
1:5ffad9f24d63 | 179 | break; |
ccli8 |
1:5ffad9f24d63 | 180 | case CONNACK: |
ccli8 |
1:5ffad9f24d63 | 181 | case PUBACK: |
ccli8 |
1:5ffad9f24d63 | 182 | case SUBACK: |
ccli8 |
1:5ffad9f24d63 | 183 | <b> |
ccli8 |
1:5ffad9f24d63 | 184 | case UNSUBACK: |
ccli8 |
1:5ffad9f24d63 | 185 | </b> |
ccli8 |
1:5ffad9f24d63 | 186 | break; |
ccli8 |
1:5ffad9f24d63 | 187 | case PUBLISH: |
ccli8 |
1:5ffad9f24d63 | 188 | { |
ccli8 |
1:5ffad9f24d63 | 189 | </pre> |
ccli8 |
1:5ffad9f24d63 | 190 | |
ccli8 |
1:5ffad9f24d63 | 191 | ## Monitor the application |
ccli8 |
1:5ffad9f24d63 | 192 | If you configure your terminal program with **9600/8-N-1**, you would see output similar to: |
ccli8 |
1:5ffad9f24d63 | 193 | |
ccli8 |
1:5ffad9f24d63 | 194 | **NOTE:** Make sure that the network is functional before running the application. |
ccli8 |
1:5ffad9f24d63 | 195 | |
ccli8 |
1:5ffad9f24d63 | 196 | <pre> |
ccli8 |
1:5ffad9f24d63 | 197 | Starting AWS IoT test |
ccli8 |
1:5ffad9f24d63 | 198 | Using Mbed OS 5.7.1 |
ccli8 |
1:5ffad9f24d63 | 199 | [EasyConnect] IPv4 mode |
ccli8 |
1:5ffad9f24d63 | 200 | Connecting with a1fbcwaqfqeozo.iot.us-east-1.amazonaws.com:8883 |
ccli8 |
1:5ffad9f24d63 | 201 | Connecting to a1fbcwaqfqeozo.iot.us-east-1.amazonaws.com:8883 |
ccli8 |
1:5ffad9f24d63 | 202 | </pre> |
ccli8 |
1:5ffad9f24d63 | 203 | |
ccli8 |
1:5ffad9f24d63 | 204 | If you get here successfully, it means configurations with security credential are correct. |
ccli8 |
1:5ffad9f24d63 | 205 | <pre> |
ccli8 |
1:5ffad9f24d63 | 206 | Starting the TLS handshake... |
ccli8 |
1:5ffad9f24d63 | 207 | TLS connection to a1fbcwaqfqeozo.iot.us-east-1.amazonaws.com:8883 established |
ccli8 |
1:5ffad9f24d63 | 208 | Server certificate: |
ccli8 |
1:5ffad9f24d63 | 209 | cert. version : 3 |
ccli8 |
1:5ffad9f24d63 | 210 | serial number : 3C:AC:B3:D3:3E:D8:6A:C9:2B:EF:D2:C5:B1:DC:BF:66 |
ccli8 |
1:5ffad9f24d63 | 211 | issuer name : C=US, O=Symantec Corporation, OU=Symantec Trust Network, CN=Symantec Class 3 ECC 256 bit SSL CA - G2 |
ccli8 |
1:5ffad9f24d63 | 212 | subject name : C=US, ST=Washington, L=Seattle, O=Amazon.com, Inc., CN=*.iot.us-east-1.amazonaws.com |
ccli8 |
1:5ffad9f24d63 | 213 | issued on : 2017-03-07 00:00:00 |
ccli8 |
1:5ffad9f24d63 | 214 | expires on : 2018-03-08 23:59:59 |
ccli8 |
1:5ffad9f24d63 | 215 | signed using : ECDSA with SHA256 |
ccli8 |
1:5ffad9f24d63 | 216 | EC key size : 256 bits |
ccli8 |
1:5ffad9f24d63 | 217 | basic constraints : CA=false |
ccli8 |
1:5ffad9f24d63 | 218 | subject alt name : iot.us-east-1.amazonaws.com, *.iot.us-east-1.amazonaws.com |
ccli8 |
1:5ffad9f24d63 | 219 | key usage : Digital Signature |
ccli8 |
1:5ffad9f24d63 | 220 | ext key usage : TLS Web Server Authentication, TLS Web Client Authentication |
ccli8 |
1:5ffad9f24d63 | 221 | Certificate verification passed |
ccli8 |
1:5ffad9f24d63 | 222 | |
ccli8 |
1:5ffad9f24d63 | 223 | Connects with a1fbcwaqfqeozo.iot.us-east-1.amazonaws.com:8883 OK |
ccli8 |
1:5ffad9f24d63 | 224 | </pre> |
ccli8 |
1:5ffad9f24d63 | 225 | |
ccli8 |
1:5ffad9f24d63 | 226 | MQTT handshake goes: |
ccli8 |
1:5ffad9f24d63 | 227 | <pre> |
ccli8 |
1:5ffad9f24d63 | 228 | MQTT connects OK |
ccli8 |
1:5ffad9f24d63 | 229 | |
ccli8 |
1:5ffad9f24d63 | 230 | Subscribing/publishing user topic |
ccli8 |
1:5ffad9f24d63 | 231 | MQTT subscribes to Nuvoton/Mbed/+ OK |
ccli8 |
1:5ffad9f24d63 | 232 | Message to publish: |
ccli8 |
1:5ffad9f24d63 | 233 | { "message": "Hello from Nuvoton Mbed device" } |
ccli8 |
1:5ffad9f24d63 | 234 | MQTT publishes message to Nuvoton/Mbed/D001 OK |
ccli8 |
1:5ffad9f24d63 | 235 | Message arrived: qos 1, retained 0, dup 0, packetid 1 |
ccli8 |
1:5ffad9f24d63 | 236 | Payload: |
ccli8 |
1:5ffad9f24d63 | 237 | { "message": "Hello from Nuvoton Mbed device" } |
ccli8 |
1:5ffad9f24d63 | 238 | |
ccli8 |
1:5ffad9f24d63 | 239 | MQTT unsubscribes from Nuvoton/Mbed/+ OK |
ccli8 |
1:5ffad9f24d63 | 240 | Subscribes/publishes user topic OK |
ccli8 |
1:5ffad9f24d63 | 241 | |
ccli8 |
1:5ffad9f24d63 | 242 | Subscribing/publishing UpdateThingShadow topic |
ccli8 |
1:5ffad9f24d63 | 243 | MQTT subscribes to $aws/things/Nuvoton-Mbed-D001/shadow/update/accepted OK |
ccli8 |
1:5ffad9f24d63 | 244 | MQTT subscribes to $aws/things/Nuvoton-Mbed-D001/shadow/update/rejected OK |
ccli8 |
1:5ffad9f24d63 | 245 | Message to publish: |
ccli8 |
1:5ffad9f24d63 | 246 | { "state": { "reported": { "attribute1": 3, "attribute2": "1" } } } |
ccli8 |
1:5ffad9f24d63 | 247 | MQTT publishes message to $aws/things/Nuvoton-Mbed-D001/shadow/update OK |
ccli8 |
1:5ffad9f24d63 | 248 | Message arrived: qos 1, retained 0, dup 0, packetid 1 |
ccli8 |
1:5ffad9f24d63 | 249 | Payload: |
ccli8 |
1:5ffad9f24d63 | 250 | {"state":{"reported":{"attribute1":3,"attribute2":"1"}},"metadata":{"reported":{"attribute1":{"timestamp":1514962195},"attribute2":{"timestamp":1514962195}}},"version":77,"timestamp":1514962195} |
ccli8 |
1:5ffad9f24d63 | 251 | |
ccli8 |
1:5ffad9f24d63 | 252 | MQTT unsubscribes from $aws/things/Nuvoton-Mbed-D001/shadow/update/accepted OK |
ccli8 |
1:5ffad9f24d63 | 253 | MQTT unsubscribes from $aws/things/Nuvoton-Mbed-D001/shadow/update/rejected OK |
ccli8 |
1:5ffad9f24d63 | 254 | Subscribes/publishes UpdateThingShadow topic OK |
ccli8 |
1:5ffad9f24d63 | 255 | |
ccli8 |
1:5ffad9f24d63 | 256 | Subscribing/publishing GetThingShadow topic |
ccli8 |
1:5ffad9f24d63 | 257 | MQTT subscribes to $aws/things/Nuvoton-Mbed-D001/shadow/get/accepted OK |
ccli8 |
1:5ffad9f24d63 | 258 | MQTT subscribes to $aws/things/Nuvoton-Mbed-D001/shadow/get/rejected OK |
ccli8 |
1:5ffad9f24d63 | 259 | Message to publish: |
ccli8 |
1:5ffad9f24d63 | 260 | |
ccli8 |
1:5ffad9f24d63 | 261 | MQTT publishes message to $aws/things/Nuvoton-Mbed-D001/shadow/get OK |
ccli8 |
1:5ffad9f24d63 | 262 | Message arrived: qos 1, retained 0, dup 0, packetid 1 |
ccli8 |
1:5ffad9f24d63 | 263 | Payload: |
ccli8 |
1:5ffad9f24d63 | 264 | {"state":{"reported":{"attribute1":3,"attribute2":"1"}},"metadata":{"reported":{"attribute1":{"timestamp":1514962195},"attribute2":{"timestamp":1514962195}}},"version":77,"timestamp":1514962198} |
ccli8 |
1:5ffad9f24d63 | 265 | |
ccli8 |
1:5ffad9f24d63 | 266 | MQTT unsubscribes from $aws/things/Nuvoton-Mbed-D001/shadow/get/accepted OK |
ccli8 |
1:5ffad9f24d63 | 267 | MQTT unsubscribes from $aws/things/Nuvoton-Mbed-D001/shadow/get/rejected OK |
ccli8 |
1:5ffad9f24d63 | 268 | Subscribes/publishes GetThingShadow topic OK |
ccli8 |
1:5ffad9f24d63 | 269 | |
ccli8 |
1:5ffad9f24d63 | 270 | Subscribing/publishing DeleteThingShadow topic |
ccli8 |
1:5ffad9f24d63 | 271 | MQTT subscribes to $aws/things/Nuvoton-Mbed-D001/shadow/delete/accepted OK |
ccli8 |
1:5ffad9f24d63 | 272 | MQTT subscribes to $aws/things/Nuvoton-Mbed-D001/shadow/delete/rejected OK |
ccli8 |
1:5ffad9f24d63 | 273 | Message to publish: |
ccli8 |
1:5ffad9f24d63 | 274 | |
ccli8 |
1:5ffad9f24d63 | 275 | MQTT publishes message to $aws/things/Nuvoton-Mbed-D001/shadow/delete OK |
ccli8 |
1:5ffad9f24d63 | 276 | Message arrived: qos 1, retained 0, dup 0, packetid 1 |
ccli8 |
1:5ffad9f24d63 | 277 | Payload: |
ccli8 |
1:5ffad9f24d63 | 278 | {"version":77,"timestamp":1514962202} |
ccli8 |
1:5ffad9f24d63 | 279 | |
ccli8 |
1:5ffad9f24d63 | 280 | MQTT unsubscribes from $aws/things/Nuvoton-Mbed-D001/shadow/delete/accepted OK |
ccli8 |
1:5ffad9f24d63 | 281 | MQTT unsubscribes from $aws/things/Nuvoton-Mbed-D001/shadow/delete/rejected OK |
ccli8 |
1:5ffad9f24d63 | 282 | Subscribes/publishes DeleteThingShadow topic OK |
ccli8 |
1:5ffad9f24d63 | 283 | |
ccli8 |
1:5ffad9f24d63 | 284 | MQTT disconnects OK |
ccli8 |
1:5ffad9f24d63 | 285 | </pre> |
ccli8 |
1:5ffad9f24d63 | 286 | |
ccli8 |
1:5ffad9f24d63 | 287 | Dynamic memory footprint (heap) is output below. |
ccli8 |
1:5ffad9f24d63 | 288 | Static memory footprint (global/stack) could be obtained by inspecting MAP file. |
ccli8 |
1:5ffad9f24d63 | 289 | You could get total memory footprint by adding these two together. |
ccli8 |
1:5ffad9f24d63 | 290 | <pre> |
ccli8 |
1:5ffad9f24d63 | 291 | Current heap size: 1351 |
ccli8 |
1:5ffad9f24d63 | 292 | Max heap size: 63022 |
ccli8 |
1:5ffad9f24d63 | 293 | </pre> |
ccli8 |
5:2a70e217325f | 294 | |
ccli8 |
5:2a70e217325f | 295 | ## Trouble-shooting |
ccli8 |
5:2a70e217325f | 296 | - Over ESP8266 WiFi, |
ccli8 |
5:2a70e217325f | 297 | if you make a loop test like below (`main.cpp`), you may always meet errors in the following loops |
ccli8 |
5:2a70e217325f | 298 | after some network error has happened in the previous one. |
ccli8 |
5:2a70e217325f | 299 | <pre> |
ccli8 |
5:2a70e217325f | 300 | <b>while (true) {</b> |
ccli8 |
5:2a70e217325f | 301 | #if AWS_IOT_MQTT_TEST |
ccli8 |
5:2a70e217325f | 302 | AWS_IoT_MQTT_Test *mqtt_test = new AWS_IoT_MQTT_Test(AWS_IOT_MQTT_SERVER_NAME, AWS_IOT_MQTT_SERVER_PORT, network); |
ccli8 |
5:2a70e217325f | 303 | mqtt_test->start_test(); |
ccli8 |
5:2a70e217325f | 304 | delete mqtt_test; |
ccli8 |
5:2a70e217325f | 305 | #endif // End of AWS_IOT_MQTT_TEST |
ccli8 |
5:2a70e217325f | 306 | |
ccli8 |
5:2a70e217325f | 307 | #if AWS_IOT_HTTPS_TEST |
ccli8 |
5:2a70e217325f | 308 | AWS_IoT_HTTPS_Test *https_test = new AWS_IoT_HTTPS_Test(AWS_IOT_HTTPS_SERVER_NAME, AWS_IOT_HTTPS_SERVER_PORT, network); |
ccli8 |
5:2a70e217325f | 309 | https_test->start_test(); |
ccli8 |
5:2a70e217325f | 310 | delete https_test; |
ccli8 |
5:2a70e217325f | 311 | #endif // End of AWS_IOT_HTTPS_TEST |
ccli8 |
5:2a70e217325f | 312 | <b>}</b> |
ccli8 |
5:2a70e217325f | 313 | </pre> |
ccli8 |
5:2a70e217325f | 314 | This issue would be caused by failure of ESP8266 AT commands **CLOSE**/**DISCONNECT** |
ccli8 |
5:2a70e217325f | 315 | because ESP8266 F/W is still busy in handling previous unfinished network transfer |
ccli8 |
5:2a70e217325f | 316 | due to bad network status and fails these commands. |
ccli8 |
5:2a70e217325f | 317 | These commands must be OK for ESP8266 F/W to reset connection state correctly. |
ccli8 |
5:2a70e217325f | 318 | If that happens, try enlarging [ESP8266 driver's](https://github.com/ARMmbed/esp8266-driver) timeout configuration. |
ccli8 |
6:7ef096085ca7 | 319 | For example, enlarge `ESP8266_SEND_TIMEOUT`/`ESP8266_RECV_TIMEOUT`/`ESP8266_MISC_TIMEOUT` (defined in |
ccli8 |
6:7ef096085ca7 | 320 | [ESP8266Interface.cpp](https://github.com/ARMmbed/esp8266-driver/blob/master/ESP8266Interface.cpp)) |
ccli8 |
6:7ef096085ca7 | 321 | to 5000/5000/5000 ms respectively (through `mbed_app.json`). |
ccli8 |
5:2a70e217325f | 322 | <pre> |
ccli8 |
5:2a70e217325f | 323 | { |
ccli8 |
5:2a70e217325f | 324 | "macros": [ |
ccli8 |
5:2a70e217325f | 325 | "MBED_CONF_APP_MAIN_STACK_SIZE=4096", |
ccli8 |
5:2a70e217325f | 326 | "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_user_config.h\"", |
ccli8 |
5:2a70e217325f | 327 | "MBED_HEAP_STATS_ENABLED=1", |
ccli8 |
5:2a70e217325f | 328 | "MBED_MEM_TRACING_ENABLED=1", |
ccli8 |
6:7ef096085ca7 | 329 | <b>"ESP8266_SEND_TIMEOUT=5000",</b> |
ccli8 |
6:7ef096085ca7 | 330 | <b>"ESP8266_RECV_TIMEOUT=5000",</b> |
ccli8 |
5:2a70e217325f | 331 | <b>"ESP8266_MISC_TIMEOUT=5000"</b> |
ccli8 |
5:2a70e217325f | 332 | ], |
ccli8 |
5:2a70e217325f | 333 | "config": { |
ccli8 |
5:2a70e217325f | 334 | </pre> |