I'm trying to create a page for a LAN-connected device that will issue the shutdown command to the device (a Raspberry Pi) and show a loading bar telling the user to wait 5 seconds before unplugging the device. The only problem is that no matter in what way I execute the script, it always shuts down before the page has the chance to load on the client-side.
The front page of the client-side "website" has a button saying "Shutdown", and when I click that, it should first load the shutdown page which shows the loading bar and the message. Then, once the page has loaded so the user can actually see it, it should execute the script. I don't believe the Pi has to be on for the page to remain on the screen and for the JavaScript that controls the loading bar to remain, so I think the page is just executing the script before it has a chance to render, and thus, I get a connection interrupted message instead of the expected page.
I've tried the following methods:
- Setting the form action of the shutdown button to the Python script which prints "Location:http://soandso/shutdown.html" and then issues the "sudo shutdown now" command with the os module.
- Setting the form action of the shutdown button to the page itself, then putting a script tag with the src attribute set to the script location in the page. Have tried this in both the header and at the bottom of the body.
- Using an XMLHttpRequest to call out to the shutdown.py script after the timeout on the page is created for the loading bar to ensure that it is not executed until the page has at least loaded (the timeout setup is called from the body onload attribute).
None of these work, and my connection is always interrupted before the page gets to load. What else could I try?
from Wait for Page Load Before CGI Script is Loaded?
No comments:
Post a Comment