8 years, 2 months ago.

what is the default MAC of WIZ550io?

I have been trying to connect Nucleo F401RE to WIZ550io and at present using this as an example https://developer.mbed.org/users/hudakz/code/WebSwitch_WIZ550io/

With the following code (in the main function) I am reading the MAC address as 00:00:00:00:00:00.

In the same code, IP address, default gateway etc are being assigned as int ret = eth.init(MY_IP, MY_NETMASK, MY_GATEWAY); and Now MAC address when printed on the screen, appears as FF:FF:FF:FF:FF:FF. The IP, netmask values are all wrong and when printed, appears to be 255.255.255.255.

Could someone please suggest what I am doing wrong?

/* 
 * In this project LED1 on the mbed board is switched on/off using a web browser.
 * However, you can easily modify the project to remotely switch on/off any external device.
 * The HTTP server is built from an mbed board and a WIZ550io board.
 * The example is based on the Tuxgraphics Web Switch <http://www.tuxgraphics.org/>.
 */
#include "mbed.h"
#include "EthernetInterface.h"
#include <string>

using namespace     std;



Serial              serial(USBTX, USBRX);

SPI spi(PC_12, PC_11, PC_10); // mosi, miso, sclk
EthernetInterface eth(&spi, PC_6, PB_8);//



// Note:
// If it happends that any of the SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS or RESET pins collide with LED1 pin
// then either use different SPI port (if available on the board) and change the pin names
// in the constructor spi(...) accordingly or instead of using LED1 pin, select
// a free pin (not used by SPI port) and connect to it an external LED which is connected
// to a 220 Ohm resitor that is connected to the groud.
// In the second case remember to replace LED1 in sw(LED1) constructor (see below).
// IP address must be also unique and compatible with your network. Change as appropriate.
const char          MY_IP[] = "163.1.6.228";
const char          MY_NETMASK[] = "255.255.255.0";
const char          MY_GATEWAY[] = "163.1.6.254";
int                 MY_PORT = 8080;

TCPSocketServer     server;
TCPSocketConnection client;
bool                serverIsListening = false;

DigitalOut          sw(LED2);   // Change LED1 to a pin of your choice.
                                // However, make sure that it does not collide with any of the SPI pins

const string        PASSWORD = "secret";    // change as you like
const string        HTTP_OK = "HTTP/1.0 200 OK";
const string        MOVED_PERM = "HTTP/1.0 301 Moved Permanently\r\nLocation: ";
const string        UNAUTHORIZED = "HTTP/1.0 401 Unauthorized";

string              httpHeader;     // HTTP header
string              httpContent;    // HTTP content

// analyse the url given
// return values: -1 invalid password
//                -2 no command given but password valid
//                -3 just refresh page
//                 0 switch off
//                 1 switch on
//
//                The string passed to this function will look like this:
//                GET /password HTTP/1.....
//                GET /password/ HTTP/1.....
//                GET /password/?sw=1 HTTP/1.....

//                GET /password/?sw=0 HTTP/1.....
int8_t analyse_get_url(string& str) {
    if(str.substr(5, PASSWORD.size()) != PASSWORD)
        return(-1);

    uint8_t pos = 5 + PASSWORD.size();

    if(str.substr(pos, 1) == " ")
        return(-2);

    if(str.substr(pos, 1) != "/")
        return(-1);

    pos++;

    string  cmd(str.substr(pos, 5));

    if(cmd == "?sw=0")
        return(0);

    if(cmd == "?sw=1")
        return(1);

    return(-3);
}

/**
 * @brief
 * @note
 * @param
 * @retval
 */
string& moved_perm(uint8_t flag) {
    if(flag == 1)
        httpContent = "/" + PASSWORD + "/";
    else
        httpContent = "";

    httpContent += "<h1>301 Moved Permanently</h1>\r\n";

    return(httpContent);
}

/**
 * @brief
 * @note
 * @param
 * @retval
 */
string& view(uint8_t status) {
    httpContent = "<h2>Web Switch</h2>\r\n";

    if(status == 1) {
        httpContent += "<pre>\r\n  <font color=#FF0000>ON</font>";
        httpContent += " <a href=\"./?sw=0\">[switch off]</a>\r\n";
    }
    else {
        httpContent += "<pre>\r\n  <font color=#00FF00>OFF</font>";
        httpContent += " <a href=\"./?sw=1\">[switch on]</a>\r\n";
    }

    httpContent += "  <a href=\".\">[refresh status]</a>\r\n";
    httpContent += "</pre>\r\n";
    httpContent += "<hr>\r\n";
    return httpContent;
}

