apple / swift-matter-examples

An Embedded Swift Matter application running on ESP32-C6
https://apple.github.io/swift-matter-examples/tutorials/tutorial-table-of-contents/
Apache License 2.0
257 stars 19 forks source link

Problem with Connecting Swift Matter Smart-Light Example to Network #9

Open yaJannik opened 3 months ago

yaJannik commented 3 months ago

Hi there,

Description

I am currently testing the Swift Matter smart-light example. The build process completed successfully, but I am encountering issues during execution. The device is recognized as a 'Matter Accessory' and I am able to enter the code. However, after this step, the device is unable to connect to the network.

System Information

Swift Version

Software Installed

Environment Setup

Log

Log

``` I (2018) main_task: Returned from app_main() I (31618) chip[DL]: Configuring CHIPoBLE advertising (interval 500 ms, connectable) I (31618) chip[DL]: Device already advertising, stop active advertisement and restart I (31618) NimBLE: GAP procedure initiated: stop advertising. I (31628) NimBLE: GAP procedure initiated: advertise; I (31638) NimBLE: disc_mode=2 I (31638) NimBLE: adv_channel_map=0 own_addr_type=1 adv_filter_policy=0 adv_itvl_min=800 adv_itvl_max=800 I (31648) NimBLE: I (36708) chip[DL]: BLE GAP connection established (con 0) I (36708) chip[DL]: CHIPoBLE advertising stopped I (37468) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (37468) chip[BLE]: local and remote recv window sizes = 5 I (37478) chip[BLE]: selected BTP version 4 I (37478) chip[BLE]: using BTP fragment sizes rx 244 / tx 244. I (37628) chip[DL]: Write request/command received for CHIPoBLE TX CCCD characteristic (con 0 ) indicate = 1 I (37628) chip[DL]: CHIPoBLE subscribe received I (37638) NimBLE: GATT procedure initiated: indicate; I (37638) NimBLE: att_handle=18 I (37708) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (37708) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (37718) chip[EM]: >>> [E:4011r S:0 M:160536951] (U) Msg RX from 0:40C9401083F2E347 [0000] --- Type 0000:20 (SecureChannel:PBKDFParamRequest) I (37728) chip[EM]: <<< [E:4011r S:0 M:160126738] (U) Msg TX to 0:0000000000000000 [0000] [BLE] --- Type 0000:21 (SecureChannel:PBKDFParamResponse) I (37748) NimBLE: GATT procedure initiated: indicate; I (37748) NimBLE: att_handle=18 I (37758) chip[SVR]: Commissioning session establishment step started I (37788) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (37788) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (37798) chip[EM]: >>> [E:4011r S:0 M:160536952] (U) Msg RX from 0:40C9401083F2E347 [0000] --- Type 0000:22 (SecureChannel:PASE_Pake1) I (37868) chip[EM]: <<< [E:4011r S:0 M:160126739] (U) Msg TX to 0:0000000000000000 [0000] [BLE] --- Type 0000:23 (SecureChannel:PASE_Pake2) I (37868) NimBLE: GATT procedure initiated: indicate; I (37878) NimBLE: att_handle=18 I (37918) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (37918) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (37928) chip[EM]: >>> [E:4011r S:0 M:160536953] (U) Msg RX from 0:40C9401083F2E347 [0000] --- Type 0000:24 (SecureChannel:PASE_Pake3) I (37938) chip[EM]: <<< [E:4011r S:0 M:160126740] (U) Msg TX to 0:0000000000000000 [0000] [BLE] --- Type 0000:40 (SecureChannel:StatusReport) I (37948) NimBLE: GATT procedure initiated: indicate; I (37958) NimBLE: att_handle=18 I (37968) chip[SC]: SecureSession[0x408220e8, LSID:14172]: State change 'kEstablishing' --> 'kActive' I (37968) chip[SVR]: Commissioning completed session establishment step I (37978) chip[DIS]: Updating services using commissioning mode 0 I (37988) chip[DIS]: CHIP minimal mDNS started advertising. I (37988) chip[DIS]: Advertise commission parameter vendorID=65521 productID=32768 discriminator=3840/15 cm=0 I (37998) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38008) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (38008) chip[DIS]: CHIP minimal mDNS configured as 'Commissionable node device'; instance name: 16E59C200C8B1FA3. I (38028) chip[DIS]: mDNS service published: _matterc._udp I (38038) chip[SVR]: Device completed Rendezvous process I (38048) chip[EM]: >>> [E:4012r S:14172 M:208185942] (S) Msg RX from 0:FFFFFFFB00000000 [0000] --- Type 0001:02 (IM:ReadRequest) I (38058) chip[EM]: <<< [E:4012r S:14172 M:191691874] (S) Msg TX to 0:FFFFFFFB00000000 [0000] [BLE] --- Type 0001:05 (IM:ReportData) I (38068) NimBLE: GATT procedure initiated: indicate; I (38078) NimBLE: att_handle=18 I (38128) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38128) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (38138) chip[EM]: >>> [E:4013r S:14172 M:208185943] (S) Msg RX from 0:FFFFFFFB00000000 [0000] --- Type 0001:02 (IM:ReadRequest) I (38148) chip[EM]: <<< [E:4013r S:14172 M:191691875] (S) Msg TX to 0:FFFFFFFB00000000 [0000] [BLE] --- Type 0001:05 (IM:ReportData) I (38158) NimBLE: GATT procedure initiated: indicate; I (38168) NimBLE: att_handle=18 I (38208) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38208) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (38218) chip[EM]: >>> [E:4014r S:14172 M:208185944] (S) Msg RX from 0:FFFFFFFB00000000 [0000] --- Type 0001:02 (IM:ReadRequest) I (38228) chip[EM]: <<< [E:4014r S:14172 M:191691876] (S) Msg TX to 0:FFFFFFFB00000000 [0000] [BLE] --- Type 0001:05 (IM:ReportData) I (38238) NimBLE: GATT procedure initiated: indicate; I (38248) NimBLE: att_handle=18 I (38288) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38308) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (38318) chip[EM]: >>> [E:4015r S:14172 M:208185945] (S) Msg RX from 0:FFFFFFFB00000000 [0000] --- Type 0001:02 (IM:ReadRequest) I (38328) chip[EM]: <<< [E:4015r S:14172 M:191691877] (S) Msg TX to 0:FFFFFFFB00000000 [0000] [BLE] --- Type 0001:05 (IM:ReportData) I (38338) NimBLE: GATT procedure initiated: indicate; I (38338) NimBLE: att_handle=18 I (38388) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38388) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (38398) chip[EM]: >>> [E:4016r S:14172 M:208185946] (S) Msg RX from 0:FFFFFFFB00000000 [0000] --- Type 0001:02 (IM:ReadRequest) I (38418) chip[EM]: <<< [E:4016r S:14172 M:191691878] (S) Msg TX to 0:FFFFFFFB00000000 [0000] [BLE] --- Type 0001:05 (IM:ReportData) I (38428) NimBLE: GATT procedure initiated: indicate; I (38428) NimBLE: att_handle=18 I (38468) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38468) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (38478) chip[EM]: >>> [E:4017r S:14172 M:208185947] (S) Msg RX from 0:FFFFFFFB00000000 [0000] --- Type 0001:02 (IM:ReadRequest) I (38498) esp_matter_attribute: ********** R : Endpoint 0x0000's Cluster 0x00000030's Attribute 0x00000000 is 0 ********** I (38508) chip[EM]: <<< [E:4017r S:14172 M:191691879] (S) Msg TX to 0:FFFFFFFB00000000 [0000] [BLE] --- Type 0001:05 (IM:ReportData) I (38518) NimBLE: GATT procedure initiated: indicate; I (38518) NimBLE: att_handle=18 I (38578) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38578) NimBLE: GATT procedure initiated: indicate; I (38578) NimBLE: att_handle=18 I (38628) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38628) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (38638) chip[EM]: >>> [E:4018r S:14172 M:208185948] (S) Msg RX from 0:FFFFFFFB00000000 [0000] --- Type 0001:02 (IM:ReadRequest) I (38648) chip[EM]: <<< [E:4018r S:14172 M:191691880] (S) Msg TX to 0:FFFFFFFB00000000 [0000] [BLE] --- Type 0001:05 (IM:ReportData) I (38658) NimBLE: GATT procedure initiated: indicate; I (38668) NimBLE: att_handle=18 I (38708) chip[DL]: Confirm received for CHIPoBLE TX characteristic indication (con 0) status= 14 I (38708) CHIP[DL]: Write request received for CHIPoBLE RX characteristic con 0 16 I (38718) chip[EM]: >>> [E:4019r S:14172 M:208185949] (S) Msg RX from 0:FFFFFFFB00000000 [0000] --- Type 0001:08 (IM:InvokeCommandRequest) I (38728) esp_matter_command: Received command 0x00000000 for endpoint 0x0000's cluster 0x00000030 I (38738) chip[FS]: GeneralCommissioning: Received ArmFailSafe (60s) I (38748) esp_matter_attribute: ********** W : Endpoint 0x0000's Cluster 0x00000030's Attribute 0x00000000 is 4 ********** Guru Meditation Error: Core 0 panic'ed (Instruction access fault). Exception was unhandled. Stack dump detected Core 0 register dump: MEPC : 0x00000000 RA : 0x4200b3b4 SP : 0x40845f00 GP : 0x4081b680 0x4200b3b4: $s10__idf_main8RootNodeV9attribute8identifyACSgyAA20MatterAttributeEventO_AA8EndpointVAA7ClusterVs6UInt32VSpySo21esp_matter_attr_val_taGSgtc_ySo0m1_N0O14identificationO13callback_typeV_s6UInt16Vs5UInt8VA0_tctcfcs5Int32VAtDOAWV_Az2nRSvSgtcfU_ at ??:? TP : 0x4080a780 T0 : 0x4200af78 T1 : 0x42006c5c T2 : 0xffffffff 0x4080a780: regi2c_ctrl_ll_bbpll_calibration_start at /Users//esp/esp-idf/components/hal/esp32c6/include/hal/regi2c_ctrl_ll.h:24 (inlined by) rtc_clk_bbpll_configure at /Users//esp/esp-idf/components/esp_hw_support/port/esp32c6/rtc_clk.c:167 (inlined by) rtc_clk_cpu_freq_set_config at /Users//esp/esp-idf/components/esp_hw_support/port/esp32c6/rtc_clk.c:274 0x4200af78: $s10__idf_main6MatterO4NodeC12eventHandler4type8endpoint7cluster9attribute5valueyAA0C14AttributeEventO_AA8EndpointVAA7ClusterVs6UInt32VSpySo21esp_matter_attr_val_taGSgtF at ??:? 0x42006c5c: esp_vfs_open at /Users//esp/esp-idf/components/vfs/vfs.c:454 S0/FP : 0x4083499c S1 : 0x40834188 A0 : 0x40834188 A1 : 0x40849640 A2 : 0x00000001 A3 : 0x00000000 A4 : 0x40845f58 A5 : 0x00000000 A6 : 0x4200b3d4 A7 : 0x0000000a S2 : 0x40845f58 S3 : 0x00000000 0x4200b3d4: $s10__idf_main8RootNodeV9attribute8identifyACSgyAA20MatterAttributeEventO_AA8EndpointVAA7ClusterVs6UInt32VSpySo21esp_matter_attr_val_taGSgtc_ySo0m1_N0O14identificationO13callback_typeV_s6UInt16Vs5UInt8VA0_tctcfcs5Int32VAtDOAWV_Az2nRSvSgtcfU_To at ??:? S4 : 0x408349b8 S5 : 0x408351f4 S6 : 0x00000000 S7 : 0x4200b69e 0x4200b69e: $s10__idf_main6MatterO4NodeCAEycfcyAA0C14AttributeEventO_AA8EndpointVAA7ClusterVs6UInt32VSpySo21esp_matter_attr_val_taGSgtcAEcfu_yAG_AikmQtcfu0_TA at Main.swift.obj:? S8 : 0x00000000 S9 : 0x4214d468 S10 : 0x40846440 S11 : 0x00000000 T3 : 0x00000000 T4 : 0x00000080 T5 : 0x00000040 T6 : 0xdfffffff MSTATUS : 0x00001881 MTVEC : 0x40800001 MCAUSE : 0x00000001 MTVAL : 0x00000000 0x40800001: _vector_table at ??:? MHARTID : 0x00000000 Failed to run gdb_panic_server.py script: Command '['riscv32-esp-elf-gdb', '--batch', '-n', '/Users//Code/swift-matter-examples/smart-light/build/light.elf', '-ex', 'target remote | "/Users//.espressif/python_env/idf5.2_py3.11_env/bin/python" -m esp_idf_panic_decoder --target esp32c6 "/var/folders/d_/tf2f7lnj74x86yjggjqgnvk80000gn/T/tmpqb0zeo2o"', '-ex', 'bt']' returned non-zero exit status 1. b'Traceback (most recent call last):\n File "", line 198, in _run_module_as_main\n File "", line 88, in _run_code\n File "/Users//.espressif/python_env/idf5.2_py3.11_env/lib/python3.11/site-packages/esp_idf_panic_decoder/__main__.py", line 4, in \n main()\n File "/Users//.espressif/python_env/idf5.2_py3.11_env/lib/python3.11/site-packages/esp_idf_panic_decoder/gdb_panic_server.py", line 285, in main\n panic_info = PANIC_OUTPUT_PARSERS[args.target](args.input_file.read())\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/Users//.espressif/python_env/idf5.2_py3.11_env/lib/python3.11/site-packages/esp_idf_panic_decoder/gdb_panic_server.py", line 150, in parse_idf_riscv_panic_output\n stack_base_addr, stack_data = get_stack_addr_and_data(res)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/Users//.espressif/python_env/idf5.2_py3.11_env/lib/python3.11/site-packages/esp_idf_panic_decoder/gdb_panic_server.py", line 118, in get_stack_addr_and_data\n assert base_addr == prev_base_addr + bytes_in_line\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAssertionError\nRemote connection closed\nNo stack.\n' Stack memory: 40845f00: 0x00000000 0x00000000 0x00000004 0x00000001 0x00000000 0x00000027 0x00000008 0x00000027 40845f20: 0x00000000 0x00000030 0x00000000 0x4200b3dc 0x00000000 0x00000030 0x00000000 0x4200fc66 40845f40: 0x00000002 0x40846764 0x4084f078 0x40846008 0x40846440 0x0000000a 0x0000000e 0x00000000 40845f60: 0x00000004 0x00000000 0x00000000 0x00000000 0x00000000 0x00000027 0x00000000 0x00000000 0x420178f4 0x42153ff4 0x00000004 0x40829618 0x420654e4 40845fa0: 0x00000002 0x4084600c 0x00000065 0x4084f078 0x00000004 0x70696863 0x40820000 0x00000030 40845fc0: 0x00000000 0x42000000 0x00000030 0x00000000 0x0000ea60 0x4214d468 0x00000000 0x00000000 40845fe0: 0x00000000 0x40846138 0x40835414 0x00000000 0x40846070 0x4084610c 0x408262c4 0x420251d4 40846000: 0x0000001f 0x40846138 0x00000004 0x00000000 0x40846070 0x4084610c 0x408262c4 0x4202bf88 40846020: 0x40846440 0x40846000 0x00000000 0x00000000 0x00000000 0x40846138 0x00000030 0x00000000 40846040: 0x00000001 0x00000001 0x00000015 0x40846138 0x00000000 0x00000000 0xffffffff 0x42148000 40846060: 0x408262c4 0x4084610c 0x408262c4 0x4202393a 0x0000003c 0x408262c4 0x00000004 0x00000000 40846080: 0x42147a08 0x00000000 0x4084610c 0x4202454e 0x00000001 0x00000000 0xffffffff 0x00000000 408460a0: 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000 0x4084f9f8 0x4084fa05 0x00000016 408460c0: 0x00000023 0x00000015 0x40000035 0x42033bac 0x408465ec 0x00000000 0x408465ec 0x408262c8 408460e0: 0x408462b0 0x408262c4 0x00000000 0x4204f938 0x00000018 0xffffffff 0x40846168 0x00000010 40846100: 0x4084fa05 0x00000000 0x408465ec 0x00000000 0x00000030 0x00000000 0x00002000 0x00000000 40846120: 0x00000000 0xfffffffb 0x00000000 0x00000000 0x00000000 0x00000000 0xffffffff 0x00000000 40846140: 0x00000100 0x00000000 0x00000000 0x00000000 0x00000000 0x4084f9ff 0x4084fa05 0x0000001d 40846160: 0x00000023 0x00000015 0xff00ffff 0x00000000 0xffffffff 0x00000000 0x00000100 0x00000000 40846180: 0x00000000 0x00000000 0x00000000 0x4084f9ec 0x4084fa05 0x0000000a 0x00000023 0x00000017 408461a0: 0x0000ffff 0x408262c4 0x00000015 0x408262c8 0x00000100 0x408262c4 0x0000007e 0x4204fc24 408461c0: 0xffffffff 0x00000000 0x00000100 0x00000000 0x00000000 0x00000000 0x00000000 0x4084f9e3 408461e0: 0x4084fa05 0x00000001 0x00000023 0xffffffff 0x42000015 0x4084f95c 0xffffffff 0x00000000 40846200: 0x00000100 0x00000000 0x00000000 0x00000000 0x00000000 0x4084f9ea 0x4084fa05 0x00000008 40846220: 0x00000023 0x00000016 0x40000015 0x4080cb4c 0xffffffff 0x00000000 0x00000100 0x00000000 40846240: 0x00000000 0x00000000 0x00000000 0x4084f9e3 0x4084fa05 0x00000001 0x00000023 0x00000015 40846260: 0x0000ffff 0x40846764 0xffffffff 0x4080ccd6 0xffffffff 0x00000000 0x00000100 0x00000000 40846280: 0x00000000 0x00000000 0x00000000 0x4084f9e9 0x4084fa05 0x00000007 0x00000023 0x00000016 408462a0: 0x4000ffff 0x00000000 0x00000015 0x408017ac 0xffffffff 0x00000000 0x00000100 0x00000000 408462c0: 0x00000000 0x00000000 0x00000000 0x4084f9ea 0x4084fa05 0x00000008 0x00000023 0x00000015 408462e0: 0x0000ffff 0x00000000 0x00000016 0x4080cb4c 0x408465ec 0x40823900 0x408262c4 0x4204fc9e ELF file SHA256: 7ab7cb82c I (2942) esp_core_dump_flash: Save core dump to flash... I (2948) esp_core_dump_flash: Erase flash 12288 bytes @ 0x3e6000 I (3041) esp_core_dump_flash: Write end offset 0x2644, check sum length 4 I (3041) esp_core_dump_flash: Core dump has been saved to flash. Rebooting... ```

