Azure-Samples / iot-middleware-freertos-samples

This repo has samples for dev kits using the Azure IoT middleware for FreeRTOS
MIT License
76 stars 46 forks source link

Azure IoT Middleware for Freertos - Failed to establish MQTT connection, error 0x00000006 #393

Closed leoleez closed 5 months ago

leoleez commented 7 months ago

I used IoT Middleware for Freertos code to run on ESP32S3, esp-idf is version 4.4, azure IoT certificates and so on follow the tutorial configuration. Azure configuration tutorial link is: https://learn.microsoft.com/en-us/azure/iot-develop/quickstart-devkit-espressif-esp32-freertos. Run logs are as follows:

I (29) boot: ESP-IDF v4.4.6-98-g5f257494c5-dirty 2nd stage bootloader I (29) boot: compile time 11:05:17 I (29) boot: Multicore bootloader I (33) boot: chip revision: v0.2 I (37) boot.esp32s3: Boot SPI Speed : 80MHz I (42) boot.esp32s3: SPI Mode : DIO I (46) boot.esp32s3: SPI Flash Size : 2MB I (51) boot: Enabling RNG early entropy source... I (57) boot: Partition Table: I (60) boot: ## Label Usage Type ST Offset Length I (67) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (75) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (82) boot: 2 factory factory app 00 00 00010000 00100000 I (90) boot: End of partition table I (94) esp_image: segment 0: paddr=00010020 vaddr=3c0a0020 size=232c4h (144068) map I (128) esp_image: segment 1: paddr=000332ec vaddr=3fc96ec0 size=03cb4h ( 15540) load I (132) esp_image: segment 2: paddr=00036fa8 vaddr=40374000 size=09070h ( 36976) load I (142) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=95788h (612232) map I (252) esp_image: segment 4: paddr=000d57b0 vaddr=4037d070 size=09e48h ( 40520) load I (269) boot: Loaded app from partition at offset 0x10000 I (269) boot: Disabling RNG early entropy source... I (280) cpu_start: Multicore app I (281) cpu_start: Pro cpu up. I (281) cpu_start: Starting app cpu, entry point is 0x403752f4 0x403752f4: call_start_cpu1 at /home/leo/esp32-s3/esp-idf/components/esp_system/port/cpu_start.c:151

I (262) cpu_start: App cpu up. I (299) cpu_start: Pro cpu start user code I (299) cpu_start: cpu freq: 160000000 I (299) cpu_start: Application information: I (302) cpu_start: Project name: azure_iot_freertos_esp32 I (308) cpu_start: App version: f06e8c7-dirty I (313) cpu_start: Compile time: Apr 18 2024 15:54:28 I (319) cpu_start: ELF file SHA256: 5b5688da8660745c... I (325) cpu_start: ESP-IDF: v4.4.6-98-g5f257494c5-dirty I (332) cpu_start: Min chip rev: v0.0 I (337) cpu_start: Max chip rev: v0.99 I (342) cpu_start: Chip rev: v0.2 I (346) heap_init: Initializing. RAM available for dynamic allocation: I (354) heap_init: At 3FCA0DD8 len 00048938 (290 KiB): D/IRAM I (360) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DIRAM I (367) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM I (373) heap_init: At 600FE000 len 00002000 (8 KiB): RTCRAM I (380) spi_flash: detected chip: gd I (384) spi_flash: flash io: dio W (388) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header. I (401) sleep: Configure to isolate all GPIO pins in sleep state I (408) sleep: Enable automatic switching of GPIO sleep configuration I (415) cpu_start: Starting scheduler on PRO CPU. I (0) cpu_start: Starting scheduler on APP CPU. I (560) pp: pp rom version: e7ae62f I (560) net80211: net80211 rom version: e7ae62f I (570) wifi:wifi driver task: 3fcee8cc, prio:23, stack:6656, core=0 I (570) system_api: Base MAC address is not set I (570) system_api: read default base MAC address from EFUSE I (570) wifi:wifi firmware version: d9959e6 I (580) wifi:wifi certification version: v7.0 I (580) wifi:config NVS flash: enabled I (580) wifi:config nano formating: disabled I (590) wifi:Init data frame dynamic rx buffer num: 32 I (590) wifi:Init management frame dynamic rx buffer num: 32 I (600) wifi:Init management short buffer num: 32 I (600) wifi:Init dynamic tx buffer num: 32 I (610) wifi:Init static tx FG buffer num: 2 I (610) wifi:Init static rx buffer size: 1600 I (610) wifi:Init static rx buffer num: 10 I (620) wifi:Init dynamic rx buffer num: 32 I (620) wifi_init: rx ba win: 6 I (630) wifi_init: tcpip mbox: 32 I (630) wifi_init: udp mbox: 6 I (630) wifi_init: tcp mbox: 6 I (640) wifi_init: tcp tx win: 5744 I (640) wifi_init: tcp rx win: 5744 I (650) wifi_init: tcp mss: 1440 I (650) wifi_init: WiFi IRAM OP enabled I (650) wifi_init: WiFi RX IRAM OP enabled I (660) sample_azureiotkit: Connecting to SugrVPN_4002... I (670) phy_init: phy_version 610,2bff4c8,Jul 27 2023,20:22:14 I (730) wifi:mode : sta (dc:da:0c:4a:07:9c) I (730) wifi:enable tsf I (730) sample_azureiotkit: Waiting for IP(s) I (3140) wifi:new:<6,2>, old:<1,0>, ap:<255,255>, sta:<6,2>, prof:1 I (4170) wifi:state: init -> auth (b0) I (4180) wifi:state: auth -> assoc (0) I (4210) wifi:state: assoc -> run (10) I (4330) wifi:connected with SugrVPN_4002, aid = 3, channel 6, 40D, bssid = 54:75:95:e1:79:76 I (4330) wifi:security: WPA2-PSK, phy: bgn, rssi: -61 I (4330) wifi:pm start, type: 1

