paullj1 / TreatLife-HomeKit

Open source firmware for the TreatLife DS0X dimmer switches for native HomeKit use.
MIT License
9 stars 5 forks source link

FW2.0 on DS02S and DS02 Switch #13

Open boboxx opened 1 year ago

boboxx commented 1 year ago

I just tried to upgrade all my switches to the latest FW and I'm running into a issue where i'm not able to adopt them. I'm able to flash, set the WIFI and I can see them connected to my network. I can also ping them but they don't show up if I click on add accessories. I have tried with the QR code or just using the code but neither of those work either.

All my switch i'm tessting now are HW 4.1.

I would also recomend that the baud rate to be added to each of the release Bin file.

Also how do you get in recover mode to reset wifi or upload the firmware again? I have tried holding down the "restart" tinny button on the bottom, the big (switch on/off) button or either od the dim +/- button but nothing is working

paullj1 commented 1 year ago

So the fix I made in 2.0 was to persist the HomeKit ID. Which means if you update, it should just stay paired. If you remove the device from your home while the device is unreachable, then it will be stuck. The fix for that is to implement a “reset” function to erase the now persisted ID. I ran into this myself, and just reflashed with the “-e” for erase. I can’t promise I’ll be able to implement that function anytime very soon, so feel free to submit a PR if you can beat me to it.

Not sure what you mean by “add the baud rate to the release binary,” but if you want to make a change, I’ll happily consider a PR.

To go into config mode, you push the main button (on/off) for 5 seconds. If it’s already on your wifi, then it won’t advertise an AP, you’ll have to just browse to it. If it’s in that mode, then you also won’t be able to add to your home (this may actually be your issue)

boboxx commented 1 year ago

Can we do the erase over the web upload or do I have to unsolder all my switches and place them on the programmer? I have almost 30 switch to do a the wiring in the box is very tight and painful to put back.

The baud rate was more to tell what baud rate each tuya switch has a setting for either 115200 or 9600. But I do have a few switch that only work with the 9600.

paullj1 commented 1 year ago

Not yet. That will take a change to the firmware. The web interface supports “configuration variables” and one of them could just be the HomeKit ID. The change shouldn’t be too difficult. I might be able to take a look at it this weekend, but can’t make any promises.

As for reflashing, I’ve been able to just take the controller off the switch without having to take the entire switch out of the wall. You can just remove the small screws on the face, and just be careful when removing the ribbon cable. You should also be able to attach wires to the GPIO 0, TX/RX, and power pins without having to remove the dev board from the controller.

That said, I’d be surprised if you had to do all 30 of them that way. Did you have any luck getting them in config mode and browsing to the web interface?

The baud rate is per model number, but I seem to recall you having a switch that has a newer board on an older model. That could also be a config variable in the web UI too, but that one will take a little more work. I can also make it a little more obvious in the per-version include file. Keep in mind, there are a few other things that change between model numbers too.

On Mon, Mar 13, 2023 at 20:46 boboxx @.***> wrote:

Can we do the erase over the web upload or do I have to unsolder all my switches and place them on the programmer? I have almost 30 switch to do a the wiring in the box is very tight and painful to put back.

The baud rate was more to tell what baud rate each tuya switch has a setting for either 115200 or 9600. But I do have a few switch that only work with the 9600.

— Reply to this email directly, view it on GitHub https://github.com/paullj1/TreatLife-HomeKit/issues/13#issuecomment-1467267681, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDPSB2AMM666C22J7KXVRTW37LXTANCNFSM6AAAAAAVZOUBTQ . You are receiving this because you commented.Message ID: @.***>

boboxx commented 1 year ago

The Homekit ID is stored in accessory_id correct?

Would it be as simple as calling homekit_storage_reset(); and erase everything and then start over?

paullj1 commented 1 year ago

Yup. We can use the WiFi Manager's custom params to get a bool in, and then call it.

paullj1 commented 1 year ago

Just pushed a commit that might fix it. Haven't been able to test it yet though since I'm not at home. I'll be able to test this weekend unless you're able to test and make sure it works sooner.

boboxx commented 1 year ago

I tried to use the new push but it still desnet seem to reset the ID. I can see the device on the network but it's not marked as available to register: ff=0 Screenshot 2023-03-20 at 8 44 50 PM

paullj1 commented 1 year ago

Were you able to see the new config variable in the config web page? I briefly tried to get it to work this past weekend, but I wasn’t able to see it.

Were you able to confirm it got a new “ID” in the HAP browser?

On Mon, Mar 20, 2023 at 19:46 boboxx @.***> wrote:

I tried to use the new push but it still desnet seem to reset the ID. I can see the device on the network but it's not marked as available to register: ff=0 [image: Screenshot 2023-03-20 at 8 44 50 PM] https://user-images.githubusercontent.com/15091037/226489278-7a2eb31c-06c8-4e43-8873-8b9b1c85ba9b.png

— Reply to this email directly, view it on GitHub https://github.com/paullj1/TreatLife-HomeKit/issues/13#issuecomment-1477094600, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDPSB2PH4EKLDIULD3KNA3W5DT7DANCNFSM6AAAAAAVZOUBTQ . You are receiving this because you commented.Message ID: @.***>

boboxx commented 1 year ago

