2018-05-27 03:03 AM
2018-05-28 07:23 AM
Try this:
struct fs_file file;
recv_err = fs_open(&file,'/STM32F4xx_files/ST.gif');
-- pa
2018-05-28 07:30 AM
here all the code for the http server based on netconn
/**
* @brief serve tcp connection * @param conn: pointer on connection structure * @retval None */void http_server_serve(struct netconn *conn) { struct netbuf *inbuf; err_t recv_err; char* buf; u16_t buflen; struct fs_file * 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);}2018-05-28 07:56 AM
It means it wants a pointer, and you provided a pointer to a pointer, ie the address of a pointer rather the address of a structure
If a function wants ptr, don't use &ptr
2018-05-28 08:38 AM
fichier != file, and the file pointer needs to actually point to some physical memory
2018-05-28 09:06 AM
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'
struct fs_file foofile;
struct fs_file *file = &foofile;recv_err = fs_open ( file, '/STM32F4xx_files/ST.gif');2018-05-29 07:44 AM
Per examples, you're supposed to be passing a pointer to a pointer so that fs_open can fill that pointer with a 'handle' to it's own structure.
recv_err = fs_open(&file,'/STM32F4xx_files/ST.gif');
See STM32Cube_FW_F7_V1.9.0\Projects\STM32746G-Discovery\Applications\LwIP\LwIP_HTTP_Server_Netconn_RTOS\Src\httpserver-netconn.c (or equivalent)
/**
* @brief serve tcp connection * @param conn: pointer on connection structure * @retval None */static void http_server_serve(struct netconn *conn){ struct netbuf *inbuf; err_t recv_err; char* buf; u16_t buflen; struct fs_file 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 /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); }...