/**
 * @brief
 * @note
 * @param
 * @retval
 */
void http_send(TCPSocketConnection& client, string& header, string& content) {
    char    content_length[5] = { };

    header += "\r\nContent-Type: text/html\r\n";
    header += "Content-Length: ";
    sprintf(content_length, "%d", content.length());
    header += string(content_length) + "\r\n";
    header += "Pragma: no-cache\r\n";
    header += "Connection: About to close\r\n";
    header += "\r\n";

    string  webpage = header + content;
    client.send (const_cast<char*>(webpage.c_str ()), webpage.length ());
}

/**
 * @brief
 * @note
 * @param
 * @retval
 */
 

int main(void) {

    serial.printf("*************************\n");
    serial.printf("Pre Initialized, MY_MAC: %s\n", eth.getMACAddress());
    int     ret = eth.init(MY_IP, MY_NETMASK, MY_GATEWAY);
    wait(1);


    if(!ret) {
        serial.printf("Initialized, MY_MAC: %s\n", eth.getMACAddress());
        serial.printf
            (
                "Connected, MY_IP: %s\n MY_NETMASK: %s\n MY_GATEWAY: %s\n",
                eth.getIPAddress(),
                eth.getNetworkMask(),
                eth.getGateway()
            );
    }
    else {
        serial.printf("Error eth.init() - ret = %d\n", ret);
        return -1;
    }

    //setup tcp socket
    if(server.bind(MY_PORT) < 0) {
        serial.printf("TCP server bind failed.\n\r");
        return -1;
    }
    else {
        serial.printf("TCP server bind succeeded.\n\r");
        serverIsListening = true;
    }

    if(server.listen(1) < 0) {
        serial.printf("TCP server listen failed.\n\r");
        return -1;
    }
    else {
        serial.printf("TCP server is listening...\n\r");
    }

    while(serverIsListening) {
        if(server.accept(client) >= 0) {
            char    buf[1024] = { };
            size_t  size = 0;
            
            serial.printf("Client connected!\n\rIP: %s\n\r", client.get_address());
            
            switch(client.receive(buf, 1023)) {
            case 0:
                serial.printf("Recieved buffer is empty.\n\r");
                break;

            case -1:
                serial.printf("Failed to read data from client.\n\r");
                break;

            default:
                size = strlen(buf);

                string  received((char*)buf);

                if(received.substr(0, 3) != "GET") {
                    httpHeader = HTTP_OK;
                    httpContent = "<h1>200 OK</h1>";
                    http_send(client, httpHeader, httpContent);
                    continue;
                }

                if(received.substr(0, 6) == "GET / ") {
                    httpHeader = HTTP_OK;
                    httpContent = "<p>Usage: http://host_or_ip/password</p>\r\n";
                    http_send(client, httpHeader, httpContent);
                    continue;
                }

                int cmd = analyse_get_url(received);

                if(cmd == -2) {

                    // redirect to the right base url
                    httpHeader = MOVED_PERM;
                    http_send(client, httpHeader, moved_perm(1));
                    continue;
                }

                if(cmd == -1) {
                    httpHeader = UNAUTHORIZED;
                    httpContent = "<h1>401 Unauthorized</h1>";
                    http_send(client, httpHeader, httpContent);
                    continue;
                }

                if(cmd == 1) {
                    sw = 1; // switch on
                }

                if(cmd == 0) {
                    sw = 0; // switch off
                }

                httpHeader = HTTP_OK;
                http_send(client, httpHeader, view(sw));
            }

            client.close();

            serial.printf("Connection closed.\n\rTCP server is listening...\n\r");
        }
    }
}

2 Answers

8 years, 2 months ago.

Please review your SPI wiring / pinout - the answer to your question is posted here:

http://wizwiki.net/wiki/doku.php?id=products:wiz550io:allpages

Update:

Hi Baljit. Your SPI definition looks fine for the use of SPI3 port but please consider to test the example with the same pinouts and methods defined here for your module:

https://developer.mbed.org/users/hudakz/code/WebSwitch_WIZ550io/file/3803ea61daa1/main.cpp

#elif defined(TARGET_NUCLEO_F401RE)
EthernetInterface   eth(PB_5, PB_4, PB_3, PB_10, PA_8); // MOSI, MISO, SCK, CS, RESET

