esp8266-react icon indicating copy to clipboard operation
esp8266-react copied to clipboard

Question: show connectivity, auto re-connect when offline

Open proddy opened this issue 2 years ago • 13 comments

Hi Rick,

Some of the people using my EMS-ESP project get confused with the System/Restart feature where it says 'Device is restarting', the ESP reboots but the web page is not refreshed. It's a trvial thing, but the same happens with uploading firmware where you need to refresh the page when you think it's done.

So I was thinking what's the best way to check for connectivity to the web server and do retry's when it's offline. I would probably use WebSockets but before I embark on this I'm interested in how you would approach it?

proddy avatar Nov 03 '21 11:11 proddy

Yes,

I suppose I'd poll every few seconds until the device responds, perhaps up to a timeout of a minute, after which I'd display a message saying the device is taking longer than expected to restart.

Though it would be nice to go further and have a firmware checksum or version on that page so you can see what's going on after the flash was successful.

On Wed, 3 Nov 2021, 11:21 Proddy, @.***> wrote:

Hi Rick,

Some of the people using my EMS-ESP project get confused with the System/Restart feature where it says 'Device is restarting', the ESP reboots but the web page is not refreshed. It's a trvial thing, but the same happens with uploading firmware where you need to refresh the page when you think it's done.

So I was thinking what's the best way to check for connectivity to the web server and do retry's when it's offline. I would probably use WebSockets but before I embark on this I'm interested in how you would approach it?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rjwats/esp8266-react/issues/260, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKE4VF7ECO226TFUSIBFKDUKEKWRANCNFSM5HIUXWYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

rjwats avatar Nov 03 '21 15:11 rjwats

ok, I'll give it a shot

proddy avatar Nov 03 '21 16:11 proddy

Was this still on your TODO list? Sounds like a good one and I have some ideas about how this might fit in to a UX refresh after the release of the new UI.

rjwats avatar Dec 01 '21 19:12 rjwats

yes, it was. It's kind of an important one for my project and often requested. It'll also fix the annoying issue when after a firmware update the UI is not automatically refreshed (I'm pushing out updates weekly). I was going to base it off this code. But won't get to it soon as I'm still struggling getting the event source not to skip messages (and reading up on when to use Memo and Callback hooks)

proddy avatar Dec 01 '21 20:12 proddy

@rjwats any thoughts on how to trigger a UI refresh after a successful firmware upload? Either via the heartbeat socket check or just hardcoded to trigger after the fileupload. This is an important one for me as I'm pushing out web UX changes every few weeks and my users (which I think could well be a few hundred now) always complain about not immediately seeing the latest UX changes. doh.

proddy avatar Dec 15 '21 14:12 proddy

I would show a spinner while I poll the "features" endpoint probably (because that endpoint is always present regardless of which features are enabled). I'd use a fairly short axios timeout, for a period of up to a couple of mins until the endpoint returns a 200 OK.

Then I would restart call document.location.reload() or force the document location to '/' on success to force the reload :)

Happy to knock together a PoC :) - i'm off till 2022!

rjwats avatar Dec 15 '21 16:12 rjwats

Lucky you! If you wouldn’t mind coding a small stub that would be super helpful. I don’t have any time off this year (new job)!

On Wed, 15 Dec 2021 at 17:25, rjwats @.***> wrote:

I would show a spinner while I poll the "features" endpoint probably (because that endpoint is always present regardless of which features are enabled). I'd use a fairly short axios timeout, for a period of up to a couple of mins until the endpoint returns a 200 OK. I think this

Then I would restart call document.location.reload() or force the document location to '/' on success to force the reload :)

Happy to knock together a PoC :) - i'm off till 2022!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rjwats/esp8266-react/issues/260#issuecomment-994952178, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJMO6BU37WMEZOX4TZZFITURC6PFANCNFSM5HIUXWYQ .

proddy avatar Dec 15 '21 18:12 proddy

https://youtu.be/bYe4CQ9zeh8

rjwats avatar Dec 16 '21 15:12 rjwats

Awesome! very fancy. So how long did that take you? I like the redirect route at the end. Also while we're (you are) at it is there way to verify the firmware with a CRC check?

proddy avatar Dec 16 '21 17:12 proddy

The verification check is an intresting one isn't it. Possibly generating an sha512 signature for the artefact and verifying that would be the way to go. The signature could be optional, and sent as a header on the file upload, and verified if supplied.

Should be as simple as calling md_update for each segment of the payload, and at then verifying it at the end before calling Update.end(true):

image

rjwats avatar Dec 16 '21 17:12 rjwats

Oh, and it took about an hour, just really needed to write a polling component 👍

rjwats avatar Dec 16 '21 17:12 rjwats

I've been using the firmware upload monitor a lot and can say it works flawlessly, a good 1 hour spent!

proddy avatar Dec 19 '21 09:12 proddy

Nice to hear. It's definitely better to have the feedback in the UI :)

On Sun, 19 Dec 2021, 09:07 Proddy, @.***> wrote:

I've been using the firmware upload monitor a lot and can say it works flawlessly, a good 1 hour spent!

— Reply to this email directly, view it on GitHub https://github.com/rjwats/esp8266-react/issues/260#issuecomment-997354266, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKE4VHWYDOSPQHU63QHAADURWOF5ANCNFSM5HIUXWYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

rjwats avatar Dec 19 '21 10:12 rjwats