Fullscreen
Loading...
 

System Workbench for STM32 Help

Forums » System Workbench for STM32» HTTPD Server - fsdata.c issue

HTTPD Server - fsdata.c issue

I posted this on the community.st.com forum but have gotten any response:

I have the STM32F407 Discovery board running with LWIP. I am able to ping the board and get replies.

I now want to get a Web Server running on the board. I used CubeMX and Enabled LWIP_HTTPD on the HTTPD configuration tab. I generated the code and imported it into System Workbench.

I created a simple web page with two html files. I then used makefsdata.exe to create the fsdata.c file and added it to the project.

When I compile the project, I get these errors:
Middlewares/Third_Party/LwIP/src/apps/httpd/fsdata.o:(.rodata+0x0): multiple definition of `file__related_html'
Middlewares/Third_Party/LwIP/src/apps/httpd/fs.o:(.rodata+0x0): first defined here
Middlewares/Third_Party/LwIP/src/apps/httpd/fsdata.o:(.rodata+0x14): multiple definition of `file__programming_html'
Middlewares/Third_Party/LwIP/src/apps/httpd/fs.o:C:\STMNew\Eth-Test\Release/../Middlewares/Third_Party/LwIP/src/apps/httpd/fs.c:85: first defined here

The compiler flags these two lines as errors:

for (f = FS_ROOT; f != NULL; f = f->next) {
if (!strcmp(name, (const char *)f->name)) { data = (const char *)f->data;
file->len = f->len;
file->index = f->len;
file->pextension = NULL;
file->flags = f->flags;


The forum cut off part of my post. This is the remainder.

The compiler flags these two lines as errors:

for (f = FS_ROOT; f != NULL; f = f->next) {
if (!strcmp(name, (const char *)f->name)) { data = (const char *)f->data;
file->len = f->len;
file->index = f->len;
file->pextension = NULL;
file->flags = f->flags;



For some reason, the forum won't let me post the rest of my code and question. The code turns purple and doesn't show up in the preview screen. I don't see code tags so I don't know how to show the lines of code where the compiler is flagging the errors.

There is a for loop in fs.c where the compiler says the html files are being redefined. The code at that point is apparently reading the files in and parsing them out. But the compiler seems to think the files are being redefiined at that point. If there was a way of posting code, I could show exactly where the error is.

The fsdata.c file defines them this way:

static const unsigned char data__programming_html[] = {
/* /programming.html (18 chars) */
0x2f,0x70,0x72,0x6f,0x67,0x72,0x61,0x6d,0x6d,0x69,0x6e,0x67,0x2e,0x68,0x74,0x6d,
0x6c,0x00,0x00,0x00,

static const unsigned char data__related_html[] = {
/* /related.html (14 chars) */
0x2f,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x2e,0x68,0x74,0x6d,0x6c,0x00,0x00,0x00,

Is there a document available that has instructions on how to setup a Web Server using System Workbench? I've searched but haven't really turned up any useful information. I do find some stuff for LWIP v1.0.1. But I assume System Workbench is using some variation of v2.x.x



Hi,

For posting code you could place them between {CODE()} and {CODE} that will present it like this:
for (f = FS_ROOT; f != NULL; f = f->next) {
    if (!strcmp(name, (const char *)f->name)) { data = (const char *)f->data;
        file->len = f->len;

The violet color is an attempt (usually failed) of the Wysiwig editor to highlight syntax...

Regarding your problem, it looks like fsdata.c is #included by fs.c and also compiled separately by System Workbench for Linux. You can try right-click on fsdata.c then select "Properties" and in "C/C++ Build" and tick the "Exclude resource from build" checkbox.

I've already seen other cases where include files were incorrectly given the ".c" extension, leading to such an errors.

Hope this helps,

Bernard (Ac6)



Bernard,

I am not running Linux. I am using Windows. If I exclude fsdata.c from the build, the program builds successfully without errors.

However, if I type the IP address in the URL bar of Firefox, I get "Unable to connect" message. I checked the lwipopts.h file and I see #define LWIP_HTTPD 1. I can ping the Discovery board and it replies to the ping request.

If I look in the Release->Middlewares->Third_Party->LwIP->apps->httpd folder, I see httpd.o but no fsdata.o. I assume the html code is in httpd.o. Is that correct? The web code includes an index.html file which is what the browser would be looking for.

Does anything else need to be done to start the HTTPD server? I believe that would be taken care if by the call to HAL_LWIP_Init in main.c.

It would be nice if there was a guide somewhere that told how to setup a HTTPD server using CubeMX and System Workbench.



Hi,

Why do you talk of Linux vs Windows; your problem was clearly not linked to your development platform but to the structure of the code. I just mentioned that #include-ing a ".c" file in another one was quite a bad idea as IDEs will quite often compile all ".c" files, yielding to weird errors like the one you encounter. I just check that this was indeed the case of the lwip httpd server (in fs.c line 42...)

Regarding starting the HTTP server, I don't really know but the help window of the LWIP_HTTPD configuration option of CubeMX says "Enable HTTPD requires user specific code not yet generated by STM32Cube MX." so yes it is possible that you need to initialize the HTTPD server manually; the way to do that probably depends on several other parameters:

  • Do you use FreeRTOS or not?
  • Which API have you configured in lwip: the "raw" API, netconn or socket (both requiring FreeRTOS)?

Anyway looking at the code for the http server (in httpd.c) it's clear you should at least call "httpd_init()" from your main program, just before your main loop.

Moreover, as the httpd server was using the "raw" API, you should call repetitively the "MX_LWIP_Process()" function (defined in "lwip.c") in your main loop, or received requests will never get passed to th ehttpd server.

Bernard (Ac6)



Bernard,

I only mentioned Linux because you mentioned it in your first reply. I did not #include any files. All #includes were generated by CubeMX before I imported the project into System Workbench.

I am using the raw API, no RTOS. I previously searched for the function httpd_init() in the files and did not find it. After reading your post, I scrolled through httpd.c and found the function. I #included httpd.h in main.c and added the function call after the MX_LWIP_Init() function call. That has made a difference as I now get an error message "The connection to the server was reset while the page was loading." when I put the IP into the URL bar.

I removed all my html code except index.html and one jpg file that index.html refers to and used makefsdata.exe to regenerate the fsdata.c file. The only thing in the index.html code is a reference to the jpg file. The index.html file opens in Firefox and displays the jpg file.

I am not using LWIP_HTTPD_SSI or LWIP_HTTPD_CGI. I wanted to keep everything as simple as possible until I was able to get the server working.

I am calling MX_LWIP_Process() repetitively in my main loop. Ping will not work without that call. That is really all I am doing other than blinking a couple of LEDs. The code looks like this:

while (1)
{
ticks = 500;
while(ticks != 0xFFFF)
{
MX_LWIP_Process();
}
HAL_GPIO_TogglePin(GPIOD, LED1);
HAL_GPIO_TogglePin(GPIOD, LED2);
}

The ticks variable is being incremented in the sys_ticks() system call.

Any other suggestions? So far you have been really helpful. I think I will eventually get this going.

Ray



Bernard,

I determined that I was able to telnet to the HTTPD server on port 80 and it would answer. That confirmed the server was working.

So I had an idea. The index.html file I was using was built using Dreamweaver CS3. I wondered if that was the issue.

I created a simple html file in notepad and saved it as index.html. I used makefsdata.exe to create a new fsdata.c file. I then recompiled the code. When I put the IP address in the URL bar, it pulled up the web page for the index.html file that I had created.

So the web server is working. It must be very particular about what type of html code it will accept.

Do you know of any limitations on the types of html files that the server can handle?

Ray



Hi ray,

I don't think Dreamweaver has anything to do with the problem, but the fact that you do not call MX_LWIP_Process fast enough; The problem is probably rather created as the Dreamweaver-generated file is a lot bigger.

You should rather code you main loop as follows:
while (1)
{
    MX_LWIP_Process();
    if (ticks == 0xFFFF)
    {
        ticks = 500;
        HAL_GPIO_TogglePin(GPIOD, LED1);
        HAL_GPIO_TogglePin(GPIOD, LED2);
    }
}

Bernard (Ac6)



Bernard,

I found the issue with the web code. Dreamweaver creates a dwsync.xml file in each sub-directory. I don't know exactly what they are doing. Inside each file there are lines of text for each html file in the directory that says the web server IP is 172.16.1.1 and the dirctory for the html files is /var/www/html. That IP and directory is where I tested the web code on my Linux box as it was being developed. By deleting those files, I was able to have the web site come up on the Discoery board.

The only other problem I found is that the makefsdata.exe program has a problem with sub-directories. I ended up having to put all the html code in one directory or I could not compile the code in System Workbench.

As an example, I had a file StockPhone.jpg in the images directory. The makefsdata tool created this structure:
const struct fsdata_file file_images_StockPhone_jpg[] = Rest of structure.

Trying to compile that code, I get an error message that the symbol could not be found. It was the same error message for any files in any sub-directory. As I said, moving everything to one root directory solved the problem. This will not be a problem for my application, as I will only have a single directory for the html code.



Show posts: