m5stack / Core2-for-AWS-IoT-Kit

Accompanying code for use with AWS IoT Kit content. Works with PlatformIO and ESP-IDF v4.2.
https://m5stack.com/collections/m5-core/products/m5stack-core2-esp32-iot-development-kit-for-aws-iot-edukit
MIT License
127 stars 66 forks source link

(xEventGroupWaitBits)- assert failed! (Can't connect to WiFi) #92

Closed Raunak-Singh-Inventor closed 2 years ago

Raunak-Singh-Inventor commented 2 years ago

I am trying to subscribe to a MQTT topic using the code from the Blinky-Hello-World example. When I run this line:

/* Wait for WiFI to show as connected */
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, portMAX_DELAY);   

I get the error: (xEventGroupWaitBits)- assert failed!.

Please help

main.c: https://github.com/Raunak-Singh-Inventor/Stockly/blob/master/edukit_deployment/main/main.c

logs:

[0;32mI (29) boot: ESP-IDF 3.40200.210118 2nd stage bootloader␛[0m
␛[0;32mI (29) boot: compile time 07:50:11␛[0m
␛[0;32mI (29) boot: chip revision: 3␛[0m
␛[0;32mI (33) boot_comm: chip revision: 3, min. bootloader chip revision: 0␛[0m
␛[0;32mI (40) boot.esp32: SPI Speed      : 80MHz␛[0m
␛[0;32mI (45) boot.esp32: SPI Mode       : DIO␛[0m
␛[0;32mI (49) boot.esp32: SPI Flash Size : 16MB␛[0m
␛[0;32mI (54) boot: Enabling RNG early entropy source...␛[0m
␛[0;32mI (59) boot: Partition Table:␛[0m
␛[0;32mI (63) boot: ## Label            Usage          Type ST Offset   Length␛[0m
␛[0;32mI (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000␛[0m
␛[0;32mI (77) boot:  1 phy_init         RF data          01 01 0000f000 00001000␛[0m
␛[0;32mI (85) boot:  2 factory          factory app      00 00 00010000 003f7a00␛[0m
␛[0;32mI (92) boot:  3 ota_0            OTA app          00 10 00410000 00010000␛[0m
␛[0;32mI (100) boot:  4 ota_1            OTA app          00 11 00420000 00640000␛[0m
␛[0;32mI (107) boot:  5 spiffs           Unknown data     01 82 00a60000 004c4c00␛[0m
␛[0;32mI (115) boot: End of partition table␛[0m
␛[0;32mI (119) boot_comm: chip revision: 3, min. application chip revision: 0␛[0m
␛[0;32mI (126) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x3055c (197980) map␛[0m
␛[0;32mI (199) esp_image: segment 1: paddr=0x00040584 vaddr=0x3ffbdb60 size=0x02cd0 ( 11472) load␛[0m
␛[0;32mI (203) esp_image: segment 2: paddr=0x0004325c vaddr=0x40080000 size=0x00404 (  1028) load␛[0m
␛[0;32mI (206) esp_image: segment 3: paddr=0x00043668 vaddr=0x40080404 size=0x0c9b0 ( 51632) load␛[0m
␛[0;32mI (234) esp_image: segment 4: paddr=0x00050020 vaddr=0x400d0020 size=0x9968c (628364) map␛[0m
␛[0;32mI (436) esp_image: segment 5: paddr=0x000e96b4 vaddr=0x4008cdb4 size=0x02620 (  9760) load␛[0m
␛[0;32mI (449) boot: Loaded app from partition at offset 0x10000␛[0m
␛[0;32mI (449) boot: Disabling RNG early entropy source...␛[0m
␛[0;32mI (449) psram: This chip is ESP32-D0WD␛[0m
␛[0;32mI (454) spiram: Found 64MBit SPI RAM device␛[0m
␛[0;32mI (458) spiram: SPI RAM mode: flash 80m sram 80m␛[0m
␛[0;32mI (464) spiram: PSRAM initialized, cache is in low/high (2-core) mode.␛[0m
␛[0;32mI (471) cpu_start: Pro cpu up.␛[0m
␛[0;32mI (475) cpu_start: Application information:␛[0m
␛[0;32mI (479) cpu_start: Project name:     Stockly␛[0m
␛[0;32mI (484) cpu_start: App version:      93108bf-dirty␛[0m
␛[0;32mI (490) cpu_start: Compile time:     May 14 2022 11:28:56␛[0m
␛[0;32mI (496) cpu_start: ELF file SHA256:  e1c98a4eb766075b...␛[0m
␛[0;32mI (502) cpu_start: ESP-IDF:          3.40200.210118␛[0m
␛[0;32mI (507) cpu_start: Starting app cpu, entry point is 0x40083008␛[0m
␛[0;32mI (0) cpu_start: App cpu up.␛[0m
␛[0;32mI (1011) spiram: SPI SRAM memory test OK␛[0m
␛[0;32mI (1012) heap_init: Initializing. RAM available for dynamic allocation:␛[0m
␛[0;32mI (1012) heap_init: At 3FFAE6E0 len 0000F480 (61 KiB): DRAM␛[0m
␛[0;32mI (1018) heap_init: At 3FFCDD80 len 00012280 (72 KiB): DRAM␛[0m
␛[0;32mI (1024) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM␛[0m
␛[0;32mI (1031) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM␛[0m
␛[0;32mI (1037) heap_init: At 4008F3D4 len 00010C2C (67 KiB): IRAM␛[0m
␛[0;32mI (1043) cpu_start: Pro cpu start user code␛[0m
␛[0;32mI (1048) spiram: Adding pool of 4093K of external SPI memory to heap allocator␛[0m
␛[0;32mI (1071) spi_flash: detected chip: generic␛[0m
␛[0;32mI (1071) spi_flash: flash io: dio␛[0m
␛[0;32mI (1071) cpu_start: Starting scheduler on PRO CPU.␛[0m
␛[0;32mI (0) cpu_start: Starting scheduler on APP CPU.␛[0m
␛[0;32mI (1079) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations␛[0m
␛[0;32mI (1309) ILI9341: Initialization.␛[0m
␛[0;32mI (1509) ILI9341: Display orientation: LANDSCAPE␛[0m
␛[0;32mI (1509) ILI9341: 0x36 command value: 0x08␛[0m
␛[0;32mI (1509) gpio: GPIO[39]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 1| Intr:3 ␛[0m
␛[0;32mI (2909) atecc608: Seeding the random number generator...␛[0m
␛[0;32mI (2909) atecc608: ok␛[0m
␛[0;32mI (2919) atecc608: Initializing ATECC608 secure element␛[0m
␛[0;32mI (2919) atecc608: ok␛[0m
␛[0;32mI (2919) atecc608: Checking data zone lock status...␛[0m
␛[0;32mI (2929) atecc608: ok: locked␛[0m
␛[0;32mI (2929) atecc608: Get the device info (type)...␛[0m
␛[0;32mI (2939) atecc608: ok: 60 03␛[0m
␛[0;32mI (3949) STOCKLY: AWS IoT SDK Version 3.0.1-␛[0m
C:\Users\rauna\.platformio\packages\framework-espidf\components\freertos\event_groups.c:350 (xEventGroupWaitBits)- assert failed!

abort() was called at PC 0x40088c96 on core 1

Backtrace:0x40087f37:0x3ffd0f80 0x400885e1:0x3ffd0fa0 0x4008c34a:0x3ffd0fc0 0x40088c96:0x3ffd1030 0x400d223b:0x3ffd1060 0x400885e9:0x3ffd1d10

ELF file SHA256: e1c98a4eb766075b

Rebooting...
Raunak-Singh-Inventor commented 2 years ago

I looked in esp-aws-iot/examples/subscribe_publish/main/subscribe_publish_sample.c and found out that I have to create the event group before running the xEventGroupWaitBits. Here is my updated code:

    /* Wait for WiFI to show as connected */
    EventGroupHandle_t wifi_event_group = xEventGroupCreate();
    xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, portMAX_DELAY);   

This code fixes the error, but now the EduKit isn't able to connect to wifi and instead is stuck in the portMAX_DELAY. Any idea on why this is happening?

Updated main.c: https://github.com/Raunak-Singh-Inventor/Stockly/blob/master/edukit_deployment/main/main.c

Raunak-Singh-Inventor commented 2 years ago

Just figured it out. Had to call initialise_wifi() from wifi.c before connecting to wifi. Updated code snippet.

    /* Wait for WiFI to show as connected */
    initialise_wifi();
    xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 300);