It is quite common that when a command has been received via the web interface, the information for the displayed web page is not immediately available.
Examples are when data has to first be collected from external devices via a serial interface or another Ethernet based protocol.
In such cases a method is required which allows the resulting web page to be sent after all details have become available - this is called DELAYED SERVING in the uTasker project. The following illustrates a typical example application and its use:
First of all, ensure that #define SUPPORT_DELAY_WEB_SERVING
is active in config.h
(in the HTTP section) so that the support is enabled.
In the handling routine fnHandleWeb() we assume that there is support for toggling output ports, which may look like this:
case 'O': // toggle out bit states
fnEventMessage(MY_TASK, OWN_TASK, E_TREAT_NEW_PORTS); // send an event to my task
return DELAY_SERVING; // delay serving the page until the event has been handled
This example toggles an output port based on the input to fnHandleWeb()
. Depending on the output state, and the reaction of an external piece of equipment
, the state displayed when returning the web page can be different. It may take a short time before the new state is stable and so the return value is set to DELAY_SERVING
. This will stop the default web page from being returned immediately and the TCP connection will remain open in this state until ready. In this example an event is sent to a task which will be handling the detail about determining the final state.
The task “later” causes the web page to be served by calling: fnServeDelayed('B', 0);
‘B’ is the file reference to be served (it can thus also cause different web pages to be served based on the actual state determined). Since the details of the web page content are also now known and stable, the content will be correct even if they have taken some time to have been collected.