Using httpsrv to access web pages on SDcard

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using httpsrv to access web pages on SDcard

Jump to solution
1,004 Views
GeneGoff
Contributor III

My project is based on the Quick Start Demo for the K60 where it used the httpd web server framework and accesses web pages in the SDcard which worked fine.  I updated my project using the httpsrv framework from the httpsrv example project and everything works fine (serving web pages from flash is good) but any web pages on the SDcard come up as 404 Page Not Found.  I see there is a root directory alias structure HTTPD_ROOT_DIR_STRUCT root_dir[] in the httpd web server which I have changed to const HTTPSRV_ALIAS http_aliases[] and kept the contents of the structure the same.  There's also a function to check if the SDcard is installed with a signature static void sdcard_status_fn(HTTPD_SESSION_STRUCT *session) which I have changed to static _mqx_int sdcard_status_fn(HTTPSRV_SSI_PARAM_STRUCT* param).  I think I've got this function coded fine and everything compiles fine, just web pages on the SDcard come up as 404 Page Not Found.  Anything else I'm missing using the httpsrv framework and accessing web pages on the SDcard? 

Thanks,

Gene

Labels (1)
Tags (2)
0 Kudos
1 Solution
566 Views
karelm_
Contributor IV

Hi Gene,

just to be sure. You are accessing webpages on sdcard from your browser through URL that looks like this: http://BOARD_IP_ADDRESS/sdcard/WEB_PAGE_NAME.html? And this sdcard is mounted as disk "a:" in your configuration, right? If that is true, then your aliases should look like this:

const HTTPSRV_ALIAS http_aliases[] = {{ "/sdcard/", "a:\\" },{ NULL, NULL }};

Best regards,

Karel

View solution in original post

0 Kudos
5 Replies
566 Views
karelm_
Contributor IV

Hi,

can you please share source code of your application with me? Problem might be with alias definitions. It should look like this:

HTTPSRV_ALIAS http_aliases[] = {    {"/usb/", "c:\\"},    {NULL, NULL}    };

First variable ("/usb/") is part of URI which will be replaced by second variable ("c:\\") when server looks for a file in filesystem. Also please note the backslashes and make sure you have set them in same way.

Best regards

Karel.

0 Kudos
566 Views
GeneGoff
Contributor III

Thanks Karel.

The alias definition you gave works for the web-hvac project, where web pages are stored on a USB stick.  In the K60 Quick Start Demo, the web pages are stored on the SDcard which is very similar, yet may have slight differences because it connects through the SD driver rather than the USB stack.

Here is my code, which is identical to the working Quick Start Demo code, but with HTTPD_ROOT_DIR_STRUCT root_dir[] replaced with HTTPSRV_ALIAS http_aliases[].  

const HTTPSRV_ALIAS http_aliases[] = {

    { "", "tfs:" },         //Internal flash with Trivial File System

    { "sdcard", "a:" }, //SDCard as a: partition drive

    { 0, 0 }

};

I also tried { "/sdcard/", "a:\\" } but still got 404 Page Not Found.

Thank you!

0 Kudos
567 Views
karelm_
Contributor IV

Hi Gene,

just to be sure. You are accessing webpages on sdcard from your browser through URL that looks like this: http://BOARD_IP_ADDRESS/sdcard/WEB_PAGE_NAME.html? And this sdcard is mounted as disk "a:" in your configuration, right? If that is true, then your aliases should look like this:

const HTTPSRV_ALIAS http_aliases[] = {{ "/sdcard/", "a:\\" },{ NULL, NULL }};

Best regards,

Karel

0 Kudos
566 Views
GeneGoff
Contributor III

Karel,

You are correct.  I added your alias entry and I had to remove the alias { "", "tfs:" } and everything works fine.

Thank you Karel!

0 Kudos
566 Views
karelm_
Contributor IV

Hi,

I am glad it works for you :smileyhappy:

Best regards,

Karel

0 Kudos