Mixiaoxiao / Arduino-HomeKit-ESP32

[Deprecated] Native Apple HomeKit accessory implementation for the ESP32 Arduino core.
MIT License
226 stars 58 forks source link

homekit_storage_reset() causes a crash #3

Open bfaliszek opened 4 years ago

bfaliszek commented 4 years ago

I added "homekit_storage_reset ()" right before "Init Button" in the example. ESP32 started rebooting constantly because of this. When I delete "homekit_storage_reset ()", the device works but still remembers the old keys.

Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c314  PS      : 0x00060f30  A0      : 0x800d7283  A1      : 0x3ffb1ef0  
A2      : 0x00000000  A3      : 0x3ffb1f30  A4      : 0x00000004  A5      : 0x00000000  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffb1ed0  
A10     : 0x3ffbe83c  A11     : 0x3f401382  A12     : 0x3f401382  A13     : 0x3ffb6610  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000004  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

Backtrace: 0x4000c314:0x3ffb1ef0 0x400d7280:0x3ffb1f00 0x400d74e4:0x3ffb1f20 0x400d1984:0x3ffb1f50 0x400ebaa3:0x3ffb1fb0 0x4008835d:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

I added "homekit_storage_reset ()" because I wanted to delete the saved keys from the previous iPhone.

v0r73x commented 3 years ago

Same issue here - i get it somehow into reset by a combination of buttons and opening homekit app on idevice. But now with the multiple sensor i fisrt deleted it in home app and couldn't pair after some mods in .ino :( a little scratch how to use this homekit_storage_reset() as reset will be great for those who not so deep digged in coding as myself ;)

timo-kurtz commented 3 years ago

I have the same issue.

bfaliszek commented 3 years ago

My solution to this problem is to delete homekit_pair.dat from spiffs instead of use homekit_storage_reset().

SPIFFS.remove(/homekit_pair.dat);

Layochi commented 3 years ago

My solution to this problem is to delete homekit_pair.dat from spiffs instead of use homekit_storage_reset().

SPIFFS.remove(/homekit_pair.dat);

@bfaliszek, can you please share your code with us: I have trouble with the SPIFFS library...

bfaliszek commented 3 years ago

@Layochi SPIFFS.remove(/homekit_pair.dat); That's all my code. You can use an example and add the above line to it. This code deletes the keys of the device with which the ESP is connected. This puts the ESP back into pairing mode.

Layochi commented 3 years ago

@bfaliszek Sadly, I got an error : SPIFFS_Test:11:17: error: expected primary-expression before '/' token SPIFFS_Test:11:18: error: 'homekit_pair' was not declared in this scope exit status 1 expected primary-expression before '/' token

With this code : 

#include "FS.h"
#include "SPIFFS.h"

void setup() {
  Serial.begin(115200);
  if (!SPIFFS.begin()) {
    Serial.println("SPIFFS Mount Failed");
    return;
  }

  SPIFFS.remove(/homekit_pair.dat);

  Serial.println( "Test complete" );
}

void loop() {

}
C-r-e-d-o commented 2 years ago

I also get this error.

Can somebody help me?

Surleika commented 2 years ago

Hi, not sure what causes the crash. IMHO you can work around if you go into storage.c (...\documents\Arduino\libraries\HomeKit-ESP8266\src\storage.c) and change parameter ACCESSORY_ID_OFFSET (was 4 on my side). After changing it will be recognised as a new device.

Layochi commented 1 year ago

Can somebody help me?

I figured out that the issue was the missing of " between the parentheses. So the code should be SPIFFS.remove("/homekit_pair.dat"); but it's not working, I still cannot detect my device...

change parameter ACCESSORY_ID_OFFSET (was 4 on my side). After changing it will be recognised as a new device.

I also tried to change ACCESSORY_ID_OFFSET from 4 to 5 or 3 but it's not working either... @Surleika what's the value that you set for ACCESSORY_ID_OFFSET ?

@C-r-e-d-o and @Surleika Did you find a solution ?

Layochi commented 1 year ago

So, I finally find two solutions.

Surleika commented 1 year ago

I worked arround as you did by changing from 4 to 5, flash, change back from 5 to 4 again. Since then it worked stable.

@Layochi: any chance to see your OTA implementation via PM?

Layochi commented 1 year ago

Glad it works for you too! It's sad that this library is not updated anymore...

Here is my implementation :


#include <ArduinoOTA.h>
#include <TelnetStream.h>

const char* hostName = "Name that is visible in arduino IDE";

void setupOTA() {

  ArduinoOTA.setHostname(hostName);
  ArduinoOTA.begin();

  ArduinoOTA.onStart([]() {
    //NOTE: make .detach() here for all functions called by Ticker.h library - not to interrupt transfer process in any way.
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH)
      type = "sketch";
    else // U_SPIFFS
      type = "filesystem";

    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  });

  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
    ESP.restart();
  });

  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });

  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("\nAuth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("\nBegin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("\nConnect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("\nReceive Failed");
    else if (error == OTA_END_ERROR) Serial.println("\nEnd Failed");
  });

  Serial.println("OTA Initialized!");

  Serial.println("Starting Telnet Communication...");
  TelnetStream.begin();
  Serial.println("Telnet Initialized!");

  Serial.println("You can open a new terminal and write the command:\n$ telnet " + WiFi.localIP().toString());
}

void debug(const char* string) {
  Serial.print(string);
  TelnetStream.print(String(string));
}

void debugln(const char* string) {
  Serial.println(string);
  TelnetStream.println(String(string));
}

void handleOTA() {
  ArduinoOTA.handle();

  switch (TelnetStream.read()) {
    case 'C':
      TelnetStream.println("\nClosing the Telnet Communication...");
      TelnetStream.flush();
      TelnetStream.stop();
    break;
    case 'R':
      debugln("\nRebooting...");
      ESP.restart();
    break;
  }
}