HTTP Server Protocol
See also: Ethernet Configuration Overview
Topic Menu
HTTP Server Protocol Overview
Note: This is a Non-Industrial Ethernet Protocol.
Note: The HTTP functionality covered in this chapter is not the same as the WebMI WebMI – Web-Machine Interface - An HTML5-based HTTP server, where access to data and visualizations is enabled from anywhere via web clients. WebMI empowers users to control everything onscreen from a computer, tablet, or other mobile device. functionality also available for many OCS products. The HTTP protocol section should not be checked if WebMI is to be used. Link: WebMI Manual
Hypertext Transfer Protocol (HTTP) is a standard Client/Server Internet protocol, based on RFC1945, which transfers web content over a TCP/IP TCP/IP – Transmission Control Protocol / Internet Protocol - A transport layer protocol and a network layer protocol developed by the Department of Defense. This is a commonly used combination for communication within networks and across internetwork. network. In this context, the OCS acts as an HTTP Server (web content provider), which responds to requests from HTTP Clients (web browsers). The OCS’s HTTP Server supports optional HTTP Client authentication, requiring the web browser operator to enter a Username and Password, before web content can be accessed. Properly authenticated, an HTTP Client can access web content previously stored in the OCS file system. This web content can include standard static HTML files and other web resource files. In addition, the HTTP Server allows the HTTP Client to display and edit OCS register data, by embedding specially named dynamic HTML files (readreg.htm and writereg.htm) into a static HTML file.
HTTP Configuration
If the HTTP Web Server will be used in the application, HTTP Configuration must be performed, in addition to the general Ethernet LAN1 Configuration previously described in Ethernet Configuration Overview . To configure HTTP protocol, use Cscape Programming Software to perform the following five steps:
-
Open the Ethernet LAN1 Configuration dialog by selecting Home > Controller > Hardware Configuration (select a series and device type) > LAN1/Config.
-
Enable HTTP by checking the HTTP (Web Server) checkbox in the LAN1 Configuration dialog. Until this is done, the OCS will not respond to any HTTP Client requests.
-
Click on the Configure Selected Protocol button next to the HTTP (Web Server) checkbox to open the HTTP Configuration dialog. Refer to figure below.
-
Optionally, set up the HTTP Configuration parameters for User 1 as follows:
Note: Usernames and Passwords are case sensitive, and, by default, the Username and Password are empty. In this case, all HTTP Clients can access the OCS web content. In a typical application, the Username and Password should be configured for security purposes.
-
Click OK to accept the new HTTP protocol configuration.
Return to the Top: HTTP Server Protocol
HTTP Operation
After performing HTTP Configuration, as described in section 11.2, a 3rd party HTTP Client (such as a PC running Internet Explorer or Firefox) can be used to browse OCS web content.
To start browsing web resources stored in the OCS file system, enter the appropriate URL (Uniform Resource Locator) into the HTTP Client (web browser). As a minimum, the URL should include the target OCS’s IP Address and a filename. For example, if the OCS’s IP address is 192.168.254.128, the following URL will access the index.htm file in the OCS file system root directory: http://192.168.254.128/index.htm
Note: The HTTP Server does not automatically default to index.htm, if no file is specified in the URL. If the OCS was configured with a Username and Password, the browser will prompt for the User Name and Password to be entered, before opening the web page. Please refer to documentation provided with the 3rd party HTTP Client, regarding how to install, configure and operate the HTTP Client.
The OCS HTTP Server implements HTTP/1.0 and does not support persistent connections. Therefore, each time a web page (or other resource) is transferred, the following sequence takes place:
-
The HTTP Client (web browser) opens a connection with the HTTP Server and sends a request.
-
The HTTP Server sends a response to the HTTP Client and then closes the connection.
Since the connection only stays open long enough to complete one request, multiple HTTP Clients can concurrently access OCS web content, even though they are sharing a single connection.
Web Content - Storing
When storing web content files in the OCS file system, the user should know that the OCS file system implements an “8.3” filename format, which means all file and directory names must consist of up to 8 characters, followed by an optional dot, and an optional extension with up to 3 characters. Web content files can be stored into the OCS file system media (such as Compact Flash/microSD), by temporarily plugging the media into a PC with an installed card reader, or via Ethernet using FTP (File Transfer Protocol). See Chapter 10 for information on using the OCS FTP Server. To keep the web content files organized, multiple files, directories and subdirectories can be created on the OCS file system media as desired. Normally, it is a good practice to store an index.htm file in the root directory as a “home page”, but this is not required.
Web Content - Dynamic Data
An OCS HTML file is either static or dynamic. The application engineer creates a static HTML file and stores it on the OCS file system media. Because of special markups in the static HTML file, the HTTP Server creates dynamic HTML files to access OCS Registers. This technique allows a static HTML file to read and write OCS registers dynamically.
Static HTML Files
Custom HTML files are created to suit the application. These files can be created with a simple text editor or by using a 3rd party HTML Editor. Within the static HTML file, <iframe> and <form> tags respectively read and write OCS Register data, by referencing two specially named dynamic HTML files (readreg.htm and writereg.htm).
Dynamic HTML Files - Reading OCS Register Data (READREG.HTM)
OCS Register data is read by placing an <iframe> tag, that references readreg.htm, within a static HTML file. The following example <iframe> tag reads and displays OCS Register %R11 as an Unsigned Integer every two seconds:
<iframe src="readreg.htm;reg–R11;fmt–UINT;rfs–2"></iframe>
The required src attribute is a quoted string containing the readreg.htm reference and two or three parameters, all separated by semicolons. The reg, fmt and rfs parameters specify the OCS Register to read, the display format to use and optionally how often to refresh the data. These parameters are described in more detail in the following 3 sections.
REG Parameter - OCS Register Read Reference
Examples:
-
reg–R11
-
reg–R11.3
The required reg parameter is followed by a dash and an OCS Register reference. Register reference numbers start at 1 and the maximum depends on the register type and OCS type, as show in the following table:
OCS Register Read References | ||
---|---|---|
OCS Register Type | Maximum Reference (ETN200) | Maximum Reference (ETN300) |
%R Retentive 16-bit registers. | R2048 | R9999 |
%AI 16-bit input registers used to gather analog input data such as voltages, temperatures, and speed settings coming from an attached device., %AQ 16-bit output registers used to send analog information such a voltages, levels, or speed settings to an attached device. | AI512, AQ512 | AI512, AQ512 |
%I Single-bit input registers. Typically, an external switch is connected to the registers., %Q Single-bit output registers. Typically, these bits are connected to an actuator, indicator light or other physical outputs., %M Retentive single-bit registers., %T Non-retentive single-bit registers. | I2048, Q2048, M2048, T2048 | I2048, Q2048, M2048, T2048 |
%S Single-bit bit coils predefined for system use. | S16 | S16 |
Note: For BOOL Boolean- [Data Type BOOL] - A single bit, binary value, or register/variable. Boolean points have only two possible values, 'TRUE' or 'FALSE'. formatting (see next section), a bit number can be appended to 16-bit register references (%R, %AI and %AQ). For example, reg–R11.3 references bit 3 of register %R11. Valid bit numbers are 1 through 16.
Return to the Top: HTTP Server Protocol
FMT Parameter - OCS Register Read Format
Examples:
fmt–BOOL
fmt–BOOL–ON–OFF
fmt–BOOL–YES–NO
fmt–BIN
fmt–HEX
fmt–INT
fmt–UINT
fmt–DINT
fmt–UDINT
fmt–REAL
fmt–REAL–E
fmt–ASCII–10
fmt–IPADR
The required fmt parameter is followed by a dash and a display format type. Valid format types are BOOL, BIN, HEX, INT, UINT, DINT, UDINT, REAL, ASCII and IPADR. Three of these format types (BOOL, REAL and ASCII) have optional or required modifiers as follows:
-
The BOOL format reads and displays a single bit, and two optional modifiers indicate the text to display for the bit’s logical On and Off states. The text "TRUE" and "FALSE" will be displayed if the modifiers are omitted. In other words, fmt–BOOL is equivalent to fmt–BOOL–TRUE–FALSE.
-
The REAL format reads a 32-bit floating-point value, and the optional –E modifier can be used to display data in exponential (scientific) notation. The fmt–REAL format displays a variable number of digits to the left of the decimal point and 6 digits to the right of the decimal point (e.g. –12345.000000). On the other hand, the fmt–REAL–E format only shows 1 digit to the left of the decimal point and shows 6 digits to the right of the decimal point followed by a 4-character power of 10 (e.g. –1.234500E+04).
-
The ASCII format accesses a string of ASCII characters, and a string size modifier from –1 to –31 is required, indicating how many ASCII characters to read and display. For example, the fmt–ASCII–10 format reads and displays a string of 10 ASCII characters.
RFS Parameter – OCS Register Read Auto-Refresh
Example: rfs–2
The optional rfs parameter specifies how often the <iframe> should automatically refresh the data on the browser screen. For example, rfs–2 will cause the data to be refreshed every 2 seconds.
The number of seconds specified can range from 0 to the limits of the browser. A refresh time of 0 will refresh the data as often as possible, but this is not recommended because of the volume of Ethernet traffic it can create. If the optional rfs parameter is omitted, the data will only be refreshed when the user manually refreshes their web browser screen.
The rfs parameter uses a technique called “client-pull” to tell the web browser to do the periodic refresh. Not all web browsers support “client pull” and those that do support it can usually be configured to disable it for security purposes.
Note: When using an Internet Explorer browser to view OCS web pages that employ the rfs parameter, the browser plays the currently configured Start Navigation sound (a short “tick” by default) for each refresh. To disable the “ticking”, (1) open the Windows Control Panel, (2) click the Sounds or Sound and Audio Devices icon or link and (3) turn off the Start Navigation sound by selecting (None) for it in the drop-down list.
FNT Parameter - OCS Register Read Font
Example: fnt-5-arial-blue
The optional fnt parameter specifies the font size, typeface, and color to be used when OCS Register data is displayed on the browser screen. All 3 font attributes (size, typeface, and color) are optional, but must be specified in the order shown. For example, fnt-5-arial specifies a size 5, Arial font, but will use the browser’s default text color. If the size or typeface is omitted, its dash character should still be used as a placeholder. For example, fnt---blue specifies that the displayed text will be blue, but the browser’s default font size and typeface will be used.
Note: In this last example, there are 3 dashes between fnt and blue.
For the 1st attribute (font size), a number from 1 to 7 can be used, with 1 as the smallest and 7 as the largest. This is a browser limitation, as browsers typically support only 7 font sizes. Optionally, a point size can be specified, such as 12pt, but the browser will translate this into one of its supported font sizes. For the 2nd attribute (font typeface), any typeface name supported by the browser can be used, such as Arial, Times New Roman or Courier New. For the 3rd attribute (font color), the 16 standard HTML color names should always work. These 16 standard colors are aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white and yellow.
Return to the Top: HTTP Server Protocol
Dynamic HTML Files – Writing OCS Register Data (WRITEREG.HTM)
OCS Register data is written by placing a <form> tag, that references writereg.htm, within a static HTML file. The following example <form> tag sets up an Unsigned Integer write to OCS Register %R11:
<form action="writereg.htm;reg–R11;fmt–UINT" method="post">…</form>
Between the <form> and </form> tags, there should be one or more <input> tags that enable a browser operator to enter or select data and write it to the register.
For example, in the following complete <form> markup, the first <input> tag creates a text input box, containing a default value of 0, which allows the user to enter a new value for %R11. The second <input> tag creates a Send button, which can be clicked to submit the new value (write it to the register):
<form action="writereg.htm;reg–R11;fmt–UINT" method="post">
<input type="text" name="reg" value="0">
<input type="submit" value="Send">
</form>
In the following example, the first <input> tag creates an ON button that can be clicked to turn %T22 On, while the second <input> tag creates an OFF button that can be clicked to turn %T22 Off.
<form action="writereg.htm;reg-T22;fmt-BOOL-ON-OFF" method="post">
<input type="submit" name=”reg” value="ON">
<input type="submit" name=”reg” value="OFF">
</form>
Alert: In the above two examples, the OCS HTTP Server expects the name=”reg” attributes to appear exactly as shown.
The <form> tag’s required action attribute is a quoted string containing the writereg.htm reference and two parameters, all separated by semicolons. The reg and fmt parameters specify the OCS Register to write and the data entry/select format to use. These parameters are described in more detail in the following 2 sections:
REG Parameter – OCS Register Write Reference
Examples:
reg–R11
reg–R11.3
The required reg parameter is followed by a dash and an OCS Register reference. Register references start at 1 and the maximum reference depends on the register type and OCS type, as show in the following table:
OCS Register Write References | ||
---|---|---|
OCS Register Type | Maximum Reference (ETN200) | Maximum Reference (ETN300) |
%R Retentive 16-bit registers. | R2048 | R9999 |
%AI 16-bit input registers used to gather analog input data such as voltages, temperatures, and speed settings coming from an attached device., %AQ 16-bit output registers used to send analog information such a voltages, levels, or speed settings to an attached device. | AI512, AQ512 | AI512, AQ512 |
%I Single-bit input registers. Typically, an external switch is connected to the registers., %Q Single-bit output registers. Typically, these bits are connected to an actuator, indicator light or other physical outputs., %M Retentive single-bit registers., %T Non-retentive single-bit registers. | I2048, Q2048, M2048, T2048 | I2048, Q2048, M2048, T2048 |
Note: For BOOL Boolean- [Data Type BOOL] - A single bit, binary value, or register/variable. Boolean points have only two possible values, 'TRUE' or 'FALSE'. formatting (see next section), a bit number can be appended to 16-bit register references (%R, %AI and %AQ). For example, reg-R11.3 references bit 3 of register %R11. Valid bit numbers are 1 through 16.
FMT Parameter – OCS Register Write Format
Examples:
fmt–BOOL
fmt–BOOL–ON–OFF
fmt–BOOL–YES–NO
fmt–BIN
fmt–HEX
fmt–INT
fmt–UINT
fmt–DINT
fmt–UDINT
fmt–REAL
fmt–ASCII–10
The required fmt parameter is followed by a dash and a data entry format type. Valid format types are BOOL Boolean- [Data Type BOOL] - A single bit, binary value, or register/variable. Boolean points have only two possible values, 'TRUE' or 'FALSE'., BIN, HEX A base-16 numbering system which uses the symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F for numeral., INT Integer - [Data Type INT] - A 16-bit signed value. Integers are used where the value of the data is expected to be in the range of -32,768 to +32,767., UINT Unsigned Integer - [Data Type UINT] - A 16-bit unsigned value. Unsigned Integers are used where the value of the data is expected to be in the range of -0 (zero) to 65,535., DINT Double Integer - [Data Type DINT] - A 32-bit signed value. Double Integers are used where the value of the data is expected to be in the range of -2,147,483,648 to +2,147,483,647., UDINT Unsigned Double Integer - [Data Type UDINT] - A 32-bit unsigned value. Unsigned Double Integers are used where the value of the data is expected to be in the range of 0 (zero) to 4,294,967,296., REAL REAL: Single precision floating point value - Real constant expressions must be valid number, and must include a dot ("."). If the user needs to enter a real expression having an integer value, add ".0" at the end of the number. The user can use "F" or "E" separators for specifying the exponent in case of a scientist representation. REAL is the default precision for floating points: such expressions do not need any prefix. and ASCII ASCII - American Standard Code for Information Interchange - ASCII-coded characters are single-byte values in the range of 0 (zero) to 127. Codes in the range 128 to 255 are not defined by the ASCII standard, but rather by the equipment manufacturer.. Three of these format types (BOOL, REAL and ASCII) have optional or required modifiers as follows:
-
The BOOL format writes a single bit, and two optional modifiers indicate the text that must be submitted to set the bit to its logical On and Off states. If these modifiers are omitted, they default to “TRUE” and “FALSE”, so that fmt–BOOL is equivalent to fmt–BOOL–TRUE–FALSE.
-
The REAL format writes a 32-bit floating-point value, and data can be entered in either standard decimal notation or in scientific notation as desired, with or without the –E modifier. The –E modifier is not necessary and is ignored if present.
-
The ASCII format accesses a string of ASCII characters, and a string size modifier from –1 to –31 is required, indicating how many ASCII characters will be written when the form is submitted. For example, the fmt–ASCII–10 format writes a string of 10 ASCII characters. If the user enters an ASCII string that is smaller than the specified string size, the submitted string will be padded with spaces.
Return to the Top: HTTP Server Protocol
Web Content - Authoring
Web content can range from very simple to extremely complex depending on application needs. As such, it is well beyond the scope of this supplement to attempt to provide a tutorial on the subject.
WEB Server Example Applications
One of the best ways to learn how to use the HTTP Web Server is to study working examples. OCS HTTP Web Server Examples are available for download on the Horner Automation website: https://hornerautomation.com/support-files/
WEB Authoring Tools
There are several 3rd party tools available to assist in the development of web content. These tools come in four basic types: Text Editors, HTML Editors, WYSIWYG Programs, and Word Processors. Text Editors require a thorough knowledge of HTML (HyperText Markup Language). However, many experienced web developers prefer to work using a plain text editor.
HTML Editors are specially enhanced text editors designed specifically to make web page creation easier, but they still require a great deal of HTML knowledge. WYSIWYG (What You See Is What You Get) Programs allow HTML code creation using drag and drop techniques, and thus promise to minimize the author’s need to understand HTML. However, when problems arise, there is no substitute for getting into the generated HTML code to see what is going on.
Return to the Top: HTTP Server Protocol