Ex1. ⑤ SENSOR DATA PUBLISH
( 태그 : AWS_IoT_FreeRTOS, AWS_IoT )
1. Enable Sensor Function
STM32 MCU 보드에 내장된 Sensor 데이터를 수집하여 MQTT 메시지로 Publish 하는 기능을 활성화 시킵니다.
Sensor Data Read Function
- Drivers/BSP/B-L475E-IOT01
- Drivers/BSP/Components/vl5310x
Sensor Data Collector
- Applications/Cloud/aws_demos/Src/
- st_sensordata_collector.c, st_statusled_update.c
Sensor Data Publish
- Applications/UCloud/aws_demos/Src/
- aws_customdemo_runner.c, aws_customerdemo_publish.c, aws_customdemo_main.c
Custom Demo Enable
- Sensor Data를 Publish 하는 기능을 활성화 합니다.
- Applications/Cloud/aws_demos/Inc/main.h
- CONFIG_ST_CUSTOM_DEMO_ENABLED를 define 합니다.
2. Project Build & Programming
- B-L4S5I-IOT01_aws_demos 프로젝트를 재 build한 후 생성된 binary image를 STM32 MCU 보드에 programming 합니다.
- Terminal 로그에서 Sensor Data를 MQTT로 Publish 하는 것을 확인할 수 있습니다.
- Topic : dt/stm32l475e/sensor-data/topic
- Message : {“Board_id”:“st-discovery-board-01”,“Temp”: 31, “Hum”: 45, “Press”: 1006, “Accel_X”: 5, “Accel_Y”: -16, “Accel_Z”: 1031, “Gyro_X”: -280, “Gyro_Y”: -2170, “Gyro_Z”: 770, “Magn_X”: -225, “Magn_Y”: -1045, “Magn_Z”: -575, “Proxi”: 7}
8 20860 [iot_thread] [INFO ][DEMO][20860] ---------STARTING DEMO---------
9 20867 [iot_thread] [INFO ][INIT][20867] SDK successfully initialized.
...10 27328 [iot_thread] [INFO ][DEMO][27328] Successfully initialized the demo. Network type for the demo: 1
11 27338 [iot_thread] [INFO ][ST-L475E-MAIN][27338] ENTRY: aws_custom_demo_main with awsIotMqttMode: 1
12 27347 [iot_thread] ENTRY: aws_custom_mqttlib_initialise
13 27353 [iot_thread] [INFO ][MQTT][27352] MQTT library successfully initialized.
14 27360 [iot_thread] [INFO ][ST-L475E-MAIN][27360] MQTT demo client identifier is Iot-stm-sensor-nodeA (length 20).
..15 31961 [iot_thread] [INFO ][MQTT][31961] Establishing new MQTT connection.
16 31969 [iot_thread] [INFO ][MQTT][31969] Anonymous metrics (SDK language, SDK version) will be provided to AWS IoT. Recompile with AWS_IOT_MQTT_ENABLE_METRICS set to 0 to disable.
17 31987 [iot_thread] [INFO ][MQTT][31987] (MQTT connection 0x20045250, CONNECT operation 0x200453d8) Waiting for operation completion.
.18 32080 [iot_thread] [INFO ][MQTT][32079] (MQTT connection 0x20045250, CONNECT operation 0x200453d8) Wait complete with result SUCCESS.
19 32092 [iot_thread] [INFO ][MQTT][32092] New MQTT connection 0x20043988 established.
20 32100 [iot_thread] [INFO ][ST-L475E-MAIN][32100] MQTT-CUST_INIT:MQTT Initialisation successful
21 32109 [iot_thread] [INFO ][ST-L475E-MAIN][32109] MQTT-CUST_INIT:MQTT Initialising Shadow Service
22 32118 [iot_thread] [INFO ][Shadow][32118] Shadow library successfully initialized.
23 32126 [iot_thread] [INFO ][Shadow][32126] (Iot-stm-sensor-nodeA) Modifying Shadow DELTA callback.
24 32136 [iot_thread] [INFO ][Shadow][32136] (Iot-stm-sensor-nodeA) Adding new DELTA callback.
25 32145 [iot_thread] [INFO ][MQTT][32145] (MQTT connection 0x20045250) SUBSCRIBE operation scheduled.
26 32154 [iot_thread] [INFO ][MQTT][32154] (MQTT connection 0x20045250, SUBSCRIBE operation 0x20045cf0) Waiting for operation completion.
27 32217 [iot_thread] [INFO ][MQTT][32217] (MQTT connection 0x20045250, SUBSCRIBE operation 0x20045cf0) Wait complete with result SUCCESS.
28 32230 [iot_thread] [INFO ][Shadow][32230] (Iot-stm-sensor-nodeA) Shadow DELTA callback operation complete with result SUCCESS.
29 32242 [iot_thread] [INFO ][Shadow][32242] (Iot-stm-sensor-nodeA) Modifying Shadow UPDATED callback.
30 32251 [iot_thread] [INFO ][Shadow][32251] (Iot-stm-sensor-nodeA) Adding new UPDATED callback.
31 32261 [iot_thread] [INFO ][MQTT][32260] (MQTT connection 0x20045250) SUBSCRIBE operation scheduled.
32 32270 [iot_thread] [INFO ][MQTT][32270] (MQTT connection 0x20045250, SUBSCRIBE operation 0x20045cf0) Waiting for operation completion.
33 32336 [iot_thread] [INFO ][MQTT][32336] (MQTT connection 0x20045250, SUBSCRIBE operation 0x20045cf0) Wait complete with result SUCCESS.
34 32349 [iot_thread] [INFO ][Shadow][32349] (Iot-stm-sensor-nodeA) Shadow UPDATED callback operation complete with result SUCCESS.
35 32361 [iot_thread] [INFO ][ST-L475E-MAIN][32361] MQTT-CUST_INIT:MQTT-SHADOW Initialisation Successful
36 32371 [iot_thread] EXIT: aws_custom_mqttlib_initialise with status:[0]
37 32378 [iot_thread] [INFO ][ST-L475E-MAIN][32378] AWS Custom Demo Initialization is Successful
38 32386 [iot_thread] [INFO ][ST-L475E-MAIN][32386] xSensor Data Queue is created
39 32395 [iot_thread] [INFO ][ST-L475E-MAIN][32395] ENTRY : _sensorDataPublisherTask
40 32403 [iot_thread] [INFO ][ST-L475E-MAIN][32403] ENTRY : onboardSensorReaderTask
.41 35768 [iot_thread] [INFO ][ST-L475E-MAIN][35768] Accelerometer [X: 537209596]
42 35776 [iot_thread] [INFO ][ST-L475E-MAIN][35775] Publishing sensor data as json string: {"Board_id":"st-discovery-board-01","Temp": 31, "Hum": 45, "Press": 1006, "Accel_X": 5, "Accel_Y": -16, "Accel_Z": 1031, "Gyro_X": -280, "Gyro_Y": -2170, "Gyro_Z": 770, "Magn_X": -225, "Magn_Y": -1045, "Magn_Z": -575, "Proxi": 7} of length [ 229]
43 35806 [iot_thread] [INFO ][ST-L475E-MAIN][35806] ENTRY: sendToTelemetryQueue:
44 35814 [iot_thread] [INFO ][ST-L475E-MAIN][35813] Sending data as json string to Telemetry Queue:[ {"Board_id":"st-discovery-board-01","Temp": 31, "Hum": 45, "Press": 1006, "Accel_X": 5, "Accel_Y": -16, "Accel_Z": 1031, "Gyro_X": -280, "Gyro_Y": -2170, "Gyro_Z": 770, "Magn_X": -225, "Magn_Y": -1045, "Magn_Z": -575, "Proxi": 7} ]
45 35843 [iot_thread] [INFO ][ST-L475E-MAIN][35843] EXIT: sendToTelemetryQueue: [ {"Board_id":"st-discovery-board-01","Temp": 31, "Hum": 45, "Press": 1006, "Accel_X": 5, "Accel_Y": -16, "Accel_Z": 1031, "Gyro_X": -280, "Gyro_Y": -2170, "Gyro_Z": 770, "Magn_X": -225, "Magn_Y": -1045, "Magn_Z": -575, "Proxi": 7} ]
46 35871 [iot_thread] [INFO ][ST-L475E-MAIN][35871]
Received Message ,:[ {"Board_id":"st-discovery-board-01","Temp": 31, "Hum": 45, "Press": 1006, "Accel_X": 5, "Accel_Y": -16, "Accel_Z": 1031, "Gyro_X": -280, "Gyro_Y": -2170, "Gyro_Z": 770, "Magn_X": -225, "Magn_Y": -1045, "Magn_Z": -575, "Proxi": 7} ] of length [ 229]
47 35900 [iot_thread] [INFO ][ST-L475E-MAIN][35900] ENTRY:_publishSensorData
48 35909 [iot_thread] [INFO ][MQTT][35909] (MQTT connection 0x20045250) MQTT PUBLISH operation queued.
49 35919 [iot_thread] [INFO ][ST-L475E-MAIN][35919] Message submitted for publish successfully
50 35927 [iot_thread] [INFO ][ST-L475E-MAIN][35927] EXIT :_publishSensorData with status :[1]
51 35936 [iot_thread] [INFO ][ST-L475E-MAIN][35936] Publish Status: 1
3. Check MQTT Message
- AWS IoT 콘솔에서 MQTT message 수신을 확인합니다.
- Test 메뉴를 선택한 후 MQTT client의 subscriptions을 구성합니다.
- Topic을 입력합니다. : dt/stm32l475e/sensor-data/topic
- Subscribe to topic 버튼을 클릭합니다.
- Sensor data가 수신되는 것을 확인할 수 있습니다.
Credits
Korean version
Jongwoo Lee (rainny@)
Sejun Kim (sejun@)
Albert Lee (sehyul@)
Original Contents Author
Vanitha Ramaswami (rvanitha@)
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
메이커스페이스 G·캠프에서 만든 콘텐츠가 아니며, 서울하드웨어해커톤에서 강의가 진행될 예정입니다.
'05_Toolkit > AWS_IoT' 카테고리의 다른 글
Ex2. ① SENSOR DASHBOARD (0) | 2020.11.26 |
---|---|
Ex2. ADDING TEMPERATURE & LED CONTROL (0) | 2020.11.26 |
Ex1. ④ AWS IOT CORE 연결 (0) | 2020.11.26 |
Ex1. ③ AWS IOT APPLICATION (0) | 2020.11.26 |
Ex1. ② STM SECURE BOOT (0) | 2020.11.26 |