Interface with File System

Although µC/HTTP-server can be used without a File System, when file operations are required by the HTTP server a File System is needed. We suggest using a conventional File system implementation such as µC/FS. This will allow you to dynamically load the web pages and enable your web server to receive files. However, µC/HTTP-server comes with a minimalist in-house Static File system which only stores static files (stored in the code space memory). Obviously, it is only possible to read them and thus not possible to upload files to a web server when the static file system is used.

µC/HTTP-server uses the API's defined by TCPIP Network File System Abstraction Layer (net_fs.h) to access the file system. It is possible to use µC/HTTP-server with other file systems by providing an appropriate implementation of the TCPIP Network File System Abstraction Layer. Example template files to port the file system are available in the TCPIP Network File System Abstraction Layer directory.

Configuration

Compile-time Configuration

The configuration macro HTTPs_CFG_FS_PRESENT_EN must be set to DEF_ENABLED in the http-s_cfg.h file when a File System (Static or real) must be used with the HTTP server.

See section File System Compile-time Configuration for more details.

Run-time Configuration

Three types of configuration structure exit for the File System Configuration: one when No FS is used, one for the Static FS and one for a standard FS. Depending on your setup, a object of one of those structure type must be define in the application and pass as a pointer inside the instance configuration object structure (HTTPs_CFG).

See section File System Run-time Configuration for additional details.

Usage

Transferring files to use with µC/HTTP-server

Transferring files on the file system for use with the µC/HTTP-server 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 access into your file system.

Note that µC/HTTP-server can support file upload when a traditional file system is used. Thus it’s possible to create scripts to transmit files using the POST method even if no file is yet loaded. Also, many web browsers have now plugins for testing purposes. They allow to send custom HTTP requests to a server. You can therefore use some of those tools to upload files to the HTTP server. We tested the Postman plugin with Chrome.

Using µC/HTTP-server with the static file system

µC/HTTP-server provides a small file system that could be allow it to be used without a conventional file system.

The static file system relies on C arrays to represent the various files, and those files are accessible only for reading. µC/HTTP-server ships with a very basic web page consisting of a gif and two html files. If you wish to include your own files in this file system, you have two possibilities, use a little Windows-based program that is available on the Micriµm website or use the python script located in the µC-HTTP/Server/FS/Script directory.

Windows program with GUI

First of all, you will have to download a small utility called bin2c.exe 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.exe /? 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 the listing below.

Listing - Example code of static file system usage
static  void  AppTaskStart (void  *p_arg) 
{
  [...]
  HTTPs_FS_Init();                                               (1)
  HTTPs_FS_AddFile((CPU_CHAR *)&STATIC_INDEX_HTML_NAME[0],       (2)
                   (void     *)&index_html[0],
                   (CPU_INT32U) STATIC_INDEX_HTML_LEN);
  HTTPs_FS_AddFile ((CPU_CHAR *)&STATIC_LOGO_GIF_NAME[0],
                    (void     *)&logo_gif[0], 
                    (CPU_INT32U) STATIC_LOGO_GIF_LEN);
  HTTPs_FS_AddFile ((CPU_CHAR *)&STATIC_404_HTML_NAME[0],
                    (void     *)¬_found_html[0], 
                    (CPU_INT32U) STATIC_404_HTML_LEN);
  [...]
}

(1) Initialize the static file system.

(2) Add files to the static file system.


Python Script

A python script named GenerateFS.py is also offered in the µC/HTTP package allowing to convert files into C arrays. The script can be useful if many files are to be converted since it support recursion inside a folder. The script also generate C files (generated_fs.c/.h) with the function to call to include all the C arrays generated.

This script has been created to ease your life as developer. It is not intended to be a production tool.

The script should be called in a command line shell like shown bellow:

python GenerateFS.py [source directory or file name] [destination directory] -f

The first argument is the path directory where to files to be converted are located or the file name of the single file to convert. The second argument is the directory path where to saved the generated file(s). An optional -f argument can be used to force the re-writing if the destination file already exist.

Static File System Module Configuration

A template for the configuration of the static file system is provided in uC-HTTP\Server\FS\Static\Cfg\Template\https_fs_static_cfg.h. If the static file system is being used with µC/HTTP-server, the configuration file have to be copied into your application directory and included to your project.

#define HTTPs_FS_CFG_ARG_CHK_EXT_EN       DEF_ENABLED

This value configures external argument check feature. You may enable this feature by setting it to DEF_ENABLED or to DEF_DISABLED otherwise.

#define HTTPs_FS_CFG_NBR_FILES            5

This value defines the maximum number of files the static file system could manage.

#define HTTPs_FS_CFG_NBR_DIRS             5

This value defines the maximum number of directory the static file system could manage.

#define HTTPs_FS_CFG_MAX_FILE_NAME_LEN    25

This value defines the maximum file name length.