orgua / OneWireHub

OneWire slave device emulator
GNU General Public License v3.0
343 stars 86 forks source link

Livolo thermostat sensor emulation #84

Closed eigenein closed 4 years ago

eigenein commented 4 years ago

Hi,

This is rather knowledge sharing because I found nothing over the Internet, but should you have some insights – this would be helpful for me.

I got a Livolo thermostat which has an internal DS18B20. Since I already have an NTC thermistor mounted into my floor, I have soldered out the built-in Dallas and decided to make a NTC-to-OneWire adapter with a Chinese Arduino Nano board.

I have tested the thermostat with an external real DS18B20 and it worked fine.

The Livolo has pretty weird 1-Wire master implementation. I spent pretty much an entire weekend to fine-tune the timings and went to the following:

// The master sends out too long reset signal,
// `35000_us` is the lowest value that worked.
constexpr timeOW_t ONEWIRE_TIME_RESET_MAX[2] = {   50000_us, … };

// Otherwise, you get `AWAIT_TIMESLOT_TIMEOUT_HIGH` and/or `FIRST_BIT_OF_BYTE_TIMEOUT`
constexpr timeOW_t ONEWIRE_TIME_MSG_HIGH_TIMEOUT = { 30000_us };

// Otherwise, you get `INCORRECT_ONEWIRE_CMD`.
// I assume this is because then it's read incorrectly.
constexpr timeOW_t ONEWIRE_TIME_READ_MIN[2] = {    35_us,  … };

I also changed hub->send(scratchpad, 9); to hub->send(scratchpad, 2); since the thermostat only reads 2 bytes. Otherwise I get FIRST_BIT_OF_BYTE_TIMEOUT.

This gives correct and stable measurement displayed on the thermostat (except for rare VERY_SHORT_RESETs).

~And now the most weird part which I haven't solved yet.~ Irrelevant, see the closing comment below.

In exactly 3m 36s after I plug the thermostat into a wall socket something happens inside the Livolo. It starts to read a measurement in a stably incorrect way. Examples:

So it looks like it misreads some bits. But there're a couple of things that totally confuse me:

It seems like there's some hidden state inside the Livolo that refreshes every 3-4 mins and somehow affects only me but not a real Dallas.

I tried to play with the other timings to no avail. Nothing changes except that extreme values break readings at all. At the moment I'm kinda stuck and it maybe I won't finish it ever. Now just making wild guesses and waiting for a logic analyser delivery. But the above might help other people.

I'll add comments if I know anything new.

eigenein commented 4 years ago

I got him.

It turned out that the thermostat is buggy. When I soldered the built-in Dallas back and turned it on, displayed value jumped from a correct one to a random one at 3m36s. Looks like a buggy firmware whatever. Gonna communicate that to the manufacturer.

Anyway, the timings above will be helpful to anyone who wants to go the same way.

tobiaswaldvogel commented 3 years ago

As mentioned before the thermostat looks nice but the software is totally buggy. I wrote a new firmware from scratch which addresses all this and much more.

https://github.com/tobiaswaldvogel/livolo-thermostat