Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

online_check should do active query #23

Open
mtfurlan opened this issue Feb 15, 2020 · 13 comments
Open

online_check should do active query #23

mtfurlan opened this issue Feb 15, 2020 · 13 comments

Comments

@mtfurlan
Copy link
Member

pio spent a while telling me it should update after flashing, so the device came online before the online check started.

@mtfurlan
Copy link
Member Author

Apparently you cannot query info2, the recommendation is to use status5.

@mkfink
Copy link
Member

mkfink commented Feb 15, 2020

Yeah, the platformio messages in the middle have tripped me up before. That usually only happens once, but I agree building around that is a good idea.

If querying status, need to make sure that the device 1) did just come online within the past minute or so, and 2) that it was flashed just prior to that. We can query status2 since that includes BuildDateTime so we can compare against that.

stat/i3/inside/hallway/light/STATUS2 {"StatusFWR":{"Version":"6.7.1(sonoff)","BuildDateTime":"2019-11-08T11:20:14","Boot":6,"Core":"STAGE","SDK":"2.2.2-dev(38a443e)"}}

So I think it should be

  1. flash
  2. watch for INFO2
  3. if that times out, actively poll for status2 and verify BuildDateTime
  4. if no respponse, give up

@mkfink
Copy link
Member

mkfink commented Feb 19, 2020

Feature is added, accidentally included in commit d6697e7#diff-2c1c94d4c8d410c526a8bc27999ac770R345

@mkfink mkfink closed this as completed Feb 19, 2020
@mtfurlan
Copy link
Member Author

Huh, I thought I said something about this a few days ago, but why not poll status2 as soon as we start watching for info2, so if it is online we don't wait for a timeout?

@mkfink
Copy link
Member

mkfink commented Feb 19, 2020

Oh yeah. I thought about that, but if we run query_tas_status that can block for up to 3 seconds if it doesn't get a response, so if the device came online right after the status query but in that 3 second window we'd miss it.

@mtfurlan
Copy link
Member Author

But if we do it after we've subscribed, we would still get the INFO2?

@mtfurlan
Copy link
Member Author

I'm thinking

  • subscribe INFO2
  • subscribe STATUS5
  • publish status 5
  • wait a while

@mkfink
Copy link
Member

mkfink commented Feb 19, 2020

Should be status 2, not 5. How about this: 0f9c42b

@mkfink mkfink reopened this Feb 19, 2020
@mtfurlan
Copy link
Member Author

-                if dt.datetime.now() - build_time < dt.timedelta(minutes=2):
-                    self.online = True
+                self.online = not too_old(build_time, 120)

?

@mkfink
Copy link
Member

mkfink commented Feb 19, 2020

Oh, sure, that works

@mtfurlan
Copy link
Member Author

Looks good to me then.

@mkfink
Copy link
Member

mkfink commented Feb 19, 2020

So there is a minor race condition I just hit testing this. Apparently there is a short time after you flash a device and before it reboots where it still responds to commands. So status 2 fired, the device replied, device started to reboot, and the script started sending commands that weren't received. This should only happen if you're flashing something for the second time within 2 minutes, but I do tend to do that sometimes, so maybe there should be a short delay before publishing status 2?

@mtfurlan
Copy link
Member Author

That's super weird.
A delay probably will work all the time?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants