Announcement

Collapse
No announcement yet.

cgi.c - How do I combine this with an HTML page?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • cgi.c - How do I combine this with an HTML page?

    Hi,

    I'm pretty new to this whole web page thing, so my questions may seem simple. I'm using the cgi.c sample as a the starting point for a set of pages that will load configuration data into my application. I understand the use of the callback function to perform an action. However I don't quite see how I could expand upon this to have multiple callback functions responding to multiple form posts. Is there always one callback function per page, or can there be several, corresponding to different actions (which is what I suspect is true)? The cgi.c code creates the web page with a simple form, which makes sense for something this simple. If I want to create a more complex page with several forms on it, I would think it would be better to create an HTML page separately and just load it into the XPort Pro. But how do I tie this page to the callback functions that will actually take the posted form data and use it in my application?

    Second, in the functions that create the page and build the form, there are a couple of lines that confuse me:

    In sampleWebMgrStart(struct http_client *httpClient):
    HttpWriteData( httpClient, "<div class=\"contentContainer\"><div
    class=\"inside\">\n"
    );


    In sampleWebMgrAddTranslation(struct http_client *httpClient, const char
    *textTranslated
    )
    HttpWriteData( httpClient, "<form method=\"post\">\n<table
    class=\"basicTablelineConfigTable\">\n"
    );


    Where is the style sheet that describes how to format the classes mentioned?

    Thanks in advance,
    - Bob

  • #2
    Bob, you have to have a seperate call back for every page that is going to be generated via CGI, ex:
    Code:
        
    TLOG(TLOG_SEVERITY_INFO, "Registering HTTP callback for status." );
    
        /* Register callback with the HTTP server */
        if(! HttpDynamicCallbackAdd(httpServer, "/status", SmrtChrgWebMgrCallback))
        {
            TLOG(TLOG_SEVERITY_ERR, "Failed to register status callback with HTTP Server.");
        }
        
        TLOG(TLOG_SEVERITY_INFO, "Registering HTTP callback for setRTC." );
    
        /* Register callback with the HTTP server */
        if(! HttpDynamicCallbackAdd(httpServer, "/setRTC", SmrtChrgsetRTCCallback))
        {
            TLOG(TLOG_SEVERITY_ERR, "Failed to register RTC callback with HTTP Server.");
        }
    
        TLOG(TLOG_SEVERITY_INFO, "Registering HTTP callback for TimeZoneSet." );
    
        /* Register callback with the HTTP server */
        if(! HttpDynamicCallbackAdd(httpServer, "/setTZ", TimeZoneSetCallback))
        {
            TLOG(TLOG_SEVERITY_ERR, "Failed to register TimeZone callback with HTTP Server.");
        }
    The stylesheet that is usually referenced is style.css in /http/config/style.css.

    You can reference it by adding the following code to your header function:
    Code:
        HttpWriteData(httpClient, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" /> ");
        HttpWriteData(httpClient, "<link rel=\"stylesheet\" href=\"/config/style.css\" title=\"default\" type=\"text/css\" />");
        HttpWriteData(httpClient, "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"/rss\" />");
        HttpWriteData(httpClient, "<link rel=\"shortcut icon\" type=\"image/ico\" href=\"/config/favicon.ico\" /> </head>");
    NOTE! This assumes that /http/config/style.css exists. It does not by default, but if you are doing custom web branding then you should have something there.

    Josh

    Comment


    • #3
      Josh,

      Thanks for the input. I guess one callback per page makes sense. So is there no way to use the callback in conjunction with an HTML page so that all of the content does not have to be produced by the callback function? For example, I would create a "config_voltages.html" page and also have a callback function "configure_voltages( )" to go with it and essentially "fill in" the forms data or whatever is changing dynamically. I guess it would be a hybrid of CGI and a standard HTML document. Or is the idea of a CGI-produced page an all-or-nothing proposition?

      As for the style sheet, I found it on the XPort, though I can't find a copy in the source code that Lantronix provides, which seems odd. I want to provide my own style sheet. How do I load it into the XPort?

      - Bob

      Comment


      • #4
        style.css should be a part of the release and I see that it is not.
        I will submit a bug and have that fixed for future releases.

        You can still access the file (on the device) by retrieving it via FTP, even though you can not see it on the file system. Just do a get of the desired file and it will be pulled from the ROM image.

        As for your web pages, you could employ Ajax techniques where basically JavaScript hosted on the browser talks to CGI on the device server.

        mattmc

        Comment


        • #5
          Bob, I see Matt has given you a few ideas.

          I find it useful to that every lantronix module I work on, I download all of the web files using my web browser so that I have a copy before I start changing things.

          I usually FTP the new stuff up. All of the web files must be in /http and your index.html must go into /http/config/

          An alternative to Ajax is frames which can be slightly easier to work with if you have less experience in web dev (like me).

          Josh

          Comment


          • #6
            Josh and Matt,

            Thanks for all your help. I spent most of yesterday learning about javascript and Ajax, and it does look like it would work really well, especially for the status that I have to display. I want the data to change fairly often, and simply refreshing the entire web page every so often seems kind of klunky. however, I think I'll expand on the cgi.c sample to get a page with multiple fields that are all submitted with one submit button.

            I don't know what "frames" are, but I'll Google the term and study up on it. If it is simpler than using Ajax and allows me to create pages that get updated smoothly I will certainly consider it.

            - Bob

            Comment


            • #7
              JQuery is a technology that I've been looking at recently. Its seem pretty impressive and is gaining a good following. In fact, Microsoft and Nokia are adopting it (or have already) as part of their ajax offerings. It would provide a powerful framework for building impressive functionality into the device server.

              The work you would have to do is match their ajax processing on the server side via some cgi, and of course build up the html/javascript/ajax web content.

              http://jquery.com/


              mattmc

              Comment

              Working...
              X