Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Submitting a new plugin
#10
(2023 Jan 28, 12:31 AM)RandyBryant Wrote:
(2023 Jan 27, 03:55 PM)dan Wrote:
(2023 Jan 26, 03:56 PM)RandyBryant Wrote:
(2023 Jan 26, 03:18 PM)dan Wrote: Hi Randy,

The problem of certain changes not showing up in the UI until a page refresh is due to the fact that the changes happen on the server (raspberry pi) side and are not pushed to the browser until a refresh is done.

I have been looking into a way for the server to cause a page refresh on the browser but I have not found a simple solution. If you have any ideas on how to accomplish this I would be very interested.

Dan

I have limited WEB programming experience, but I'll investigate.

What causes the station updates when the keypad starts a program run?  The run times/status shows up with out doing a refresh.

Randy

The way the stations are updated when a program is running is that the home page requests a status update from the server once a second (templates/home.html line ~76). It gets an update from the api_status class in webpages.py (line ~645) which sends a JSON formatted list of status data. JavaScript on the home page updates the display.

You can see the status data at <SIP url>/api/status

I have been tinkering with HTML Server-Sent Events (SSE) to force a page refresh on the browser. One big problem is that if a plugin changes the value of a SIP variable there is no easy way to detect the change unless the plugin notifies the core program.

Dan

I have a little headway in try to understand the WEB interface and status updates.

Turns out the following code return not only the station running info, but a few system status items too:

class api_status(ProtectedPage):
    """Simple Status API"""

    def GET(self):
        #print("api_status GET")
        statuslist = []
        status = {
            "systemName": gv.sd["name"],
            "systemStatus": gv.sd["en"],
            "waterLevel": gv.sd["wl"],
            "rainDelay": gv.sd["rd"],
            "mode": gv.sd["mm"]
        }
.
.
.
                                    status["status"] = "waiting"
                                    status["reason"] = "program"
                                    status["programName"] = pname
                                    status["remaining"] = rem
                    else:
                        status["reason"] = "system_off"
                    statuslist.append(status)
        web.header("Content-Type", "application/json")
        #print("    returning '{}'".format(statuslist))
        return json.dumps(statuslist)

When the keypad runs a station this status return to a /api/status request, returns the system info too.  It just doesn't get updated by the Gui.  I don't understand how the program data causes the home.html to repaint the program info:

    function statusTimer() {
        jQuery.getJSON("/api/status", updateStatus)
    }

Is the request, and:

    function updateStatus(status) {
        let display, updateInterval = 5000;

        console.debug("SIP home.html: status.length = " + status.length);
        for (let s=0; s<status.length; s++) {
            let station = status[s];
            let classes = "noNewline stationStatus station_" + station.status;

            if (s == 0) {
                let system = status[s];
                console.debug("SIP home.html: system status = " + system.systemStatus);
                console.debug("              system name = " +  system.systemName);
                console.debug("              water level = " +  system.waterLevel);
                console.debug("              rain delay = " +    system.rainDelay);
                console.debug("              mode = " +          system.mode);
            }
            else {
                console.debug("SIP home.html: station " + s + "; status = " + station.status);

                switch (station.reason) {
                    case "program" :
                        let minutes = Math.floor(station.remaining / 60);
                        let seconds = Math.floor(station.remaining - 60*minutes);
                        if (minutes < 10) {minutes = "0"+minutes;}
                        if (seconds < 10) {seconds = "0"+seconds;}
,.
.
.

            jQuery("td#status" + station.station)
                .text(display)
                .removeClass()
                .addClass(classes);
        }

        setTimeout(statusTimer,updateInterval);

        if (updateInterval > 1000) {
            displayProgram();
        }

Updates the program/station part of the Gui.

So how do I get it to also repaint the other information?

Updating part of a page can be done with JavaScript but in some cases it is necessary to refresh the entire page.
In home.html line ~179 there is some code to do that:
Code:
        function refreshPage() {
            window.location = "/";
            }
I should point out that the "$" symbol is often used for jQuery but in SIP (web.py) templates that symbol is used for embedded Python code:
https://webpy.readthedocs.io/en/latest/templating.html
<p><br></p>
Reply


Messages In This Thread
Submitting a new plugin - by RandyBryant - 2023 Jan 09, 11:24 PM
RE: Submitting a new plugin - by dan - 2023 Jan 10, 12:18 AM
RE: Submitting a new plugin - by RandyBryant - 2023 Jan 21, 12:35 AM
RE: Submitting a new plugin - by dan - 2023 Jan 21, 04:32 PM
RE: Submitting a new plugin - by RandyBryant - 2023 Jan 25, 08:32 PM
RE: Submitting a new plugin - by dan - 2023 Jan 26, 03:18 PM
RE: Submitting a new plugin - by RandyBryant - 2023 Jan 26, 03:56 PM
RE: Submitting a new plugin - by dan - 2023 Jan 27, 03:55 PM
RE: Submitting a new plugin - by RandyBryant - 2023 Jan 28, 12:31 AM
RE: Submitting a new plugin - by dan - 2023 Jan 28, 04:18 PM
RE: Submitting a new plugin - by RandyBryant - 2023 Jan 28, 05:46 PM
RE: Submitting a new plugin - by RandyBryant - 2023 Jan 29, 05:06 PM
RE: Submitting a new plugin - by dan - 2023 Jan 30, 05:32 PM
RE: Submitting a new plugin - by RandyBryant - 2023 Jan 30, 05:55 PM
RE: Submitting a new plugin - by dan - 2023 Feb 01, 08:12 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)