https://developer.mbed.org/users/hudakz/code/WebSwitch_WIZ550io/

Update # 2

Hey Baljit. Please try again with:

192.168.1.181/secret/

as shown on this webpage:

https://developer.mbed.org/users/hudakz/code/WebSwitch_WIZ550io/

  • see the URL on the phone photo
  • ALSO change the definition of this IP address inside your source code as shown here:

https://developer.mbed.org/users/hudakz/code/WebSwitch_WIZ550io/file/3803ea61daa1/main.cpp

  • the same 192.168.1.181 is present and must match to get started with this module

// IP address must be also unique and compatible with your network. Change as appropriate.
const char          MY_IP[] = "192.168.1.181";
const char          MY_NETMASK[] = "255.255.255.0";
const char          MY_GATEWAY[] = "192.168.1.1";
int                 MY_PORT = 80;

Update # 3

Hi Baljit. Not an expert on this topic but suspecting the issue is now local network related. Consider to download and run the recommended utility posted on the following Wiznet wiki page:

http://www.wiznet.co.kr/product-item/wiz550io/

Download, run and configure the posted AX1 tool as documented. With this tool and cross network cable (noted in their docs if using PC to module direct connection which may be your issue), you should be able to ping your module using your host computer (the wiring should be just between your PC and this external Wiznet module and without external hubs / network switches, etc.). The Wiznet module will be configured by your Nucleo board.With the proper tools, you should be able to get this to work. Start with the ping tests to be sure you can ping the module.

In addition to the above tool, review how this author pings the Wiznet module as shown on the following webpage:

http://www.ermicro.com/blog/?p=1773

/media/uploads/juthi/wiznet_ping.png

Please attempt the same testing using your defined IP address. Once you start receiving a reply from the Wiznet module, you should be able to serve the referenced webpage. Good luck and do post your results.

Dear Sanjiv,

Could you please give more details?

I am using SPI3 of F401RE board. I have checked wiring layout which seems to be correct as per the WIZ550io requirements, such as MOSI, MISO, CLK of the F401RE SPI are connected to the respective pins of Wiz device. The remaining pins PC_6, PB_8 of F401RE are just the standard GPIO pins and connected to SCSn and RSTn, respectively of Wiz device.

posted by Baljit Riar 22 Jan 2016

Thanks, I tried using the below as you suggested and wired WIZ to the new F401RE pins

#elif defined(TARGET_NUCLEO_F401RE)
EthernetInterface   eth(PB_5, PB_4, PB_3, PB_10, PA_8); // MOSI, MISO, SCK, CS, RESET

Now all the parameters are initialised as desired, which is good. Why does it work with these pins and not for SPI3?

But when I type 163.1.6.228/secret into browser, it does not open any webpage?

Any suggestions please?

posted by Baljit Riar 25 Jan 2016

Follow up from Update 2#

I tried changing the definitions IP and others to that of the given example, but unfortunately it did open the webpage. I think IP address needs to be matched to that of the PC, because the PC and the WIZnet are connected to the LAN. Ofcourse, the device is already added to the network here and is allocated with its IP address as stated in my original post.

I have also tried using my laptop so that there is no LAN involved, but could not succeed with this option either.

Thank you once again and looking forward to hear more from you!

posted by Baljit Riar 25 Jan 2016

Follow up Update # 3

Hi Sanjiv, I have been able to ping the device even when connected to LAN and hence don't believe LAN has anything to do with it. But could not open the webpage. I will keep trying the other option that you suggested.

posted by Baljit Riar 25 Jan 2016

Hi Baljit, What message did you get from the server? If it says "Usage: http://host_or_ip/password" then you probably missed to type in the closing slash. Provided the ping works with 163.1.6.228, then try

163.1.6.228/secret/

(Notice the slash at the end of URL).

posted by Zoltan Hudak 26 Jan 2016

Hi Zoltan,

As I am using the LAN, I was missing a port number, which is required, 163.1.6.228:8080/secret/

posted by Baljit Riar 03 Feb 2016
8 years, 2 months ago.

Hi

I heard that you had problem via Bongjun Hur. So I tried to check your code and run using NUCLEO-F103RB and WIZ550io. And then I found some problem in your code.

I think you have to use dedicated SPI pins for using SPI function of NUCLEO. So I modified your code as below.

SPI spi(PB_5, PB_4, PB_3); // mosi, miso, sclk
EthernetInterface eth(&spi, PB_10, PA_8);//

