7 years, 9 months ago.

How to set Static IP address with Nucleo F767ZI?

Hi,All.

I have a Nucleo F767ZI board.

The following sample program worked normally(with DHCP address).

"New -> Nucleo-F767ZI -> A small example of TCP server over ethernet for mbed-OS"

However, setting a static IP address as described below will result in an error.

main.cpp

#if !FEATURE_LWIP
    #error [NOT_SUPPORTED] LWIP not supported for this target
#endif

#include "mbed.h"
#include "EthernetInterface.h"
#include "TCPServer.h"
#include "TCPSocket.h"

#define HTTP_STATUS_LINE "HTTP/1.0 200 OK"
#define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8"
#define HTTP_MESSAGE_BODY ""                                     \
"<html>" "\r\n"                                                  \
"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
"    <div style=\"margin:auto\">" "\r\n"                         \
"      <h1>Hello World</h1>" "\r\n"                              \
"      <p>It works !</p>" "\r\n"                                 \
"    </div>" "\r\n"                                              \
"  </body>" "\r\n"                                               \
"</html>"

#define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n"   \
                      HTTP_HEADER_FIELDS "\r\n" \
                      "\r\n"                    \
                      HTTP_MESSAGE_BODY "\r\n"

int main()
{
    printf("Basic HTTP server example\n");
    
    EthernetInterface eth;
    //eth.init("192.168.3.24","255.255.252.0","192.168.3.1"); // <---------- Compile Error
    //eth.init(); //  <----------------------------------------------------- Compile Error
    eth.connect();
    
    printf("The target IP address is '%s'\n", eth.get_ip_address());
    
    TCPServer srv;
    TCPSocket clt_sock;
    SocketAddress clt_addr;
    
    /* Open the server on ethernet stack */
    srv.open(&eth);
    
    /* Bind the HTTP port (TCP 80) to the server */
    srv.bind(eth.get_ip_address(), 80);
    
    /* Can handle 5 simultaneous connections */
    srv.listen(5);
    
    while (true) {
        srv.accept(&clt_sock, &clt_addr);
        printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port());
        clt_sock.send(HTTP_RESPONSE, strlen(HTTP_RESPONSE));
    }
}

Please tell me how to solve.

1 Answer

7 years, 7 months ago.

Quote:

    //eth.init("192.168.3.24","255.255.252.0","192.168.3.1"); // <---------- Compile Error
    //eth.init(); //  <----------------------------------------------------- Compile Error

Your problem is you the wrong member function. You must use the following function.

   eth.set_network("192.168.3.24","255.255.252.0","192.168.3.1");

or with macros... it's somthing like this

   eth.set_network(IP_Adress,GATEWAY,MASK);

but the problem is, on my NUCLEO F767ZI i can only connect to my tcp-server when i'm using DHCP. When i'm try to use static IP my NUCLEO F767ZI didn't answer the "how has" (ARP) question (didn't sends his MAC-Adress) from the clint....

Accepted Answer

Hi, Hendrik. I'm sorry for the late reply. I have not operated MBED for a long time. MBED worked normally with your advice. Thank you.

posted by Image Writer 03 Nov 2018