Store web pages externally step by step
Web pages can be stored on any media accessible via MFS, such as USB memory stick, SD card. It is also possible to use FFS and store web pages on NAND flash. The following example is a step by step guide on how MQX can use nandflash on TWR-K70F120M, we start with the httpsrv demo.
1. Add FTP server and nandflash flush support
This demo starts with default HTTPSRV example, Shell console is enabled in the default httpdsrv.c. Ping, ipconfig and help commands are enabled by default. We add ftpsrv application to support FTP protocol , and nandflash support.
2. Allow RTCS for more sockets
We will use two TCP servers. There is one socket need for HTTPSRV listening socket, second listening socket for FTP server. One socket for each connected client.
3 .Add MFS library to the HTTPSRV build project
By default, MFS library is not enabled in the HTTPSRV project. It uses only TFS for web pages storage. We add path to MFS library into HTTPSRV build project
4. Add FFS support to the HTTPSRV build project
Ffs library is not enabled by default. We need to add path into HTTPSRV build library. Install FFS driver and open it.
5. Resolve build errors
When we try to build now the HTTPSRV example, we have compile errors. This is because by default the HTTPSRV example does not include MFS and FFS library head files. We need to add a path for MFS and FFS
6. Configure HTTPSRV root directory
Web pages of this demo are to be stored in nandflash within web_pages folder. We need to set rootdir and index
Before we can view the web page in browser, we need to copy web pages to nand flash. This is the purpose of FTP server, as one example how to copy files.
If you wish to be sure the web pages survive power cycle, make sure you flush the FFS file system after “web_pages” are copied.
7. Build, Download, Execute
As hardware we use TWR-K70F120M and TWR-SER. After you download the executable and run, start FTP server by issuing command “ftpsrv start” on serial console; start FTP client; copy over files from PC host to TWR nandflash. Keep the folder structure of the copied files; now open your web browser (support for HTML5 is required); open Url http://192.168.1.202