pvvx / THB2

Custom firmware for Tuya devices on the PHY622x2 chipset
Other
239 stars 20 forks source link

(Macbook) Error writing the FW-APP #63

Open eph2 opened 3 months ago

eph2 commented 3 months ago

Hello. I'm trying to write the FW APP to my BTH01.

The firmware was successful uploaded, but when I try to upload the FW APP some errors occurs.

I tryed from OTA page, and the command line method too.

Here are the code from the command line:

% python3 rdwr_phy62x2.py -p /dev/cu.SLAB_USBtoUART -b 115200 -e wh bin/BOOT_BTH01_v17.hex
python3 rdwr_phy62x2.py -p /dev/cu.SLAB_USBtoUART -b 115200 -r we 0x10000 bin/BTH01_v17.bin
=========================================================
PHY62x2 Utility version 11.03.24
---------------------------------------------------------
Connecting...
PHY62x2 - Reset Ok
Revision: b'001364c8 6222M005'
FlashID: 1364c8, size: 512 kbytes
PHY62x2 - connected Ok
---- Segments Table -------------------------------------
Segment: 11003000 <- Flash addr: 00003000, Size: 00008b64
Segment: 1fff0000 <- Flash addr: 0000bb64, Size: 00000400
Segment: 1fff1838 <- Flash addr: 0000bf64, Size: 00002bca
----------------------------------------------------------
Erase Flash work area... ok
Segment Table[03] <- Flash addr: 00002000, Size: 00000130
Write 0x00000130 bytes to Flash at 0x00002000... ok
Segment: 11003000 <- Flash addr: 00003000, Size: 00008b64
Write 0x00002000 bytes to Flash at 0x00003000... ok
Write 0x00002000 bytes to Flash at 0x00005000... ok
Write 0x00002000 bytes to Flash at 0x00007000... ok
Write 0x00002000 bytes to Flash at 0x00009000... ok
Write 0x00000b64 bytes to Flash at 0x0000b000... ok
Segment: 1fff0000 <- Flash addr: 0000bb64, Size: 00000400
Write 0x00000400 bytes to Flash at 0x0000bb64... ok
Segment: 1fff1838 <- Flash addr: 0000bf64, Size: 00002bca
Write 0x00002000 bytes to Flash at 0x0000bf64... ok
Write 0x00000bca bytes to Flash at 0x0000df64... ok
----------------------------------------------------------
Write Flash from file: bin/BOOT_BTH01_v17.hex - ok.
=========================================================
PHY62x2 Utility version 11.03.24
---------------------------------------------------------
Connecting...
PHY62x2 - Reset Ok
Revision: b'001364c8 6222M005'
FlashID: 1364c8, size: 512 kbytes
PHY62x2 - connected Ok
Write Flash data 0x00010000 to 0x0001bde4 from file: bin/BTH01_v17.bin ...
Erase sector Flash at 0x00010000... ok
Erase sector Flash at 0x00011000... ok
Erase sector Flash at 0x00012000... ok
Erase sector Flash at 0x00013000... ok
Erase sector Flash at 0x00014000... ok
Erase sector Flash at 0x00015000... ok
Erase sector Flash at 0x00016000... ok
Erase sector Flash at 0x00017000... ok
Erase sector Flash at 0x00018000... ok
Erase sector Flash at 0x00019000... ok
Erase sector Flash at 0x0001a000... ok
Erase sector Flash at 0x0001b000... ok
Write 0x00002000 bytes to Flash at 0x00010000... ok
Write 0x00002000 bytes to Flash at 0x00012000... ok
Write 0x00002000 bytes to Flash at 0x00014000... ok
Write 0x00002000 bytes to Flash at 0x00016000... ok
Write 0x00002000 bytes to Flash at 0x00018000... ok
Write 0x00001de4 bytes to Flash at 0x0001a000... error!
Error: Write Flash!

And here are the OTA error:

20:43:47: Start OTA flashing...
20:44:18: OTA: NotSupportedError: GATT operation failed for unknown reason.
20:44:18: Device is disabled.

On the status area this are the message when the FW area trying to be uploaded: Block transferred 15 from 3039, 0% succeeded, total time 0.006 seconds

Sometimes, OTA returns this message too: Error: Error (7) during block transmission 15 OTA: Package loss

I'm attaching the "resume" of the sensors to this post too, the voltage are ok!

Captura de Tela 2024-08-22 às 20 46 01

And, I'm attaching a photo of the board too. IMG_5812

EDIT: I tried with the 1.8 version too, and I have the same errors

eph2 commented 3 months ago

I'm using a Macbook, but when I try to upload the FW APP with OTA, on a Windows computer, it worked.

pvvx commented 3 months ago

Only Linux, Windows, Android are supported. APP programming has problems in the ROM chip program. Therefore, it is recommended to use OTA for APP.

eph2 commented 3 months ago

Only Linux, Windows, Android are supported. APP programming has problems in the ROM chip program. Therefore, it is recommended to use OTA for APP.

Nice, Victor. Thanks for your reply!

Straying from the topic of this post, but taking advantage of the fact that I have doubts.

I configured the BTH01 in Home Assistant, using BTHome, everything worked perfectly, but only two entities are coming without values ​​(as shown in the image below). When clicking on them, they say they are disabled. Is this normal?

Captura de Tela 2024-08-23 às 19 20 15

