pvvx / THB2

Custom firmware for Tuya devices on the PHY622x2 chipset
Other
92 stars 13 forks source link

THB1 bluetooth problems #38

Closed rainer38 closed 3 months ago

rainer38 commented 3 months ago

Hi,

thanks for your effort for this nice project. I already updated my Xiaomi Thermometers and they work fine with your firmware. :)

Now i got a few cheap Tuya THB1 and tried to flash your firmware on them.

Therefor i soldered an usb2ttl serial adapter to the board and executed the following two commands:

python3 rdwr_phy62x2.py -p /dev/ttyUSB0 -e -r wh bin/BOOT_THB1_v16.hex python3 rdwr_phy62x2.py -p /dev/ttyUSB0 -r we 0x10000 bin/THB1_v16.bin

They executed successfully and the LCD shows "bot 16" after the first and "app 16" after the second command. I can also see some bluetooth beacons with "hcitool lescan --duplicates".

The problem starts when i try to connect to the device through this webpage from yours: https://pvvx.github.io/THB2/web/PHY62x2BTHome.html

I started the page in chromium on android to get the bluetooth web api and can see my device in the list. But when i try to connect to the device i get an connection failure error.

These are the screens from my android device: Screenshot_20240401-201055 Screenshot_20240401-201241

The translation of the messages doesn't help me at all where the problem could be.

Maybe you have a hint for me what i can try to connect to the device.

Thanks Rainer

pvvx commented 3 months ago
  1. On Linux, you must configure Bluez to be compatible with the Bluetooth SIG standard. This is done in the Bluez configuration files. Connection delays must be set to the required 10 seconds to comply with Bluetooth standards. Taking into account the possible missed reception - by 22 seconds. Also add the ability to run Bluez in "experimental mode". Otherwise it doesn't work with BLE. Bluez only supports BT4.2 released in 2014. And today this is completely outdated software, like most of the applications and APIs, including the Linux kernel itself.
  2. To quickly connect, you need to briefly press the button on the thermometer. A short press of the button shortens the BLE advertising transmission interval to one and a half seconds. The action lasts 80 seconds to enable scanning and connection to the thermometer on non-standard devices and for Linux (Bluez).
  3. Connecting to a device requires more battery power. Check the battery level.
  4. The internal clock of PHY chips is unstable. Programmatic adjustments are made over hundreds of advertising periods. The Chinese SDK contains a poor implementation of the correction algorithm. Changes made to this algorithm showed better results, but the discrepancies for all chips are unknown. Try connecting several times. There may be an adjustment.
rainer38 commented 3 months ago

I flashed the other 9 devices and i can connect to all of them. Only to the first one i can't connect. But this is not a great problem compared to how cheap they were.

Thanks for your help and the ticket can be closed.

pvvx commented 3 months ago

Try writing with erasing the entire flash (option -a):

python3 rdwr_phy62x2.py -p COMxx -a -r wh BOOT_xxx_vxx.hex

Areas protected from normal erase may contain some settings that are incorrect (RF, ADC).

rainer38 commented 1 month ago

Sorry for the late answer but now it works. Today i reflashed v1.7 with your command and i can connect to the device.

Thanks for the help.