Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homekit_service_by_type Causing Panic (Load Prohibited) #219

Open
mriksman opened this issue Nov 16, 2024 · 3 comments
Open

homekit_service_by_type Causing Panic (Load Prohibited) #219

mriksman opened this issue Nov 16, 2024 · 3 comments

Comments

@mriksman
Copy link
Contributor

mriksman commented Nov 16, 2024

Another issue I am having after the update. The code used to work.

When I change the value (brightness) on Home App, the callback function is called

void state_change_on_callback(homekit_characteristic_t *_ch, homekit_value_t value, void *context) {
    ESP_LOGI(TAG, "%s", _ch->description);
    homekit_service_t *light_service     = homekit_service_by_type(_ch->service->accessory, HOMEKIT_SERVICE_LIGHTBULB);
    homekit_characteristic_t *brightness = homekit_service_characteristic_by_type(light_service, HOMEKIT_CHARACTERISTIC_BRIGHTNESS);

It then panics at homekit_service_t *light_service = homekit_service_by_type(_ch->service->accessory, HOMEKIT_SERVICE_LIGHTBULB);

>>> HomeKit: [Client 2] Update Characteristics
>>> homekit_server_on_update_characteristics: Free heap: 158852
>>> homekit_server_on_update_characteristics: [Client 2] Processing element {
        "aid":  1,
        "iid":  11,
        "value":        70
}
>>> HomeKit: [Client 2] Updating characteristic 1.11 ("Brightness") with integer 70
>>> homekit_characteristic_notify: Got characteristic 1.11 change event
I (59161) main: Brightness
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x400d8e94  PS      : 0x00060530  A0      : 0x800e0b2d  A1      : 0x3ffd2df0  
--- 0x400d8e94: state_change_on_callback at /home/mriksman/Projects/esp32_homekit_animation/main/main.c:65

A2      : 0x3ffcf2c8  A3      : 0x00000000  A4      : 0x00000014  A5      : 0x00000000  
A6      : 0x00000046  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffd2da0  
A10     : 0x00000003  A11     : 0x3f403750  A12     : 0x3f403734  A13     : 0x0000e719  
A14     : 0x3f402294  A15     : 0x3ffcf35d  SAR     : 0x00000004  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffd  
--- 0x400014fd: strlen in ROM
0x4000150d: strlen in ROM



Backtrace: 0x400d8e91:0x3ffd2df0 0x400e0b2a:0x3ffd2e40 0x400e1488:0x3ffd2e80 0x400e165a:0x3ffd2ef0 0x400e2fdd:0x3ffd2f30 0x40100e67:0x3ffd2f50 0x400df2ed:0x3ffd2fa0 0x400e1ae3:0x3ffd2fd0 0x400e3159:0x3ffd3020 0x4008b311:0x3ffd30e0
--- 0x400d8e91: state_change_on_callback at /home/mriksman/Projects/esp32_homekit_animation/main/main.c:65
0x400e0b2a: homekit_characteristic_notify at /home/mriksman/Projects/esp32_homekit_animation/components/homekit/src/server.c:3870
0x400e1488: process_characteristics_update at /home/mriksman/Projects/esp32_homekit_animation/components/homekit/src/server.c:3065
0x400e165a: homekit_server_on_update_characteristics at /home/mriksman/Projects/esp32_homekit_animation/components/homekit/src/server.c:3110
0x400e2fdd: homekit_server_on_message_complete at /home/mriksman/Projects/esp32_homekit_animation/components/homekit/src/server.c:3604
0x40100e67: http_parser_execute at /home/mriksman/Projects/esp32_homekit_animation/components/http-parser/http-parser/http_parser.c:1918 (discriminator 3)
0x400df2ed: homekit_client_process at /home/mriksman/Projects/esp32_homekit_animation/components/homekit/src/server.c:3702

My code is here
https://github.com/mriksman/esp32_homekit_animations

@mriksman
Copy link
Contributor Author

I tried uncommenting a piece of code in my other program https://github.com/mriksman/esp32_homekit_light_switch. It too fails.

Line 625

            homekit_service_t *acc_service = homekit_service_by_type(light->service->accessory, HOMEKIT_SERVICE_ACCESSORY_INFORMATION);
            homekit_characteristic_t *acc_service_manufacture  = homekit_service_characteristic_by_type(acc_service, HOMEKIT_CHARACTERISTIC_MANUFACTURER);
            ESP_LOGE(TAG, "Button Press ***** Manufacturer NAME char %s", acc_service_manufacture->value.string_value ); 
Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x420104b4  RA      : 0x4200adba  SP      : 0x3fca3580  GP      : 0x3fc94400  
--- 0x420104b4: homekit_service_by_type at /home/mriksman/Projects/esp32_homekit_light_switch_v5/components/homekit/src/server.c:594
0x4200adba: main_event_handler at /home/mriksman/Projects/esp32_homekit_light_switch_v5/main/main.c:626

TP      : 0x3fca3810  T0      : 0x000a6d30  T1      : 0x00000065  T2      : 0x5b1b4555  
S0/FP   : 0x3fca3ac0  S1      : 0x3fca2338  A0      : 0x00000000  A1      : 0x3c0f5540  
A2      : 0xfc000000  A3      : 0x00000020  A4      : 0x00000020  A5      : 0x3fcb3598  
A6      : 0x4200aa5e  A7      : 0x00000076  S2      : 0x3c0f5540  S3      : 0x00000025  
--- 0x4200aa5e: main_event_handler at /home/mriksman/Projects/esp32_homekit_light_switch_v5/main/main.c:521

S4      : 0xffffffff  S5      : 0x00000000  S6      : 0xffffffff  S7      : 0x3fcb0784  
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x0000000a  T4      : 0x00000000  T5      : 0x00000000  T6      : 0x00000000  
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000005  MTVAL   : 0x0000000c  
--- 0x40380001: _vector_table at /home/mriksman/esp/v5.3.1/esp-idf/components/riscv/vectors_intc.S:54

@mriksman
Copy link
Contributor Author

Found why it's happening. Originally, the function homekit_accessories_init() was in accessories.c and it would create the linking in services->accessory and characteristics->service. The important lines are

for (homekit_service_t **service_it = accessory->services; *service_it; service_it++) {
    homekit_service_t *service = *service_it;
    service->accessory = accessory;
    for (homekit_characteristic_t **ch_it = service->characteristics; *ch_it; ch_it++) {
        homekit_characteristic_t *ch = *ch_it;
        ch->service = service;
    }
}

In the new version, homekit_accessories_init() is in server.c and it no longer sets these back-pointers.

@mriksman
Copy link
Contributor Author

I've created pull request #220. But I am no programmer, so it's worth a proper review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant