Author Topic: static web pages or hard coded html  (Read 16671 times)

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
static web pages or hard coded html
« on: November 25, 2008, 12:47:12 AM »
Mark,

I'm trying to figure out how to hard code my web pages into the flash, so that they don't have to be up loaded later.  I want the S19 file to be all inclusive, program and initial set of web files.
I'd like to keep the option of updating the files via ftp later though.

I've looked through the documentation and I can't find it.  Is this an option?
I did find SUPPORT_INTERNAL_HTML_FILES and the "one line" defined files.  But this doesn't appear to support binary files, like images.

Thanks,
Aaron

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: static web pages or hard coded html
« Reply #1 on: November 25, 2008, 01:13:48 AM »
Aaron

It is possible to serve files from anywhere, also from code, as you have seen at a coupe of locations in the project, however this has to be controlled to a certain degree from outside of the HTTP server. The HTTP server works autonomously with files in the file system and so this is the easiest method.

Don't forget that the there is a bat file in \Applications\uTaskerV1.3\WebPages\WebPagesM5223X called Copy_all.bat. You can edit ftp.txt to automatically load all of your project files by double clicking on it. This is fast and usually easier than working with files embedded in the code (also more flexible since the project doesn't have to be recompiled due to HTML changes).

However also images could be embedded as long as you have a program that converts them to a binary array which can be linked into the code. Eg.
const unsigned char image1[] = {0x00, 0x01, 0x03, 0x03.....0xf2};
The web server then needs to known the pointer to it and its length and it can serve it. It should also be told that it is not an HTML file so that it doesn't try passing it to look for places to insert strings and stuff.

somewhere suitable...
        http_session->ptrFileStart = (unsigned char*)image1;
        http_session->FileLength   = sizeof(image1);
        http_session->ucMimeType   = MIME_JPG;


Once this is set it will be served (instead of the page from the file system) in response to a GET.
However there is no standard support for this and so it might get trickier if referencing images from HTML in this manor. Generally web servers which use this method can't support FTP and have a special program that converts the web pages to am embedded set of lots of such arrays - somehow linked to each other where necessary.