I (4330) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000 I (4390) wifi:AP's beacon interval = 102400 us, DTIM period = 1 I (5340) esp_netif_handlers: sample_azureiotkit: sta ip: 192.168.3.132, mask: 255.255.255.0, gw: 192.168.3.1 I (5340) sample_azureiotkit: Got IPv4 event: Interface "sample_azureiotkit: sta" address: 192.168.3.132 I (5350) sample_azureiotkit: Connected to sample_azureiotkit: sta I (5350) sample_azureiotkit: - IPv4 address: 192.168.3.132 I (5360) sample_azureiotkit: Waiting for time synchronization with SNTP server I (8270) wifi:idx:0 (ifx:0, 54:75:95:e1:79:76), tid:0, ssn:233, winSize:64 I (8320) sample_azureiotkit: Notification of a time synchronization event I (8370) AZ IOT: Creating a TLS connection to global.azure-devices-provisioning.net:8883.

I (10840) esp_tls: (Network connection 0x3fca5e90) Connection to global.azure-devices-provisioning.net established. I (10900) MQTT: Incoming packet: Packet type=32. I (10900) MQTT: Packet received. ReceivedBytes=2. I (10900) MQTT: MQTT_PACKET_CONNACK Session Present:0, CONNACK response code: 0. I (10910) MQTT: CONNACK session present bit not set. I (10920) MQTT: Connection accepted. I (10920) MQTT: Received MQTT CONNACK successfully from broker. I (10930) MQTT: MQTT connection established with the broker. I (10930) AZ IOT: AzureIoTProvisioning established an MQTT connection with global.azure-devices-provisioning.net I (12960) AZ IOT: AzureIoTProvisioning attempting to subscribe to the MQTT topic: devices/+/messages/devicebound/# I (13000) MQTT: Incoming packet: Packet type=144. I (13000) MQTT: Packet received. ReceivedBytes=3. I (15580) MQTT: Incoming packet: Packet type=48. I (15580) MQTT: Packet received. ReceivedBytes=144. I (15580) MQTT: De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess. I (15590) MQTT: State record updated. New state=MQTTPublishDone. I (15600) AZ IOT: $dps/registrations/res/202/?$rid=1&retry-after=3 I (15600) AZ IOT: {"operationId":"5.71cf7e385566aa10.4469ed4c-dc19-4af8-8b36-9ef6396ac1b3","status":"assigning"} I (22150) MQTT: Incoming packet: Packet type=48. I (22150) MQTT: Packet received. ReceivedBytes=547. I (22150) MQTT: De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess. I (22170) MQTT: State record updated. New state=MQTTPublishDone. I (22170) AZ IOT: $dps/registrations/res/200/?$rid=1 I (22180) AZ IOT: {"operationId":"5.71cf7e385566aa10.4469ed4c-dc19-4af8-8b36-9ef6396ac1b3","status":"assigned","registrationState":{"x509":{},"registrationId":"aa7bf6eb-f0fd-4da2-ab47-5106b37e6f97","createdDateTimeUtc":"2024-04-18T09:29:32.2935213Z","assignedHub":"lvz-iot-preprod-neu-iot.azure-devices.net","deviceId":"aa7bf6eb-f0fd-4da2-ab47-5106b37e6f97","status":"assigned","substatus":"initialAssignment","lastUpdatedDateTimeUtc":"2024-04-18T09:29:32.5748143Z","etag":"IjA4MDA3ZjFjLTAwMDAtMGMwMC0wMDAwLTY2MjBlN2ZjMDAwMCI="}} I (22220) AZ IOT: Successfully acquired IoT Hub name and Device ID3 I (22240) AZ IOT: Creating a TLS connection to lvz-iot-preprod-neu-iot.azure-devices.net:8883.

I (25530) esp_tls: (Network connection 0x3fca5f10) Connection to lvz-iot-preprod-neu-iot.azure-devices.net established. I (25530) AZ IOT: Creating an MQTT connection to lvz-iot-preprod-neu-iot.azure-devices.net.

I (25540) AZ IOT: pucIotHubDeviceId connection to aa7bf6eb-f0fd-4da2-ab47-5106b37e6f97.

I (25560) AZ IOT: An MQTT connection is pucDeviceID with aa7bf6eb-f0fd-4da2-ab47-5106b37e6f97 I (25930) MQTT: Incoming packet: Packet type=32. I (25930) MQTT: Packet received. ReceivedBytes=2. I (25930) MQTT: MQTT_PACKET_CONNACK Session Present:0, CONNACK response code: 5. I (25930) MQTT: CONNACK session present bit not set. E (25940) MQTT: Connection refused: not authorized. E (25940) MQTT: CONNACK recv failed with status = MQTTServerRefused. E (25960) MQTT: MQTT connection failed with status = MQTTServerRefused. E (25960) AZ IOT: Failed to establish MQTT connection: Server=lvz-iot-preprod-neu-iot.azure-devices.net, MQTT error=0x00000006

I have changed the certificate test, but I don't know what to do next, can you help me solve the problem.