![](/media/cache/group/7eebcc78c9728c99279acaac1d5c9078.jpg.50x50_q85.jpg)
Websocket Test Program for W5500 or WIZ550io ( WIZnet, http://wizwiki.net ) LPC11U68 Xpresso v2 + WIZ550io Ethernet Board.
Dependencies: W5500Interface WebSocketClient mbed
Fork of Websocket_Ethernet_W5500 by
Websocket example using Ethernet component of WIZ550io (W5500)
How to put W5500 on your mbed board?
It's tested on LPC11U68 Board.
main.cpp@6:f20b8a6b33f3, 2014-09-01 (annotated)
- Committer:
- Bongjun
- Date:
- Mon Sep 01 01:55:17 2014 +0000
- Revision:
- 6:f20b8a6b33f3
- Parent:
- 5:75e9b8457321
Correction of a bug in socket::close() via Pull Request of Patrick Pollet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bongjun | 0:2efa5e59223d | 1 | #include "mbed.h" |
Bongjun | 5:75e9b8457321 | 2 | #include "EthernetInterface.h" |
Bongjun | 0:2efa5e59223d | 3 | #include "Websocket.h" |
Bongjun | 0:2efa5e59223d | 4 | |
Bongjun | 0:2efa5e59223d | 5 | DigitalOut myled(LED1); |
Bongjun | 0:2efa5e59223d | 6 | |
Bongjun | 0:2efa5e59223d | 7 | int main() |
Bongjun | 0:2efa5e59223d | 8 | { |
Bongjun | 5:75e9b8457321 | 9 | printf("Start Websocket Demo. \r\n"); |
Bongjun | 5:75e9b8457321 | 10 | |
Bongjun | 0:2efa5e59223d | 11 | #if defined(TARGET_LPC1114) |
Bongjun | 0:2efa5e59223d | 12 | SPI spi(dp2, dp1, dp6); // mosi, miso, sclk |
Bongjun | 5:75e9b8457321 | 13 | EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset |
Bongjun | 0:2efa5e59223d | 14 | |
Bongjun | 0:2efa5e59223d | 15 | #elif defined(TARGET_LPC1768) |
Bongjun | 0:2efa5e59223d | 16 | SPI spi(p11, p12, p13); // mosi, miso, sclk |
Bongjun | 5:75e9b8457321 | 17 | EthernetInterface eth(&spi, p14, p15); // spi, cs, reset |
Bongjun | 0:2efa5e59223d | 18 | |
Bongjun | 0:2efa5e59223d | 19 | #elif defined(TARGET_LPC11U68) |
Bongjun | 0:2efa5e59223d | 20 | SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk |
Bongjun | 0:2efa5e59223d | 21 | //WIZnetInterface eth(&spi, P0_2, P1_25); // spi, cs, reset |
Bongjun | 0:2efa5e59223d | 22 | //SPI spi(p5, p6, p7); // mosi, miso, sclk |
Bongjun | 5:75e9b8457321 | 23 | EthernetInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io |
Bongjun | 0:2efa5e59223d | 24 | spi.format(8,0); // 8bit, mode 0 |
Bongjun | 0:2efa5e59223d | 25 | spi.frequency(7000000); // 7MHz |
Bongjun | 0:2efa5e59223d | 26 | wait(1); // 1 second for stable state |
Bongjun | 0:2efa5e59223d | 27 | |
Bongjun | 0:2efa5e59223d | 28 | #endif |
Bongjun | 0:2efa5e59223d | 29 | |
Bongjun | 0:2efa5e59223d | 30 | eth.init(); //Use DHCP |
Bongjun | 5:75e9b8457321 | 31 | printf("Initialized, MAC: %s\r\n", eth.getMACAddress()); |
Bongjun | 0:2efa5e59223d | 32 | eth.connect(); |
Bongjun | 0:2efa5e59223d | 33 | //printf("IP Address is %s\n\r", eth.getIPAddress()); |
Bongjun | 5:75e9b8457321 | 34 | printf("Connected, IP: %s, MASK: %s, GW: %s\r\n",eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); |
Bongjun | 5:75e9b8457321 | 35 | /* |
Bongjun | 1:22e5197655a9 | 36 | // as your env. change to real IP address and so on. |
Bongjun | 5:75e9b8457321 | 37 | //int ret = eth.init(your IP, Subnet, Gateway); |
Bongjun | 5:75e9b8457321 | 38 | int ret = eth.init("xxx.xxx.xxx.xxx", "255.255.255.0", "yyy.yyy.yyy.yyy"); |
Bongjun | 0:2efa5e59223d | 39 | if (!ret) { |
Bongjun | 5:75e9b8457321 | 40 | printf("Initialized, MAC: %s\r\n", eth.getMACAddress()); |
Bongjun | 5:75e9b8457321 | 41 | printf("Connected, IP: %s, MASK: %s, GW: %s\r\n", |
Bongjun | 0:2efa5e59223d | 42 | eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); |
Bongjun | 0:2efa5e59223d | 43 | } else { |
Bongjun | 5:75e9b8457321 | 44 | printf("Error eth.init() - ret = %d\r\n", ret); |
Bongjun | 0:2efa5e59223d | 45 | return -1; |
Bongjun | 0:2efa5e59223d | 46 | } |
Bongjun | 5:75e9b8457321 | 47 | */ |
Bongjun | 0:2efa5e59223d | 48 | |
Bongjun | 0:2efa5e59223d | 49 | // Websocket ws("ws://sockets.mbed.org:443/ws/demo/wo"); |
Bongjun | 0:2efa5e59223d | 50 | // ws.connect(); |
Bongjun | 0:2efa5e59223d | 51 | |
Bongjun | 0:2efa5e59223d | 52 | // this code from http://mbed.org/teams/mbed/code/Websocket_Ethernet_HelloWorld/file/bd0a76c1d9d0/main.cpp |
Bongjun | 0:2efa5e59223d | 53 | // view @ http://sockets.mbed.org/demo/viewer |
Bongjun | 0:2efa5e59223d | 54 | Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); |
Bongjun | 0:2efa5e59223d | 55 | ws.connect(); |
Bongjun | 0:2efa5e59223d | 56 | |
Bongjun | 0:2efa5e59223d | 57 | char str[100]; |
Bongjun | 5:75e9b8457321 | 58 | |
Bongjun | 0:2efa5e59223d | 59 | for(int i=0; i<0x10; ++i) { |
Bongjun | 3:4c02f6287752 | 60 | |
Bongjun | 5:75e9b8457321 | 61 | sprintf(str, "%dth WebSocket message for WIZnet W5500 Hello World over Ethernet.", i); |
Bongjun | 0:2efa5e59223d | 62 | ws.send(str); |
Bongjun | 0:2efa5e59223d | 63 | // clear the buffer and wait a sec... |
Bongjun | 0:2efa5e59223d | 64 | memset(str, 0, 100); |
Bongjun | 0:2efa5e59223d | 65 | wait(0.5f); |
Bongjun | 0:2efa5e59223d | 66 | |
Bongjun | 0:2efa5e59223d | 67 | // websocket server should echo whatever we sent it |
Bongjun | 0:2efa5e59223d | 68 | if (ws.read(str)) { |
Bongjun | 5:75e9b8457321 | 69 | printf("Recv : %s\r\n", str); |
Bongjun | 0:2efa5e59223d | 70 | } |
Bongjun | 0:2efa5e59223d | 71 | } |
Bongjun | 0:2efa5e59223d | 72 | ws.close(); |
Bongjun | 0:2efa5e59223d | 73 | eth.disconnect(); |
Bongjun | 0:2efa5e59223d | 74 | |
Bongjun | 0:2efa5e59223d | 75 | while(1) { |
Bongjun | 0:2efa5e59223d | 76 | myled = 1; |
Bongjun | 0:2efa5e59223d | 77 | wait(0.2); |
Bongjun | 0:2efa5e59223d | 78 | myled = 0; |
Bongjun | 0:2efa5e59223d | 79 | wait(0.2); |
Bongjun | 0:2efa5e59223d | 80 | } |
Bongjun | 0:2efa5e59223d | 81 | } |