After then, It operated well. This picture is result which I operated your code.

/media/uploads/kaizen/20160127_093846.png

If you have another question or problem, contact to me.

Thank you.

/* 
 * In this project LED1 on the mbed board is switched on/off using a web browser.
 * However, you can easily modify the project to remotely switch on/off any external device.
 * The HTTP server is built from an mbed board and a WIZ550io board.
 * The example is based on the Tuxgraphics Web Switch <http://www.tuxgraphics.org/>.
 */
#include "mbed.h"
#include "EthernetInterface.h"
#include <string>
 
using namespace     std;
 
 
 
Serial              serial(USBTX, USBRX);
 
SPI spi(PB_5, PB_4, PB_3); // mosi, miso, sclk
EthernetInterface eth(&spi, PB_10, PA_8);//
 
 
 
// Note:
// If it happends that any of the SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS or RESET pins collide with LED1 pin
// then either use different SPI port (if available on the board) and change the pin names
// in the constructor spi(...) accordingly or instead of using LED1 pin, select
// a free pin (not used by SPI port) and connect to it an external LED which is connected
// to a 220 Ohm resitor that is connected to the groud.
// In the second case remember to replace LED1 in sw(LED1) constructor (see below).
// IP address must be also unique and compatible with your network. Change as appropriate.
const char          MY_IP[] = "192.168.1.150";
const char          MY_NETMASK[] = "255.255.255.0";
const char          MY_GATEWAY[] = "192.168.1.1";
int                 MY_PORT = 8080;
 
TCPSocketServer     server;
TCPSocketConnection client;
bool                serverIsListening = false;
 
DigitalOut          sw(LED2);   // Change LED1 to a pin of your choice.
                                // However, make sure that it does not collide with any of the SPI pins
 
const string        PASSWORD = "secret";    // change as you like
const string        HTTP_OK = "HTTP/1.0 200 OK";
const string        MOVED_PERM = "HTTP/1.0 301 Moved Permanently\r\nLocation: ";
const string        UNAUTHORIZED = "HTTP/1.0 401 Unauthorized";
 
string              httpHeader;     // HTTP header
string              httpContent;    // HTTP content
 
// analyse the url given
// return values: -1 invalid password
//                -2 no command given but password valid
//                -3 just refresh page
//                 0 switch off
//                 1 switch on
//
//                The string passed to this function will look like this:
//                GET /password HTTP/1.....
//                GET /password/ HTTP/1.....
//                GET /password/?sw=1 HTTP/1.....
 
//                GET /password/?sw=0 HTTP/1.....
int8_t analyse_get_url(string& str) {
    if(str.substr(5, PASSWORD.size()) != PASSWORD)
        return(-1);
 
    uint8_t pos = 5 + PASSWORD.size();
 
    if(str.substr(pos, 1) == " ")
        return(-2);
 
    if(str.substr(pos, 1) != "/")
        return(-1);
 
    pos++;
 
    string  cmd(str.substr(pos, 5));
 
    if(cmd == "?sw=0")
        return(0);
 
    if(cmd == "?sw=1")
        return(1);
 
    return(-3);
}
 
/**
 * @brief
 * @note
 * @param
 * @retval
 */
string& moved_perm(uint8_t flag) {
    if(flag == 1)
        httpContent = "/" + PASSWORD + "/";
    else
        httpContent = "";
 
    httpContent += "<h1>301 Moved Permanently</h1>\r\n";
 
    return(httpContent);
}
 
/**
 * @brief
 * @note
 * @param
 * @retval
 */
string& view(uint8_t status) {
    httpContent = "<h2>Web Switch</h2>\r\n";
 
    if(status == 1) {
        httpContent += "<pre>\r\n  <font color=#FF0000>ON</font>";
        httpContent += " <a href=\"./?sw=0\">[switch off]</a>\r\n";
    }
    else {
        httpContent += "<pre>\r\n  <font color=#00FF00>OFF</font>";
        httpContent += " <a href=\"./?sw=1\">[switch on]</a>\r\n";
    }
 
    httpContent += "  <a href=\".\">[refresh status]</a>\r\n";
    httpContent += "</pre>\r\n";
    httpContent += "<hr>\r\n";
    return httpContent;
}
 
/**
 * @brief
 * @note
 * @param
 * @retval
 */
void http_send(TCPSocketConnection& client, string& header, string& content) {
    char    content_length[5] = { };
 
    header += "\r\nContent-Type: text/html\r\n";
    header += "Content-Length: ";
    sprintf(content_length, "%d", content.length());
    header += string(content_length) + "\r\n";
    header += "Pragma: no-cache\r\n";
    header += "Connection: About to close\r\n";
    header += "\r\n";
 
    string  webpage = header + content;
    client.send (const_cast<char*>(webpage.c_str ()), webpage.length ());
}
 
/**
 * @brief
 * @note
 * @param
 * @retval
 */
 
 
int main(void) {
 
    serial.printf("*************************\n");
    serial.printf("Pre Initialized, MY_MAC: %s\n", eth.getMACAddress());
    int     ret = eth.init(MY_IP, MY_NETMASK, MY_GATEWAY);
    wait(1);
 
 
    if(!ret) {
        serial.printf("Initialized, MY_MAC: %s\n", eth.getMACAddress());
        serial.printf
            (
                "Connected, MY_IP: %s\n MY_NETMASK: %s\n MY_GATEWAY: %s\n",
                eth.getIPAddress(),
                eth.getNetworkMask(),
                eth.getGateway()
            );
    }
    else {
        serial.printf("Error eth.init() - ret = %d\n", ret);
        return -1;
    }
 
    //setup tcp socket
    if(server.bind(MY_PORT) < 0) {
        serial.printf("TCP server bind failed.\n\r");
        return -1;
    }
    else {
        serial.printf("TCP server bind succeeded.\n\r");
        serverIsListening = true;
    }
 
    if(server.listen(1) < 0) {
        serial.printf("TCP server listen failed.\n\r");
        return -1;
    }
    else {
        serial.printf("TCP server is listening...\n\r");
    }
 
    while(serverIsListening) {
        if(server.accept(client) >= 0) {
            char    buf[1024] = { };
            size_t  size = 0;
            
            serial.printf("Client connected!\n\rIP: %s\n\r", client.get_address());
            
            switch(client.receive(buf, 1023)) {
            case 0:
                serial.printf("Recieved buffer is empty.\n\r");
                break;
 
            case -1:
                serial.printf("Failed to read data from client.\n\r");
                break;
 
            default:
                size = strlen(buf);
 
                string  received((char*)buf);
 
                if(received.substr(0, 3) != "GET") {
                    httpHeader = HTTP_OK;
                    httpContent = "<h1>200 OK</h1>";
                    http_send(client, httpHeader, httpContent);
                    continue;
                }
 
                if(received.substr(0, 6) == "GET / ") {
                    httpHeader = HTTP_OK;
                    httpContent = "<p>Usage: http://host_or_ip/password</p>\r\n";
                    http_send(client, httpHeader, httpContent);
                    continue;
                }
 
                int cmd = analyse_get_url(received);
 
                if(cmd == -2) {
 
                    // redirect to the right base url
                    httpHeader = MOVED_PERM;
                    http_send(client, httpHeader, moved_perm(1));
                    continue;
                }
 
                if(cmd == -1) {
                    httpHeader = UNAUTHORIZED;
                    httpContent = "<h1>401 Unauthorized</h1>";
                    http_send(client, httpHeader, httpContent);
                    continue;
                }
 
                if(cmd == 1) {
                    sw = 1; // switch on
                }
 
                if(cmd == 0) {
                    sw = 0; // switch off
                }
 
                httpHeader = HTTP_OK;
                http_send(client, httpHeader, view(sw));
            }
 
            client.close();
 
            serial.printf("Connection closed.\n\rTCP server is listening...\n\r");
        }
    }
}

Dear DongEun Koak,

Thank you for the reply. Why does wiznet works with particular pins of Mbed when wiznet needs a SPI connection to run? This SPI connection could be provided from any pins of Mbed (as long as SPI is enabled on those pins).

Do you have example project with which Wiznet can be used for data logging (sending and receiving) using mbed controller?

I will appreciate your help.

posted by Baljit Riar 27 Jan 2016

Dear Baljit Riar

I think you'd like to check that Nucleo generate SPI3 signal normally. If Nucleo generate SPI3 signal, WIZ550io will operate well. So you have to check what SPI3 signal of Nucleo is generated firstly.

And, About your second question, please refer to this URL for data logging example. https://developer.mbed.org/users/Bongjun/code/WIZ550io_Xively_Demo/

posted by DongEun Koak 01 Feb 2016