PLC Webserver: Resolving Stale Values After Disconnect

Karen Mitchell2 min read
HMI ProgrammingOther ManufacturerTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

A polled PLC web page can continue displaying the last successful values after communication fails. Prevent operators from mistaking stale data for live data by handling the JSON request failure and replacing every displayed value with a defined fallback.

Identify the Stale-Value Failure Mode

The browser uses setInterval to request PLC data from IOCounter.htm. A successful request updates the page, but a lost connection leaves the previously rendered values unchanged unless the request error path explicitly changes them.

The evidence does not distinguish among loss of Internet access, loss of the webserver, and loss of the PLC data path. The implemented safeguard therefore detects failure of the browser request to IOCounter.htm; it does not diagnose which network component failed.

Define Success and Failure Behavior

Request result Display action Gauge action
JSON request succeeds Trim and display uno through ocho Refresh g1 from cinco
JSON request fails Set all eight displayed values to 0 Refresh g1 with 0

Zero is a communication-failure fallback in this implementation. If zero is also a valid process value, the display alone cannot distinguish a genuine zero from lost communications; add a separate communication-status indication when that distinction matters.

Handle the JSON Request Error

  1. Keep the normal updates inside the successful $.getJSON callback.
  2. Attach an error callback that writes zero to every displayed point and refreshes the gauge with zero.
$.getJSON("IOCounter.htm", function(result) {
    $('#uno').text($.trim(result.uno));
    $('#dos').text($.trim(result.dos));
    $('#tres').text($.trim(result.tres));
    $('#cuatro').text($.trim(result.cuatro));
    $('#cinco').text($.trim(result.cinco));
    $('#seis').text($.trim(result.seis));
    $('#siete').text($.trim(result.siete));
    $('#ocho').text($.trim(result.ocho));
    g1.refresh($('#cinco').text());
})
.error(function() {
    $('#uno').text(0);
    $('#dos').text(0);
    $('#tres').text(0);
    $('#cuatro').text(0);
    $('#cinco').text(0);
    $('#seis').text(0);
    $('#siete').text(0);
    $('#ocho').text(0);
    g1.refresh(0);
});

Verify the Fail-Safe Display

  1. Confirm that a successful request updates uno through ocho and that g1 follows cinco.
  2. Interrupt browser access to IOCounter.htm and confirm that all eight values and g1 change to zero instead of retaining their last readings.
  3. Restore access and confirm that the next successful poll replaces the fallback zeros with returned PLC data.

FAQ

Why does my PLC web page keep showing values after disconnecting?

The browser retains the last rendered values when a later JSON request fails. Add a request error handler that explicitly replaces those stale values.

How do I set PLC webserver values to zero after a JSON error?

In the $.getJSON error callback, call .text(0) for uno through ocho and call g1.refresh(0).

Does a failed request identify whether the PLC or Internet connection is down?

No. It confirms that the browser request to IOCounter.htm failed, but the available evidence does not isolate the failed network component.

Back to blog