espressif / esp-aws-iot

AWS IoT SDK for ESP32 based chipsets
Apache License 2.0
257 stars 154 forks source link

Multiple connections to AWS IoT (CA-216) #118

Open AlvaroModuly opened 2 years ago

AlvaroModuly commented 2 years ago

Hi, I'm trying to connect two ESP32 to the same IoT Thing but on different topics. When I connect just one there is no problem with the connection or the messages, but when both ESP32 are connected both crash after publishing 2 times in their corresponded topics and restart. I think the problem shouldn't be in the code or certificates since the code is able to run we there is just one ESP32. Does anyone have tried to connect several ESP32 via MQTT to the same IoT Thing in AWS?

Here is the message that I'm getting in the terminal:

I (0) cpu_start: App cpu up. I (469) cpu_start: Pro cpu start user code I (469) cpu_start: cpu freq: 160000000 I (469) cpu_start: Application information: I (473) cpu_start: Project name: mqtt_websocket_secure I (479) cpu_start: App version: fa89e55-dirty I (485) cpu_start: Compile time: Apr 13 2022 15:14:42 I (491) cpu_start: ELF file SHA256: 5a071dbad022c99b... I (497) cpu_start: ESP-IDF: v4.4-dirty I (502) heap_init: Initializing. RAM available for dynamic allocation: I (509) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (515) heap_init: At 3FFB7988 len 00028678 (161 KiB): DRAM I (522) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM I (528) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (535) heap_init: At 40095754 len 0000A8AC (42 KiB): IRAM I (542) spi_flash: detected chip: generic I (545) spi_flash: flash io: dio I (551) cpu_start: Starting scheduler on PRO CPU. I (0) cpu_start: Starting scheduler on APP CPU. I (624) wifi_manager: Set STA IP String to: 0.0.0.0 I (634) TX_TASK: Wrote 1 bytes: '3' I (624) subpub: AWS IoT SDK Version 3.0.1- I (644) system_api: Base MAC address is not set I (644) system_api: read default base MAC address from EFUSE I (654) wifi_init: rx ba win: 6 I (654) wifi_init: tcpip mbox: 32 I (654) wifi_init: udp mbox: 6 I (654) wifi_init: tcp mbox: 6 I (654) wifi_init: tcp tx win: 5744 I (664) wifi_init: tcp rx win: 5744 I (664) wifi_init: tcp mss: 1440 I (674) wifi_init: WiFi IRAM OP enabled I (674) wifi_init: WiFi RX IRAM OP enabled I (1434) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07 I (1544) wifi_manager: I (1544) http_server: Registering URI handlers I (1544) wifi_manager: MESSAGE: ORDER_LOAD_AND_RESTORE_STA I (1554) wifi_manager: wifi_manager_fetch_wifi_sta_config: ssid:* password:*** I (1554) wifi_manager: Saved wifi found on startup. Will attempt to connect. I (1564) wifi_manager: MESSAGE: ORDER_CONNECT_STA I (3584) wifi_manager: WIFI_EVENT_STA_CONNECTED I (6634) esp_netif_handlers: sta ip: 192...**, mask: 255.255.255.0, gw: 192... I (6634) wifi_manager: IP_EVENT_STA_GOT_IP I (6634) wifi_manager: WM_EVENT_STA_GOT_IP I (6644) wifi_manager: Set STA IP String to: 192...** I (6644) main: I have a connection and my IP is 192..*.***! I (6654) subpub: Connecting to AWS... I (8494) subpub: Subscribing... I (9574) subpub: Stack remaining for task 'aws_iot_task' is 3240 bytes I (10634) TX_TASK: Wrote 1 bytes: '3' I (14574) JSON: going to write a json I (15074) JSON: Serialize..... I (15074) JSON: my_json_string { "string": "test" } I (15154) subpub: Subscribe callback I (15154) subpub: Title1 { "string": "test" } I (16174) subpub: Stack remaining for task 'aws_iot_task' is 3240 bytes I (20634) TX_TASK: Wrote 1 bytes: '3' I (21174) JSON: going to write a json I (21674) JSON: Serialize..... I (21674) JSON: my_json_string { "string": "test" } E (21694) aws_iot: Failed ! mbedtls_ssl_read returned -0x7880

I (30634) TX_TASK: Wrote 1 bytes: '3' I (40634) TX_TASK: Wrote 1 bytes: '3' E (41694) subpub: An error occurred in the main loop, '-12'

abort() was called at PC 0x400d77e3 on core 1 0x400d77e3: aws_iot_task at C:\Users\alvar\ESP32-Coding\homekit-firmware\build/../main/app_main.c:423

Backtrace:0x40081b42:0x3ffc0b300x400891b5:0x3ffc0b50 0x40090256:0x3ffc0b70 0x400d77e3:0x3ffc0be0 0x4008c929:0x3ffc19d0 0x40081b42: panic_abort at C:/Users/alvar/esp/esp-idf/components/esp_system/panic.c:402

0x400891b5: esp_system_abort at C:/Users/alvar/esp/esp-idf/components/esp_system/esp_system.c:121

0x40090256: abort at C:/Users/alvar/esp/esp-idf/components/newlib/abort.c:46

0x400d77e3: aws_iot_task at C:\Users\alvar\ESP32-Coding\homekit-firmware\build/../main/app_main.c:423

0x4008c929: vPortTaskWrapper at C:/Users/alvar/esp/esp-idf/components/freertos/port/xtensa/port.c:131

ELF file SHA256: 5a071dbad022c99b

Rebooting...

AlvaroModuly commented 2 years ago

I just found out that the MQTT specification allows only one active connection per client ID, so devices with conflicting IDs are forced to constantly reconnect. Because this might indicate that a device or a device's credentials have been compromised, and might be part of a DDoS attack. https://docs.aws.amazon.com/iot/latest/developerguide/audit-chk-conflicting-client-ids.html

However, that doesn't explain why the ESP32 reboots.