Core Dump

``` │ esptool.py v4.7.0 │ Serial port /dev/cu.usbserial-1420 │ Connecting.... │ Detecting chip type... ESP32-C6 │ Chip is ESP32-C6 (QFN40) (revision v0.0) │ Features: WiFi 6, BT 5, IEEE802.15.4 │ Crystal is 40MHz │ MAC: xxx │ BASE MAC: xxx │ MAC_EXT: xxx │ Uploading stub... │ Running stub... │ Stub running... │ Changing baud rate to 460800 │ Changed. │ A fatal error occurred: Invalid head of packet (0x00): Possible serial noise or corruption. ```

Request

Any guidance or suggestions to resolve this build issue would be greatly appreciated.

EDIT: Currently I don't have access to a JTAG Debugger. I'll ask some coworker if they can help me out.

Best regards, Jannik

davidmuzi commented 3 months ago

I'm having the same issue.

The WWDC video "Go small with Embedded Swift" mentions that the device needs to be connected to WiFi:

The device will then join my WiFi and the HomeKit network, and it can be controlled from the Home app on any of the Apple devices.

Should connecting to WiFi happen when adding the accessory to HomeKit in the Home app (the iOS device provides the SSID and password)? Or is there some step missing to connect the ESP32 to WiFi before adding to HomeKit?

PaulSolt commented 2 months ago

It should get provisioned through the Home app when you set it up.

I was able to fix it by erasing everything and starting over with HomeKit.

You can reset your device using this command.

idf.py erase-flash

Then retry and build and run

idf.py build flash monitor
iDevPro commented 2 months ago

I connected with wifi normally 1) when you do idf.py set-target targetname all configs are drop and need to fix again 2) for wifi connect after set-target procedure I change CONFIG_DEFAULT_WIFI_SSID in three files:

sdkconfig
sdkconfig.h
sdkconfig.json

and build project

Or more easy way:

create file sdkconfig.defaults.esp32c3 where esp32c3 (your target name) and append CONFIG_DEFAULT_WIFI_SSID and save then remove build folder and call idf.py set-target esp32c3 again :)