I have not been able to get it working. I can confirm that I amn getting a new ID. looking at the Arduino-Homekit-ESP8266 I see on line 3200 in arduino_homekit_server.cpp that the pairing flag is commented : //MDNS.addServiceTxt(HAP_SERVICE, HOMEKIT_MDNS_PROTO, "sf", (server->paired) ? "0" : "1");

ff is used for a Pairing "Feature flags" and sf is "Status flags"

boboxx commented 1 year ago

digging more I see the SF flag is actualy set at line 3183 via:

MDNS.setDynamicServiceTxtCallback(mdns_service,
            [](const MDNSResponder::hMDNSService p_hService) {
                DEBUG("MDNS call DynamicServiceTxtCallback");
                if (running_server) {
                    MDNS.addDynamicServiceTxt(p_hService, "sf",
                            (running_server->paired) ? "0" : "1");
                    MDNS.addDynamicServiceTxt(p_hService, "c#",
                            running_server->config->config_number);
                }

            }
    );

Using Flame you can see each value from one of my old switch running 1.9.1 updated to 2.0 via OTA (AB18F8) and a blank chip on the programmer (67F978).

I also don't know if this is an issue or if's it's just from the Flame tool but there is a space in the name of the device and it get replaced by \0 for exemple: DS02S \003267F98. I think that the _ that gets striped from somewhere. Out of all my Homekit devices that the only place I see this happening.

Screenshot 2023-03-22 at 8 30 17 AM

Screenshot 2023-03-22 at 8 27 42 AM

boboxx commented 1 year ago

I was able to grab the log of a black chip that is in the programmer where I did a ATO update vs a erase and flash via the serial port upload.

It looks like the id is checking the pairing code and not the id: 09:13:49.290 -> >>> [ 983] HomeKit: Starting server 09:13:49.337 -> >>> [ 1024] HomeKit: Using existing accessory ID: E7:FF:62:01:7A:C0 09:13:49.384 -> >>> [ 1097] HomeKit: Found admin pairing with 61B6AFF5-7580-46AE-B85A-8511B8AAD23E, disabling pair setup 09:13:49.525 -> >>> [ 1208] HomeKit: Configuring MDNS 09:13:49.572 -> >>> [ 1251] HomeKit: MDNS begin: DS02S 67F978, IP: 10.1.10.223 09:13:49.619 -> >>> [ 1318] HomeKit: Init server over

boboxx commented 1 year ago

I have tried to simply go back to V2.0 code and to call homekit_storage_reset(); after the homekit_setup(); I was hopping it would reset all the values and then I could load the release FW that you have. But for some reason it's having issue erasing the eeprom. I'm just trying to find a way to wipe the ESP but keep the ATO so I can reupload a good build

Like: void setup() { WiFi.mode(WIFI_STA);

tuya_init(9600); tuya_set_wifi(TUYA_WIFI_DISCONNECTED);

WiFiManager wm; wm.setDebugOutput(false); wm.setConfigPortalTimeout(WIFI_BOOT_CONFIG_TIMEOUT); if (!wm.autoConnect()) { ESP.restart(); } tuya_set_wifi(TUYA_WIFI_CONNECTED);

homekit_storage_reset(); homekit_setup();

}

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address PC: 0x4000425c EXCVADDR: 0x3ffe9c9b

Decoding stack results 0x40205fc1: homekit_storage_set_magic at C:\Users\user\Documents\Arduino\libraries\Arduino-HomeKit-ESP8266\src\storage.c line 105 0x40206022: homekit_storage_init at C:\Users\user\Documents\Arduino\libraries\Arduino-HomeKit-ESP8266\src\storage.c line 124 0x4020603c: homekit_storage_init at C:\Users\user\Documents\Arduino\libraries\Arduino-HomeKit-ESP8266\src\storage.c line 126 0x40227ae3: homekit_server_init(homekit_server_config_t) at C:\Users\user\Documents\Arduino\libraries\Arduino-HomeKit-ESP8266\src\arduino_homekit_server.cpp line 3304 0x4023693c: snprintf at /workdir/repo/newlib/newlib/libc/stdio/snprintf.c line 90 0x4021aafa: WiFiManager::DEBUG_WM__FlashStringHelper const, IPAddress>(WiFiManager::wm_debuglevel_t, __FlashStringHelper const, IPAddress) at C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\cores\esp8266/IPAddress.h line 85 0x402186e8: S2Stream::read() at C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\cores\esp8266/WString.h line 254 0x402208bb: WiFiManager::autoConnect(char const, char const) at C:\Users\user\Documents\Arduino\libraries\WiFiManager\WiFiManager.cpp line 353 0x40232699: uart_write(uart_t, char const, size_t) at C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\cores\esp8266\uart.cpp line 544 0x402288b2: arduino_homekit_loop() at C:\Users\user\Documents\Arduino\libraries\Arduino-HomeKit-ESP8266\src\arduino_homekit_server.cpp line 3551 0x40217ce8: tuya_send_cmd(unsigned char, unsigned char, unsigned short) at C:\Users\user\Documents\Arduino\TreatLife-HomeKit-2.0\DS02S/tuya.ino line 17 0x4023183c: esp_try_delay(unsigned int, unsigned int, unsigned int) at c:\users\user\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.1.0-gcc10.3-e5f9fec\xtensa-lx106-elf\include\c++\10.3.0/numeric line 132 0x40100361: cont_check(cont_t*) at C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\cores\esp8266\cont_util.cpp line 50**