µC/HTTPs is compliant with the all available browser for computer system. It was written for target systems running µC/OS-II or µC/OS-III, and µC/TCP-IP. This section describes the µC/HTTPs usage.
Interface with FS
The sample application that comes with µC/HTTPs assumes the presence of µC/FS, as mentioned in See Directories and Files. It is possible to port µC/HTTPs so it is used with other file system by providing an appropriate implementation of apps_fs.c
and apps_fs.h
. Example template files to port the file system are available in the uC-HTTPs\FS\Template
directory.
µC/HTTPs is distributed with file system ports for µC/FS, and the port corresponding to the version used by your project should be moved into the µC/FS directory structure. Furthermore, the source files of that port must only be included in your project from the µC/FS module. This is necessary since multiple applications might share the same file system port, and including it from several locations would cause linker and/or build errors.
Alternatively, if you do not want to move it to your file system directory structure, you may include it directly from µC/HTTPs. If you do so, make sure other applications relying on the file system port do not include it too.
Using µC/HTTPs with the Static File System
µC/HTTPs could be used without a conventional file system in order to test its functionalities.
The static file system relies on C arrays to represent the various files, and those files are accessible only for reading. µC/HTTPs ships with a very basic web page consisting of an html and a gif file. If you wish to include your own files in this file system, you will have to follow a few simple steps.
First of all, you will have to download a small utility called “bin2c.com
” from Micrium’s web site to help you create a C array from any given file. You need to create these arrays for every single file you want to include in this file system. Type “bin2c.com /?
” at the command prompt for more information on its usage.
The C array having been generated by this utility then have to be included into your project’s application (see file static_files.h
for complete example). Finally, prior to being able to access the files on the static file system, you need to initialize it and add the files to it, just like it is being done in See ..
Also note that additional configuration values have to be added to your app_cfg.h
file. Refer to See µC/HTTPs Configuration. for more information).Transferring Files to Use with µC/HTTPs
Transferring files on the file system for use with the µC/HTTPs module is outside the scope of this document. For this purpose, you could use a FTP server or client, such as µC/FTPs or µC/FTPc, or again use a mass storage media to into your file system.
Make sure the files intended to be served by the µC/HTTPs module are located below HTTPs_CFG_FS_ROOT
, or the web server will not be able to transfer them to web browsers.
µC/HTTPs Configuration
The µC/HTTPs module has to be configured according to your specific needs. A template configuration file ( http-s_cfg.h
) is included in the module package (see See Directories and Files.), and this configuration should be copied into your app_cfg.h
file. Here is the list of the values and description of each of the configuration variable. However, keep in mind that future releases of this module might include more configuration options.
Module Configuration
This value defines the TCP port µC/HTTPs will listen for requests. The default value is 80.These values define the timeout values for sockets, in milliseconds. If the server doesn’t reply within the specified time after a request is made, that request will be aborted.These values define the maximum number of retries for various actions before returning an error to the application.These values determine the size of the buffer used to read the HTML file and the size of the one used to transmit this file, in bytes. If you choose to increase these values, make sure the HTTPs task’s size is large enough. If you enable the parsing of the tokens found in HTML files, you have to make sure the read buffer length ( HTTPs_CFG_FILE_RD_BUF_LEN
) is at least as large as the longest token present in your HTML files.HTTPs_CFG_TOK_PARSE_EN
allows the developer to enable or disable the parsing of the tokens found in HTML files (dynamic content). If the server does not host such content, set this configuration variable to DEF_DISABLED
in order to speed up processing. The other variable defines the size of the array used to collect the tokens’ values when parsing the file. Make sure it is large enough to contain all of these values. The minimum for this value is 2.This defines the file system root for the µC/HTTPs module.This value defines the default file returned to web browser when no file is specified.This value defines the message returned by µC/HTTPs to a web browser when a requested file is not found.
Static File System Module Configuration
If the static file system is being used with µC/HTTPs, the following configuration values also have to be added to your app_cfg.h
file.This value defines the maximum number of files the static file system could manage.This value defines the maximum number of directory the static file system could manage.This value defines the maximum file name length.
Operating System Configuration
The following configuration constants relate to the µC/HTTPs OS port. For many OSs, the µC/HTTPs task priority and stack size will need to be explicitly configured for the particular OS (consult the specific OS’s documentation for more information).
The priority of µC/HTTPs task is dependent on the requirements of the application.For µC/OS-II and µC/OS-III, the following macros must be configured within app_cfg.h
:Value of the priority for the µC/HTTPs tasks. The value assigned depend of the software architecture of your system, and of the importance of this module response time relative to the other tasksValue of the priority for the µC/HTTPs tasks. This default value should be enough for most environments, but you should check this on your system for reliability or performance purpose.
Interface with RTOS
µC/HTTPs requires the presence of a Real Time Operating System (RTOS). As mentioned in See Directories and Files., the sample application uses µC/OS-II or µC/OS-III. It is possible to port µC/HTTPs so it is used with other OS by providing an appropriate implementation of http-s_os.c
.
HTML Files Token Substitution
µC/HTTPs allows dynamic content to be inserted in HTML web pages (files having the htm or html suffix) by using special tokens being substituted before the page is actually sent to the web browser. Those tokens are represented in the HTML files as:Assuming we have an HTML page that look like this:When a web client requests this file, µC/HTTPs will parse the file, find the ${My_IP_Address}
token, and pass the string " My_IP_Address
" into the HTTPs_ValRx()
callback function. That function will then substitute the token for its value, sending the following HTML file to the client:See See µC/HTTPs API. for more information on the callback function having to be implemented to support this.
Handling Form Submissions
µC/HTTPs allows you to use forms in you HTML documents. When the form is posted, µC/HTTPs will process the POST action and will invoke the HTTPs_ValRx()
callback function located in your application for every key-value pair transmitted. Please refer to See µC/HTTPs API. for more details on this function.
µC/HTTPs Example Code
The file app.c contains an example of application code, and was written to illustrate the capabilities of the µC/HTTPs module. That code simply initializes µC/OS-II or µC/OS-III, µC/TCP-IP, µC/FS, and µC/HTTPs, and creates a few tasks and other kernel objects that will give the user information about the state of the system.
Some sections of the source code have been removed or modified to help focus on the µC/HTTPs module use.