MCUXpresso_LPC55S69/boards/lpcxpresso55s69/aws_examples/shadow_wifi_serial/cm33_core0/readme.txt

277 lines
12 KiB
Plaintext

Overview
========
The simple Shadow lightbulb example to illustrate how client application and things communicate with the Shadow service.
Toolchain supported
===================
- IAR embedded Workbench 9.20.2
- GCC ARM Embedded 10.3.1
- Keil MDK 5.36
- MCUXpresso 11.5.0
Hardware requirements
=====================
- Mini/micro USB cable
- LPCXpresso55s69 board
- Personal Computer
- Murata CMWC1ZZABR-107-EVB
Board settings
==============
Plug the WiFi module to mikroBUS (P23, P24).
Prepare the Demo
================
Before running the demo it is need to configure AWS IoT Console and update some of project files:
1. Create AWS Account: https://console.aws.amazon.com/console/home
2. Configure device in the AWS IoT Console base on this guide: https://docs.aws.amazon.com/iot/latest/developerguide/iot-sdk-setup.html
Make note of example's "Thing name" and "REST API endpoint". These strings need to be set in the "aws_clientcredential.h".
Example:
static const char clientcredentialMQTT_BROKER_ENDPOINT[] = "abcdefgh123456.iot.us-west-2.amazonaws.com";
#define clientcredentialIOT_THING_NAME "MyExample"
In the next step you will get the "device certificate" and the "primary key". The device certificate and private key needs to be opened in text editor and its content copied into the "aws_clientcredential_keys.h".
Or you can use the CertificateConfigurator.html (mcu-sdk-2.0\rtos\freertos\tools\certificate_configuration) to generate the "aws_clientcredential_keys.h".
Example:
#define keyCLIENT_CERTIFICATE_PEM "Paste client certificate here."
Needs to be changed to:
#define keyCLIENT_CERTIFICATE_PEM "-----BEGIN CERTIFICATE-----\n"\
"MIIDWTCCAkGgAwIBAgIUfmv3zA+JULlMOxmz+upkAzhEkQ0wDQYJKoZIhvcNAQEL\n"\
.
.
.
"mepuT3lKmD0jZupsQ9vLQOA09rMjVMd0YPmI9ozvvWqLpjVvNTKVhsf/3slM\n"\
"-----END CERTIFICATE-----\n"
In the same way update the private key array.
3. Open example's project and build it.
4. Connect a USB cable between the PC host and the OpenSDA port on the target board.
5. Download the program to the target board with the CMSIS-DAP or J-Link debugger.
6. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.
7. Open a serial terminal on PC for serial device with these settings:
- 115200 baud rate
- 8 data bits
- No parity
- One stop bit
- No flow control
8. During the runtime will be necessary to configure Wi-Fi module. Follow instructions in the terminal for Wi-Fi module configuration or resetting to provisioning mode.
If the module is in provisioning mode, it will create micro-AP:
SSID: Serial2Wifi
Passphrase: nxp12345
Connect your PC or mobile phone to this Wi-Fi micro-AP, open address: http://192.168.10.1 in web browser, select "Provisioning" and then select WLAN for connection.
Wi-Fi module stores the WLAN credentials and it will use them automatically for next connection.
Running the demo
================
The log below shows the output of the demo in the terminal window. The log can be different based on your Wi-Fi network configuration.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 221 [Tmr Svc] Write certificate...
1 453 [iot_thread] [INFO ][DEMO][451] ---------STARTING DEMO---------
2 458 [iot_thread] [INFO ][INIT][458] SDK successfully initialized.
Wi-Fi is connecting...
Wi-Fi is connecting...
Wi-Fi is connecting...
Wi-Fi is connected to: nxp, IP Address: 192.168.199.197
To reset Wi-Fi module to provisioning mode connect to WLAN: nxp, open address: http://192.168.199.197 in web browser and select "Reset to Provisioning".
Then restart this application.
3 16801 [iot_thread] [INFO ][DEMO][16801] Successfully initialized the demo. Network type for the demo: 1
4 16804 [iot_thread] [INFO] Create a TCP connection to a2zcot8a2tqh6c-ats.iot.us-east-2.amazonaws.com:8883.
5 28209 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
6 28210 [iot_thread] [INFO] CONNACK session present bit not set.
7 28212 [iot_thread] [INFO] Connection accepted.
8 28214 [iot_thread] [INFO] Received MQTT CONNACK successfully from broker.
9 28216 [iot_thread] [INFO] MQTT connection established with the broker.
10 28218 [iot_thread] [INFO] MQTT connection successfully established with broker.
11 28220 [iot_thread] [INFO] A clean MQTT connection is established. Cleaning up all the stored outgoing publishes.
12 28247 [iot_thread] [INFO] SUBSCRIBE topic $aws/things/aws_demo/shadow/delete/accepted to broker.
13 28509 [iot_thread] [INFO] Packet received. ReceivedBytes=3.
14 28510 [iot_thread] [INFO] MQTT_PACKET_TYPE_SUBACK.
15 30420 [iot_thread] [INFO] SUBSCRIBE topic $aws/things/aws_demo/shadow/delete/rejected to broker.
16 30736 [iot_thread] [INFO] Packet received. ReceivedBytes=3.
17 30737 [iot_thread] [INFO] MQTT_PACKET_TYPE_SUBACK.
18 32629 [iot_thread] [INFO] the published payload:
19 32651 [iot_thread] [INFO] PUBLISH sent for topic $aws/things/aws_demo/shadow/delete to broker with packet ID 3.
20 32887 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
21 32890 [iot_thread] [INFO] Ack packet deserialized with result: MQTTSuccess.
22 32892 [iot_thread] [INFO] State record updated. New state=MQTTPublishDone.
23 32894 [iot_thread] [INFO] PUBACK received for packet id 3.
24 32896 [iot_thread] [INFO] Cleaned up outgoing publish packet with packet id 3.
25 33104 [iot_thread] [INFO] Packet received. ReceivedBytes=94.
26 33105 [iot_thread] [INFO] De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess.
27 33107 [iot_thread] [INFO] State record updated. New state=MQTTPubAckSend.
28 33109 [iot_thread] [INFO] pPublishInfo->pTopicName:$aws/things/aws_demo/shadow/delete/accepted.
29 33113 [iot_thread] [INFO] Received an MQTT incoming publish on /delete/accepted topic.
30 34827 [iot_thread] [INFO] UNSUBSCRIBE sent topic $aws/things/aws_demo/shadow/delete/accepted to broker.
31 35118 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
32 35121 [iot_thread] [INFO] MQTT_PACKET_TYPE_UNSUBACK.
33 37030 [iot_thread] [INFO] UNSUBSCRIBE sent topic $aws/things/aws_demo/shadow/delete/rejected to broker.
34 37298 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
35 37299 [iot_thread] [INFO] MQTT_PACKET_TYPE_UNSUBACK.
36 39208 [iot_thread] [INFO] SUBSCRIBE topic $aws/things/aws_demo/shadow/update/delta to broker.
37 39494 [iot_thread] [INFO] Packet received. ReceivedBytes=3.
38 39495 [iot_thread] [INFO] MQTT_PACKET_TYPE_SUBACK.
39 41406 [iot_thread] [INFO] SUBSCRIBE topic $aws/things/aws_demo/shadow/update/accepted to broker.
40 42128 [iot_thread] [INFO] Packet received. ReceivedBytes=3.
41 42129 [iot_thread] [INFO] MQTT_PACKET_TYPE_SUBACK.
42 43618 [iot_thread] [INFO] SUBSCRIBE topic $aws/things/aws_demo/shadow/update/rejected to broker.
43 43906 [iot_thread] [INFO] Packet received. ReceivedBytes=3.
44 43907 [iot_thread] [INFO] MQTT_PACKET_TYPE_SUBACK.
45 45798 [iot_thread] [INFO] Send desired power state with 1.
46 45801 [iot_thread] [INFO] the published payload:{"state":{"desired":{"powerOn":1}},"clientToken":"045799"}
47 45843 [iot_thread] [INFO] PUBLISH sent for topic $aws/things/aws_demo/shadow/update to broker with packet ID 9.
48 46107 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
49 46108 [iot_thread] [INFO] Ack packet deserialized with result: MQTTSuccess.
50 46110 [iot_thread] [INFO] State record updated. New state=MQTTPublishDone.
51 46112 [iot_thread] [INFO] PUBACK received for packet id 9.
52 46114 [iot_thread] [INFO] Cleaned up outgoing publish packet with packet id 9.
53 46328 [iot_thread] [INFO] Packet received. ReceivedBytes=184.
54 46329 [iot_thread] [INFO] De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess.
55 46331 [iot_thread] [INFO] State record updated. New state=MQTTPubAckSend.
56 46333 [iot_thread] [INFO] pPublishInfo->pTopicName:$aws/things/aws_demo/shadow/update/delta.
57 46335 [iot_thread] [INFO] /update/delta json payload:{"version":141,"timestamp":1623222009,"state":{"powerOn":1},"metadata":{"powerOn":{"timestamp":1623222009}},"clientToken":"045799"}.
58 46341 [iot_thread] [INFO] version: 141
59 46343 [iot_thread] [INFO] version:141, ulCurrentVersion:0
60 46347 [iot_thread] [INFO] The new power on state newState:1, ulCurrentPowerOnState:0
61 46425 [iot_thread] [INFO] Packet received. ReceivedBytes=211.
62 46426 [iot_thread] [INFO] De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess.
63 46428 [iot_thread] [INFO] State record updated. New state=MQTTPubAckSend.
64 46430 [iot_thread] [INFO] pPublishInfo->pTopicName:$aws/things/aws_demo/shadow/update/accepted.
65 46432 [iot_thread] [INFO] /update/accepted json payload:{"state":{"desired":{"powerOn":1}},"metadata":{"desired":{"powerOn":{"timestamp":1623222009}}},"version":141,"timestamp":1623222009,"clientToken":"045799"}.
66 46438 [iot_thread] [INFO] clientToken: 045799
67 46442 [iot_thread] [INFO] receivedToken:45799, clientToken:0
68 46444 [iot_thread] [WARN] The received clientToken=45799 is not identical with the one=0 we sent
69 47933 [iot_thread] [INFO] Report to the state change: 1
70 47934 [iot_thread] [INFO] the published payload:{"state":{"reported":{"powerOn":1}},"clientToken":"047934"}
71 47976 [iot_thread] [INFO] PUBLISH sent for topic $aws/things/aws_demo/shadow/update to broker with packet ID 10.
72 48307 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
73 48308 [iot_thread] [INFO] Ack packet deserialized with result: MQTTSuccess.
74 48312 [iot_thread] [INFO] State record updated. New state=MQTTPublishDone.
75 48314 [iot_thread] [INFO] PUBACK received for packet id 10.
76 48316 [iot_thread] [INFO] Cleaned up outgoing publish packet with packet id 10.
77 48557 [iot_thread] [INFO] Packet received. ReceivedBytes=213.
78 48560 [iot_thread] [INFO] De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess.
79 48562 [iot_thread] [INFO] State record updated. New state=MQTTPubAckSend.
80 48564 [iot_thread] [INFO] pPublishInfo->pTopicName:$aws/things/aws_demo/shadow/update/accepted.
81 48566 [iot_thread] [INFO] /update/accepted json payload:{"state":{"reported":{"powerOn":1}},"metadata":{"reported":{"powerOn":{"timestamp":1623222012}}},"version":142,"timestamp":1623222012,"clientToken":"047934"}.
82 48572 [iot_thread] [INFO] clientToken: 047934
83 48576 [iot_thread] [INFO] receivedToken:47934, clientToken:47934
84 48578 [iot_thread] [INFO] Received response from the device shadow. Previously published update with clientToken=47934 has been accepted.
85 50065 [iot_thread] [INFO] Start to unsubscribe shadow topics and disconnect from MQTT.
86 50089 [iot_thread] [INFO] UNSUBSCRIBE sent topic $aws/things/aws_demo/shadow/update/delta to broker.
87 50398 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
88 50399 [iot_thread] [INFO] MQTT_PACKET_TYPE_UNSUBACK.
89 52309 [iot_thread] [INFO] UNSUBSCRIBE sent topic $aws/things/aws_demo/shadow/update/accepted to broker.
90 52584 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
91 52587 [iot_thread] [INFO] MQTT_PACKET_TYPE_UNSUBACK.
92 54496 [iot_thread] [INFO] UNSUBSCRIBE sent topic $aws/things/aws_demo/shadow/update/rejected to broker.
93 54818 [iot_thread] [INFO] Packet received. ReceivedBytes=2.
94 54819 [iot_thread] [INFO] MQTT_PACKET_TYPE_UNSUBACK.
95 56513 [iot_thread] [INFO] Disconnected from the broker.
96 56535 [iot_thread] [INFO] Demo iteration 1 is successful.
97 56538 [iot_thread] [INFO ][DEMO][56536] memory_metrics::freertos_heap::before::bytes::79216
98 56540 [iot_thread] [INFO ][DEMO][56540] memory_metrics::freertos_heap::after::bytes::29704
99 56544 [iot_thread] [INFO ][DEMO][56544] memory_metrics::demo_task_stack::before::bytes::5336
100 56548 [iot_thread] [INFO ][DEMO][56548] memory_metrics::demo_task_stack::after::bytes::3320
101 57550 [iot_thread] [INFO ][DEMO][57550] Demo completed successfully.
102 57556 [iot_thread] [INFO ][INIT][57556] SDK cleanup done.
103 57560 [iot_thread] [INFO ][DEMO][57558] -------DEMO FINISHED-------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~