I would have a go with the FTP bat since most users (especially the ones who don't program the code but just develop the web pages) tend to find it very handy.

Regards

Mark

PS. When a program with web pages is to be programmed for production purposes as a one-shot task this is also quite easy.
- load a board with the program and then upload the web pages via FTP.
- Now do a copy of the entire FLASH with a debugger to a reference file.
- Now simply program the reference file each board in the factory (they will have program and web pages in one go)


Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: static web pages or hard coded html
« Reply #2 on: November 25, 2008, 01:39:18 AM »
Thanks Mark,

I think I can make a solution from your answers.

Aaron

Offline Lukee

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: static web pages or hard coded html
« Reply #3 on: February 17, 2009, 05:23:11 PM »
Hello Mark!

I try add to my project the internal (hard-coded) HTML files. I define:

#define  FILE_0       "<html><head><title>test</title></head><body>test</body></html>";

but I don't know how to use them like HTML pages form FTP. I would like to acces content of this define like acces to 0.htm file.

Best regards
Lukee 

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: static web pages or hard coded html
« Reply #4 on: February 18, 2009, 03:29:56 PM »
Hi Lukee

Presently the only method to serve internal HTML is to respond to fnWebHandle() with something like:

            http_session->ptrFileStart = (unsigned char*)cSuccessSW_HTML;
            http_session->FileLength = sizeof(cSuccessSW_HTML)-1;
            fnDelayResetBoard();                                         // after 2 seconds the application will reset and then the new software will be copied
            return DISPLAY_INTERNAL;                                     //


The HTML code is in a string in code, like cSuccessSW_HTML[].

I would like to expand the support for serving internal files which are hard coded in the program code.
Presently first tests have resulted in a complication using the simulator since it doesn't (yet) known how to differentiate between file which are in the 'real' file system and the code. Once this is overcome I hope that extended support of this topic will be available.

Perhaps the method as show above can still be sued in your case.

Regards

Mark

Offline Lukee

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: static web pages or hard coded html
« Reply #5 on: February 18, 2009, 06:37:37 PM »
Hi Mark,

I do this that (added following code):

Code: [Select]

...
    if ((http_session->ucState > HTTP_STATE_ACTIVE) || (*cFileName < '0')) { // if we have just authenticated, always do start page
            *cFileName = '0';                                            // default start side
        }
else if ((http_session->ucState > HTTP_STATE_ACTIVE) || (*cFileName =='0')) {
ucFile = (MEMORY_RANGE_POINTER)cFile0_HTML - FILE_HEADER;
http_session->ptrFileStart = (unsigned char*)cFile0_HTML;
            http_session->FileLength = sizeof(cFile0_HTML)-1;
http_session->ucMimeType = MIME_HTML;
#ifdef _WINDOWS   
iFetchingInternalMemory = 1;
#endif
}
else
{
...

I have the internal file called 0.htm. That is correct ?

Best regards
Lukee

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: static web pages or hard coded html
« Reply #6 on: February 18, 2009, 09:06:26 PM »
Hi

If you look how the 404 page is served in the HTTP code you can also do something similar for your own pages. This does however require modifying the HTTP code, which I believe you are doing. It should therefore work (I didn't test your example though, but this is very easy to do in the simulator).

However I hope to add a method which is controllable from the application code and so doesn't involve and HTTP code changes to be able top work with it.

regards

Mark

Offline robo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: static web pages or hard coded html
« Reply #7 on: February 25, 2009, 11:44:47 AM »
Hi Mark!

You answers are always very felpfull! Are you planing date to add this method for uTasker project?
Because I want to use hard coded html pages in my project and I wonder if wait or change http code like I'm doing now.

Best regards,
robo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: static web pages or hard coded html
« Reply #8 on: February 25, 2009, 11:58:01 AM »
Hi Robo

I have started working on this but found some complications (especially for the simulator).
If you have another solution I would continue with it for the moment since I don't know when the next service pack will be ready - I am a little behind with USB for the Luminary Micro family and this is the first that I need to complete.

Regards

Mark

Offline Lukee

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: static web pages or hard coded html
« Reply #9 on: March 05, 2009, 02:59:01 PM »
Hi Mark,

I try hardcoded webpages and I add a bit code to http.c. When hardcoded file (cFile1_HTML) in flash is smaller than 1400 characters it work, but when is bigger than 1400 dosen't work.

That is code which I add to http.c:

Code: [Select]
static int fnDoWebPage(CHAR *cFileName, HTTP *http_session)
{
    unsigned short usLen = HTTP_BUFFER_LENGTH;
    unsigned char ucPush = TCP_FLAG_PUSH;
    MEMORY_RANGE_POINTER ucFile;

#ifdef SUPPORT_INTERNAL_HTML_FILES
    if (cFileName != 0) {                                                                              // predefined internal file is to be displayed
#endif
        if ((http_session->ucState > HTTP_STATE_ACTIVE) || (*cFileName < '0'))  // if we have just authenticated, always do start page
            *cFileName = '0';                                                                           // default start side
if ((http_session->ucState > HTTP_STATE_ACTIVE) || (*cFileName =='1'))
{
ucFile = (MEMORY_RANGE_POINTER)cFile1_HTML - FILE_HEADER;
            http_session->FileLength = sizeof(cFile1_HTML);
#ifdef SUPPORT_MIME_IDENTIFIER
http_session->ucMimeType = MIME_HTML;
#endif
#ifdef _WINDOWS   
iFetchingInternalMemory = 1;
#endif
}
else
{
    ucFile = uOpenFile(cFileName);                                          // open the file to be displayed
    http_session->ucState = HTTP_STATE_ACTIVE;
    http_session->FileLength = uGetFileLength(ucFile);               // get the length of the file to be displayed
    #ifdef SUPPORT_MIME_IDENTIFIER
    http_session->ucMimeType = UNKNOWN_MIME;
    #endif

if (http_session->FileLength == 0) {                                       // file not found
        #ifdef FILE404_IN_PROG                                                               // processors with linear memory can choose to use a 404 file  in code space
            ucFile = (MEMORY_RANGE_POINTER)cFile404 - FILE_HEADER;
            http_session->FileLength = sizeof(cFile404);
            #ifdef SUPPORT_MIME_IDENTIFIER
            http_session->ucMimeType = MIME_HTML;                                  // force HTML type
            #endif
            #ifdef _WINDOWS                                                                   // {10}
            iFetchingInternalMemory = 1;                                                    // inform the simulator that this access is definitively from internal FLASH
            #endif
        #else
            ucFile = (MEMORY_RANGE_POINTER)FILE404;                               // no file exists so get the error page
            if (!(http_session->FileLength = uGetFileLength(ucFile))) {             // get length of 404 error file from the file system
                fnTCP_close(http_session->OwnerTCPSocket);                        // no error file exists so just close connection
                return APP_REQUEST_CLOSE;
            }
        #endif
}
}

Thank you for reply.

Best regards
Lukee

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: static web pages or hard coded html
« Reply #10 on: March 05, 2009, 04:01:28 PM »
Hi Lukee

Yes, this is the complication. The first frame can be determined by the code quite easily but the problem starts when the frame needs to be repeated (due to no ACK) and when following frames need to be added. In this case, the HTTP code is file system oriented and tries to get the data from the file system. Presently it can't detect that the web page being served is special in this respect. You will in fact see that the 404 page is also handled specifically by HTTP (also when repeating!!).

This is indeed the difficulty that need to be over come...

Regards

Mark

Offline Lukee

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: static web pages or hard coded html
« Reply #11 on: April 07, 2009, 02:19:24 PM »
Hi Mark,

How do you think when hardcoeded pages will be available in uTasker? I have try to do this but I always have problem with bigs files.

Best regards
Lukee

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: static web pages or hard coded html
« Reply #12 on: April 07, 2009, 07:20:58 PM »
Hi Lukee

I am sorry that there hasn't been much progress on this front but I do now have a test version which allows serving web pages from program code. This doesn't seem to be length dependent. This means that you can embed long HTML content or images etc. It should work with these in program FLASH (theoretically also in external if that makes sense) or in SRAM (if this is ever a necessity).

It also works in the simulator (at least from internal FLASH program code - which is probably the one which is most likely to be used).

In addition it also allows pages to reference each other using long(er) file names.

It hasn't been tested very much at all... but I think that it has good chances and it is also very easy to use. What I don't know about yet is how it is best to put web pages into the code but maybe some other existing methods can be used as a basis for doing that (eg. converting images to table). It can be used together with files in the file system too.

Please contact me by email if you would like to have a go with it and see whether there are any problems or restrictions that need to be overcome.

I would like to also be able to see these files as write-only ones via FTP but I haven't done any work on that just yet.

Regards

Mark

Offline phomann

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Homann Designs
Re: static web pages or hard coded html
« Reply #13 on: April 08, 2009, 06:21:29 AM »
Hi Mark,

I too am very interested in being able to have web pages served from Program code. I'd be happy to do some testing on the LM3 port.  As to how to put the pages into code, there is a perl script in UIP called makefsdata that does it. It is in StellarisWare.  Luminary Micro also have a program in that tools directory C:\StellarisWare\tools\makefsfile that also does it.

As a stopgap, I'll use this to embed the web pages into code then on initialisation put then into the file system. At this stage I have enough code space to to that.

Cheers,

Peter.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: static web pages or hard coded html
« Reply #14 on: April 08, 2009, 04:14:16 PM »
Hi Peter / Lukee

I have drafted a new document called USER FILES which can be found in the preliminary section on the documents page http://www.utasker.com/docs/documentation.html

I will send you both the new files involved so that you can look into its suitability and further advancement.

Good luck

regards

Mark