Second question: when the sensors were connected to the Tuya system, the integration with Home Assistant notified me when the devices became unavailable. Is there any way I can monitor this now? I imagine it has to do with the entities mentioned above, but maybe there is another way. When I remove the batteries from the sensors, they just stop sending the signal and do not update the value. Should I use this time of the last update as a "sign" of unavailability?

Thanks in advance!

pvvx commented 3 months ago

I configured the BTH01 in Home Assistant, using BTHome, everything worked perfectly, but only two entities are coming without values ​​(as shown in the image below). When clicking on them, they say they are disabled. Is this normal?

This is diagnostic data and is not needed by everyone. When activated, the data will be written to the history, to the HA database. This will reduce the media resource and increase the size of the database.

image

Second question: when the sensors were connected to the Tuya system, the integration with Home Assistant notified me when the devices became unavailable.

This is configured in the integration package you are using (Bluetooth, BTHome).

The parameter state is marked as "Unavailable". I don't remember where in "Bluetooth" and "BTHome" the period is set. image

eph2 commented 2 months ago

NIce, thanks, Victor!

g6094199 commented 2 months ago

i get the same error on bth01 when fw 1.8b.bin was successfully flashed with ota and i try to reconnect with web flasher. boot was updated to 1.8 before via serial

`

5:09:16 PM: Not connected 5:09:19 PM: Searching for devices 5:09:23 PM: Waiting for connection to BTH01-FF9DAB 5:09:33 PM: Model: BTH01 5:09:33 PM: Firmware: github.com/pvvx 5:09:33 PM: Hardware: 0014 5:09:33 PM: Software: B1.8 5:09:33 PM: Device info # hw: 0014, sw: 0018, services: 00000281, sd: 0000 5:09:33 PM: OTA ver: 01 5:09:33 PM: Connected. 5:09:33 PM: Set device time... 5:09:33 PM: Set device time (23CDCEE166)... 5:10:22 PM: Download firmware file 'BTH01_v18.bin'... 5:10:22 PM: File: bin/BTH01_v18.bin 5:10:22 PM: File id:PHY6, Segments: 3, Start: 0x"1FFF1838, : 48624 5:10:22 PM: Filesize: 48628 bytes 5:10:22 PM: Counter: 3040 blocks 5:10:43 PM: Start OTA flashing... 5:11:37 PM: Flash finished in 52.867 seconds 5:11:40 PM: Device is disabled. 5:11:45 PM: Searching for devices 5:11:49 PM: Waiting for connection to BTH01-FF9DAB 5:11:58 PM: Model: BTH01 5:11:58 PM: Firmware: github.com/pvvx 5:11:58 PM: Hardware: 0014 5:11:58 PM: Software: V1.8 5:11:58 PM: NotSupportedError: GATT operation failed for unknown reason. 5:11:58 PM: Reconnect 0 / 5 5:11:58 PM: Waiting for connection to BTH01-FF9DAB 5:11:59 PM: Model: BTH01 5:11:59 PM: Firmware: github.com/pvvx 5:11:59 PM: Hardware: 0014 5:11:59 PM: Software: V1.8 5:11:59 PM: NotSupportedError: GATT operation failed for unknown reason. 5:11:59 PM: Reconnect 1 / 5 5:11:59 PM: Waiting for connection to BTH01-FF9DAB 5:11:59 PM: Model: BTH01 5:11:59 PM: Firmware: github.com/pvvx 5:11:59 PM: Hardware: 0014 5:11:59 PM: Software: V1.8 5:11:59 PM: NotSupportedError: GATT operation failed for unknown reason. 5:11:59 PM: Reconnect 2 / 5 5:11:59 PM: Waiting for connection to BTH01-FF9DAB 5:12:00 PM: Model: BTH01 5:12:00 PM: Firmware: github.com/pvvx 5:12:00 PM: Hardware: 0014 5:12:00 PM: Software: V1.8 5:12:00 PM: NotSupportedError: GATT operation failed for unknown reason. 5:12:00 PM: Reconnect 3 / 5 5:12:00 PM: Waiting for connection to BTH01-FF9DAB 5:12:00 PM: Model: BTH01 5:12:00 PM: Firmware: github.com/pvvx 5:12:00 PM: Hardware: 0014 5:12:00 PM: Software: V1.8 5:12:00 PM: NotSupportedError: GATT operation failed for unknown reason. 5:12:00 PM: Reconnect 4 / 5 5:12:00 PM: Waiting for connection to BTH01-FF9DAB 5:12:01 PM: Model: BTH01 5:12:01 PM: Firmware: github.com/pvvx 5:12:01 PM: Hardware: 0014 5:12:01 PM: Software: V1.8 5:12:01 PM: NotSupportedError: GATT operation failed for unknown reason. 5:12:01 PM: Connection failed!`

pvvx commented 2 months ago

Two options:

  1. Long BLE advertising interval. Before attempting to connect, you must press the button on the thermometer.
  2. Chip glitch. At supply voltage over 2.6 V, some batches of PHY6222 chips have a special instability of the internal timer. This is most often found in BTH01. Software correction of the internal oscillator drift is performed over a long interval. That is, try connecting later or install a discharged battery. [Or disconnect the external 3.3V power source (if connected) and use batteries.]
Staars commented 1 week ago

Two observations on MacOS Sequoia on a M1Max:

  1. In MacOS I did not even pass the first step of seeing a successful reset in many, many tries.
  2. Using a virtual machine (Ubuntu Noble server/Virtualbox) solved this completely with a 100% success rate on the same Macbook.