Dynamic content can be generated at run-time on your NetBurner device. For example, you can a web page for an instrument in which the content changes to match the current state of the instrument, such as gauges, light indicators, switches, etc. This can done by creating a web page and inserting a variable, JavaScript, or generating the entire page. There are many examples of this in the folder.
The methods for creating dynamic content are:
When the web server encounters a CPPCALL tag it will call the corresponding function in your application code. Note that the space characters are important: ``
In your application source code create a function with the signature:
For example, to display the web client IP address and port number that made the web page request:
In your application:
Prior to the 2.8.x development tools release the function call tags were called as C functions instead of C++ functions. For reverse compatibility the tag can still be used. To prevent C++ name mangling you must add the extern “C” declaration at the top of your application file for each of your web functions. For example,
The VARIABLE tag has two uses:
To display a variable the format is:
Where <name>
is the name of the application variable or an expression. For example, the system time tick variable, TimeTick can be displayed with
Or you can display the time in seconds with the equation
The VARIABLE tag is processed during the compilation of the application by parsing the text between “<!—VARIABLE”
and the trailing “ -->”
, then the NetBurner tools automatically convert it into a function call with a signature that contains a file descriptor and variable. For example, ( fd, TimeTick/TICKS_PER_SECOND );
The following parameter types are defined by the functions located in .h:
The functions that are created from the VARIABLE tags are located in an auto-generated file named htmldata.cpp. Since these functions reference the variable names, there must be a way for the linker to resolve them. For example, to display TimeTick the application would need to include <nbrtos.h>, otherwise a linker error will occur.
Include files can be handled two ways: you can use an <INCLUDE headername.h> tag in the HTML code, or you can create a header file in your project with the name “htmlvar.h” that will be automatically included if no tags are detected in the HTML source code.
An example htmlvar.h file that exposes two variables, the <nbrtos.h> header file, and a function that takes an integer parameter is shown below:
An example HTML file using the INCLUDE tag:
If you need to specify a function call, but need to pass a parameter, the CPPCALL and FUNCTIONCALL tags will not work because the parameters are fixed as the socket file descriptor and URL. In this case we can use the VARIABLE tag to achieve the functionality of calling a function with a variable.
The include file (e.g. htmlvar.h) must specify the function definition in the format below. In this case we are passing an integer value ‘v’. The first parameter must always be the socket file descriptor.
const char * myIntFunction(int fd,int v);
The HTML source code then used the VARIABLE tag with the function definition below. In this example we are passing the integer value of TimeTick.
When the application is compiled the function created will be: WriteHtmlVariable( fd, MyFunction(fd,TimeTick) );
This function returns an empty string, which will have no effect on the web page. An example of what a function might do is shown below:
The VARIABLE functionality can be extended to support user defined types, such as displaying a user defined structure or class. Let’s say you have a structure you want to display on a web page called myStruct:
In your include file add the function definition: void WriteHtmlVariable(int fd, MY_STRUCT myStruct);
Now you can display it on the web page with the VARIABLE tag:
What this look like behind the scenes is: WriteHtmlVariable( fd, myStruct );
Note that you still have to write the implementation of the above function. The function below is the source code for the MAC address type already defined by the system: