The compiler is usually right, so if it is complaining something is wrong. Showing me two lines that haven't been cut-n-pasted from the failing code correctly doesn't help me diagnose the issue.
The 'file' pointer ultimately needs to point at some memory that describes some 'struct fs_file'
/* Read the data from the port, blocking if nothing yet there.
We assume the request (the part we care about) is in one netbuf */ recv_err = netconn_recv(conn, &inbuf); if (recv_err == ERR_OK) { if (netconn_err(conn) == ERR_OK) { netbuf_data(inbuf, (void**)&buf, &buflen);
/* Is this an HTTP GET command? (only check the first 5 chars, since
there are other formats for GET, and we're keeping it very simple )*/ if ((buflen >=5) && (strncmp(buf, 'GET /', 5) == 0)) { /* Check if request to get ST.gif */ if (strncmp((char const *)buf,'GET /STM32F4xx_files/ST.gif',27)==0) { recv_err = fs_open(file,'/STM32F4xx_files/ST.gif'); netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY); fs_close(file); } /* Check if request to get stm32.jpeg */ else if (strncmp((char const *)buf,'GET /STM32F4xx_files/stm32.jpg',30)==0) { recv_err = fs_open(file,'/STM32F4xx_files/stm32.jpg'); netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY); fs_close(file); } else if (strncmp((char const *)buf,'GET /STM32F4xx_files/logo.jpg', 29) == 0) { /* Check if request to get ST logo.jpg */ recv_err = fs_open(file,'/STM32F4xx_files/logo.jpg'); netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY); fs_close(file); } else if(strncmp(buf, 'GET /STM32F4xxTASKS.html', 24) == 0) { /* Load dynamic page */ DynWebPage(conn); } else if((strncmp(buf, 'GET /STM32F4xx.html', 19) == 0)||(strncmp(buf, 'GET / ', 6) == 0)) { /* Load STM32F4x7 page */ recv_err = fs_open(file,'/STM32F4xx.html'); netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY); fs_close(file); } else { /* Load Error page */ recv_err = fs_open(file,'/404.html'); netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY); fs_close(file); } } } } /* Close the connection (server closes in HTTP) */ netconn_close(conn); /* Delete the buffer (netconn_recv gives us ownership, so we have to make sure to deallocate the buffer) */ netbuf_delete(inbuf);}/** * @brief http server thread * @param arg: pointer on argument(not used here) * @retval None */static void http_server_netconn_thread(void *arg){ struct netconn *conn, *newconn; err_t err, accept_err; /* Create a new TCP connection handle */ conn = netconn_new(NETCONN_TCP); if (conn!= NULL) { /* Bind to port 80 (HTTP) with default IP address */ err = netconn_bind(conn, NULL, 80); if (err == ERR_OK) { /* Put the connection into LISTEN state */ netconn_listen(conn); while(1) { /* accept any incoming connection */ accept_err = netconn_accept(conn, &newconn); if(accept_err == ERR_OK) { /* serve connection */ http_server_serve(newconn);
/* delete connection */
netconn_delete(newconn); } } } }}
/**
* @brief Initialize the HTTP server (start its thread) * @param none * @retval None */void http_server_netconn_init(void){ sys_thread_new('HTTP', http_server_netconn_thread, NULL, DEFAULT_THREAD_STACKSIZE, osPriorityAboveNormal);}
/* Read the data from the port, blocking if nothing yet there.
We assume the request (the part we care about) is in one netbuf */ recv_err = netconn_recv(conn, &inbuf);
if (recv_err == ERR_OK)
{ if (netconn_err(conn) == ERR_OK) { netbuf_data(inbuf, (void**)&buf, &buflen);
/* Is this an HTTP GET command? (only check the first 5 chars, since
there are other formats for GET, and we're keeping it very simple )*/ if ((buflen >=5) && (strncmp(buf, 'GET /', 5) == 0)) { /* Check if request to get ST.gif */ if (strncmp((char const *)buf,'GET /STM32F7xx_files/ST.gif',27)==0) { fs_open(&file, '/STM32F7xx_files/ST.gif'); netconn_write(conn, (const unsigned char*)(file.data), (size_t)file.len, NETCONN_NOCOPY); fs_close(&file); } /* Check if request to get stm32.jpeg */ else if (strncmp((char const *)buf,'GET /STM32F7xx_files/stm32.jpg',30)==0) { fs_open(&file, '/STM32F7xx_files/stm32.jpg'); netconn_write(conn, (const unsigned char*)(file.data), (size_t)file.len, NETCONN_NOCOPY); fs_close(&file); }
...
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..