MityDSP Documentation Index

Using the MityDSP Web Server Daemon

The MityDSP web server deamon allows you to easily add a web interface to your MityDSP based aplication. A web interface can be used for MityDSP device configuration, monitoring device status and/or as a diagnostic aid.

The MityDSP web server class (tcHttpd) provides full featured web server which may serve static web pages or dynamic web pages using server side includes and HTML forms. Your MityDSP application will provide server side CGI functions which are tailored to the specific requirements of your application. This allows the memory and resource requirements of the webserver to remain small which is ideal for an embedded application. The tcHttpd class handles all of the low level TCP socket interfaces and the HTTP protocol layer messages.

Example

The following simple example will start a web server. A single CGI function "visitors" which will report the number of visitors since the server started.

The web page will generate this text:

This is an example web page with dynamic content.
Visitors to this site: 10

The following HTML code will be compiled into your application (See: ROM File System):

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html><head></head>
 <body>
     This is an example web page with dynamic content.<br>
     Visitors to this site: <%visitors%><br>
 </body>
 </html>

Note: The "<%" and "%>" tags surround the name of a CGI function, "visitors", which your application will provide. When the MityDSP HTTP server encounters these tags, it will search for a CGI function in the tsHttpdCgiTable with a name that matches the string contained within the tags. If a match is found then that CGI function temporarily takes over rendering HTML code which will be inserted into the final web page. If no matching CGI function is found, then no extra text will be inserted into the web page.

The following C++ code will create the web server deamon object, configure it with a table of application specific CGI functions, then start the server.

 #include "net/telnetd/httpd.h"

 tcHttpd *httpd;
 void cgi_visitors (HTTPCONN *httpconn);  // Our CGI function
 
 tsHttpdCgiTable cgi_function_table[] = 
 {
     cgi_visitors,  "visitors",           // <%visitors%> tag
     NULL, NULL                           // End of table marker
 };
 
 void start_web_server ()
 {
     // Create the web server daemon
     httpd = new tcHttpd (12);
 
     // Start the web server daemon
     tsHttpdParams hp;
     memset (&hp, 0, sizeof (hp));       
     hp.user1         = NULL;
     hp.port          = 80;
     hp.cgi_table     = cgi_function_table;
     
     httpd->run (&hp);   // Will not return...
 }
 
 // This is our CGI function which gets called as the HTTP server
 // encouters the <%visitors%> tag. It increments a static counter
 // then converts that count to a bold faced HTML string.
 void cgi_visitors (tsHttpConn *httpconn)
 {
     static int visit_count = 0;
     char *str[40];

     visit_count++;
 
     // Create the HTML string data that we want to inserted into 
     // the page being rendered. This string must be valid HTML text.
     sprintf (str, "<B>%d</B>", visit_count);
     httpconn->httpd->html_write (httpconn, str, strlen (str));
 }

ROM File System

The MityDSP web server stores it's web pages in a very simple ROM based file system. The file system can be easily modified to your applications needs, but in its most basic form you will compile the content of your webserver (HTML, GIF, JPG, etc. files) into your application code. With small modifications this approach could be changed to use a particular region of your FLASH or the MityDSP FAT file system.

Generating The File System

To compile your webserver content into the application a tool (make_romfs.exe) is included in the MityDSP distribution which will compile all of the files in a directory tree into data arrays in a CPP file which you will then compile into your application. Below is an example of using this tool to generate the ROM file system for a web server demo program. The output from the following example is a file named "romfsdata.cpp", this file is then compiled into a web server demo program. There are two command line parameters to "make_romfs.exe": The -d parameter specifies the directory to compile and the -o option specifies the output file name.

    C:\web_server> ..\MityDSP\sw\tools\make_romfs -d web -o romfsdata.cpp
   
    make_romfs - Version: 1.0 Built: Apr 26 2005 10:34:55
    Copyright 2005 Critical Link LLC, All rights Reserved
    
    Including: "404.html"
    Including: "cgi_demo.html"
    Including: "eye.gif"
    Including: "followingeyes.js"
    Including: "form_demo.html"
    Including: "index.html"
    Including: "java_demo.html"
    Including: "leftchip.gif"
    Including: "mitylogosmall.gif"
    Including: "pupils.gif"
    Including: "rightchip.gif"
    Including: "thinklink.gif"
    
    Successfully Generated: "romfsdata.cpp"
    Compiled 12 files.
    23879 bytes used for the file system.
    
    C:\web_server>
    

File System Contents

There are very few special requirements to the contents of your ROM file system. It must contain all of the files which your web server will serve. It should contain one file named "index.html", which will serve as the homepage for your MityDSP web application. It can optionally contain one file named "404.html" which will act as the default "Web page not found" page for your MityDSP based web server. Beyond that the only limit is available memory in your MityDSP device to hold the file system contents. You should take special care not to allow the directory tree which you run through "make_romfs.exe" to contain any files which you do not want in your web server's ROM. Any unreferenced files will waste memory space in your MityDSP application.

Copyright Information

The MityDSP HTTP server is based in part on the Ethernut HTTP server written by egnite Software GmbH. More information on the Ethernut project may be found here http://www.ethernut.de.

Portions of the MitySP HTTP server are Copyright by Critical Link LLC. These portions written by Critical Link do not fall under the same redistribution guidelines (outlined below) as the sections copyrighted by other individuals.

Portions of the MityDSP HTTP server copyright by:
Copyright (C) 2001-2004 by egnite Software GmbH. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


  
Generated on Wed Mar 17 18:24:38 2010 for MityDSP Net by  Doxygen Version 1.6.1
Copyright © 2009, Critical Link LLC, All rights reserved.