-
Notifications
You must be signed in to change notification settings - Fork 31
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
radio BLE issues with all THB1 #74
Comments
wonder if this could be related: #38 (comment) |
Some more feedback, that makes a huge difference for the majority of the devices. Around 80% work now after clearing the whole flash once:
Is that something that helps to solve an underlying problem with tunings, maybe for the remaining devices where this does not help? |
THB01 - what is this variant? On some PHY6222 series chips, the RC oscillator is unstable. |
Reprogramming BOOT v1.4 -> v1.8. 20:03:13: Ожидание соединения с THB1-4ACDD9 Connect BOOT v1.8 and re-OTA THB1_v18. 20:07:20: Ожидание соединения с THB1-4ACDD9 The tested thermometers on PHY6222 all work stably. Nothing disappears in HA BTHome. |
Thank you for checking with your devices! That proves that the code is working. And after clearing all flash with -a flag, most devices I have can be connected. |
Under the Tuya brand, devices are produced from various junk. Tuya devices do not have any guarantees or certificates. The PHY documentation mentions the capacitance in the RF part power supply for RF stability. It is not known what they put in the device assembled from junk. It is also not known what PHY chips were used. They may be from a defective batch from the factory... I bought devices with PHY from different suppliers for testing. Only a couple, where the PHY6222 chip had a different marking from the others, worked unstably. Because of them, I had to rewrite the SDK functions for correcting the RC clock to my own, having extended ranges and an algorithm. According to other users, there were only 2 chips that had problems with the RC generator. These users simply threw them away - there is no point in messing around with defective chips. The PHY6222 chip itself has several unfixed problems. One is an unstable RC oscillator, with a departure that does not comply with the BLE standard, another problem is in the delays of the radio frequency part... But the largest number of errors are in the program ROM. That's why it is cheap. Tuya partially checks only modules with PHY6222, which it sells as OEM. But these thermometers are assembled by small offices without any checks. You can register in Tuya yourself and sell any junk. It may also turn out that you have chips with a different revision of the ROM code... But there is a high probability that you are doing something wrong. |
I see your point that wasting time on cheap hardware doesnt pay off - however before I performed the -a full erase none of those devices did work. Now at least 80% work as expected. So I don't see what I should do wrong here. Here is an example of a problematic device. Those devices light up the bluetooth icon for about 1s then the connection is dropped. No stable connection possible.
|
Are you using the same batteries in each device? Seems like it's more sensitive to supply voltage than it should be, so batteries that happen to have a different voltage might be the cause of a problem in one device rather than the device itself. |
This is powered at 3.3V via USB. Also tried lower voltages of 2.5V or even batteries. Same behaviour. |
When I powered a BTH01 from the USB serial adapter it did not work reliably. Interval between BLE beacons was inconsistent. Attempting to connect would rarely succeed. And once connected it would last a most a few seconds before being disconnected. Just removing all soldered wires and changing to batteries (NiMH now at 2.65 V) has fixed it. Interval between received beacons is now a multiple of 5 seconds. Once connected it stays that way for hours. Connecting is not perfectly reliable, but I think this is caused by the long connection interval with a too short timeout on the host. |
Interesting! So you are saying reducing the default setting of the interval should improve the likelihood for a successfull connection? |
Для подключения в Linux необходимо установить стандартные интервалы (Bluetooth v4.0..5.4) в файлах конфигурации Bluez. By default, Bluez for Bluetooth has intervals invented by the assemblers that do not correspond to the standard. |
Yes, button works for me. This is with batteries. Same device on USB serial cable power was nearly useless. There are lots of reasons that power from an USB-serial cable could cause problems beyond voltage. Batteries provide a very clean low noise supply. Cheap USB serial cable does not at all. A good device will have a well designed power supply filter caps and work on less than perfect power from the USB serial adapter. But will a Tuya device have extra capacitors that shouldn't be absolutely necessary on battery power? Of course not. |
There is no stability from the battery under pulse load. For example, a half-discharged CR2032 has an internal resistance of 100 Ohm. The current of the BLE device changes from 2 μA to 8 mA. Accordingly, the supply voltage jumps by 0.8 V (3.0V -> 2.2 V). |
The connection is stable for ~1s before it drops, visible via the icon. |
The RC oscillator is corrected with a drift of 20%. Large deviations are not taken into account in the average deviation. The Bluetooth Core Specifications Version 5.0+ require the active clock to have a drift less than or equal to ±50 ppm. It is impossible to get such accuracy in PHY62xx chips from RC oscillator. |
This is more related to the constants of different intervals in the SDK and the receiving adapter. If you select coefficients for your chip, then such correction will not work on others. And on your chip, when changing the supply voltage, you will have to rebuild the SDK with new constants again. https://github.com/pvvx/THB2/blob/master/bthome_phy6222/SDK/lib/rf/patch.c#L7716-L7909 These constants are applied as a patch to the program in the ROM of the chip, since in ROM they are also incorrect. They depend on everything. On CPU frequency, clock frequencies of other counters, RF part delays, internal voltages, RC generator drift, supply voltage and temperature. This chip is PHY6222. Each time the chip wakes up from sleep, the RC stroke to the quartz generator is calculated and the RC generator count coefficient is dynamically corrected. But when the chip is asleep, the supply voltage is 3.0 V, and when waking up from sleep, it is 1.9..2.8 V depending on the battery state. And in different chip modes, sleep or active operation, the internal supply voltages of the units change to achieve minimum consumption during sleep. In this case, the RC generator changes its stroke significantly. The RC generator correction procedure from any РHY SDK failed to cope with its task. Half of the purchased Tuya devices on PHY6222 did not maintain communication at all at a supply voltage of more than 2.4V. I had to change (increase) the RC generator spread thresholds and replace the correction algorithms. Only then did all the PHY6222 devices that I had at least somehow maintain communication at supply voltages of more than 2.5V. I don't want to waste any more time digging around and fixing faulty chips. Such instability of the main power supply of the chip (and DC-DC work) after sleep during the transition to activity... You can do it yourself if you have a lot of extra time. |
Amazing work with this project @pvvx - really appreciating and exiting!
I bought 6x THB01 and all show the same connection issues. Right from the first BOOT flash it is almost impossible (maybe 1 of 30 attempts) to connect to the devices to try OTA. So I went ahead with UART flashing .... However, the BLR connection is so extremly fragile, it disconnects after few seconds. OTA is basically impossible, I was only once (from 100x tries or so) able to do, trying to downgrade to 1.7 FW (if that solves the issue but no).
Tried with 2 different Windows Laptops and 2 different Android devices, tablet and phone.
One day later all devices stopped to announce via BLE now! Even with NRF connnect I can only guess by the RSSI which devices they are, connection impossible. I tried power unplug, oder batteries and of course pressing the button.
I sounds to me the PLL for the Radio might have an issue.
Any idea please, is it possible that the BLE setup is broken
The text was updated successfully, but these errors were encountered: