Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of pyend instruction for execution of commands right after page serving #68

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ftylitak
Copy link

This commit adds support of a new instruction {{ pyend }}. {{ pyend }} behaves exactly as the {{ py }} in the manner of including code that will to be executed. Its only specialty is that the code included in the instruction, will be executed in a separate thread after the "generated" html from pyhtml has been served.

Usage: we use it in a microcontroller Web based UI for easy configuration. During the final step of the configuration wizard, the configurations are saved and the device gets rebooted to apply new configuration. In the {{ pyend }} we add the code to wait for a period of time and then power off/on the controller. Its benefit is that the pyhtml page includes a success message, which is first served and then the device gets rebooted, enhancing User Experience.

image

The alternative of not using this, would be either not to show a success message or to load a new page that would include the reboot code in a {{ py }}.

    {{ pyend }}
      import machine
      import utime

      start_time = utime.ticks_ms()
      WAIT_UNTIL_REBOOT_MSEC = 3000
      while (utime.ticks_ms()-start_time < WAIT_UNTIL_REBOOT_MSEC):
              utime.sleep_ms(1000)

      machine.reset()
    {{ end }}

We do not know if this is something that you consider useful though we have been using this for a while and we thought it would be better to share.

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

Successfully merging this pull request may close these issues.

1 participant