alessandro308/YeelightController

Hey Think I get the problem.

Opened this issue · 2 comments

Hey. Me again. I got the code to Build. (y).
I think I see the problem. Unfortunately, I don't speak a "Line" SWIFT, but i have an idea how you can fix it. Here is what I would do:

Create a global counter in the readReplay function. (Every time it gets called ++...)

Now every time you get responses store it before you parse it. ( or If the first replay is always readable - read it. - but with the counter you always know how often it ran)

if the readReaply runs the second time. Store the data again. Then compare both replays. (as a string, or len or whatever suits you. Then you can validate the Reply. and only parse the reply you need. ;) this is at least what I would do in python :D

Yeah, I think that this solution should work.
Of course, with this solution, we aren't able to manage multiple bulb (that is not my problem) but I will try to implement this logic in the future!

I was thinking another solution. Execute a separate thread that reads only the incoming connections. Parse and store the messages received in a queue. Then the main thread, if there are new incoming messages, process them and update the interface. Do you think that this works?