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
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "Websocket.h" 00004 00005 DigitalOut myled(LED1); 00006 00007 int main() 00008 { 00009 printf("Start Websocket Demo. \r\n"); 00010 00011 #if defined(TARGET_LPC1114) 00012 SPI spi(dp2, dp1, dp6); // mosi, miso, sclk 00013 EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset 00014 00015 #elif defined(TARGET_LPC1768) 00016 SPI spi(p11, p12, p13); // mosi, miso, sclk 00017 EthernetInterface eth(&spi, p14, p15); // spi, cs, reset 00018 00019 #elif defined(TARGET_LPC11U68) 00020 SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk 00021 //WIZnetInterface eth(&spi, P0_2, P1_25); // spi, cs, reset 00022 //SPI spi(p5, p6, p7); // mosi, miso, sclk 00023 EthernetInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io 00024 spi.format(8,0); // 8bit, mode 0 00025 spi.frequency(7000000); // 7MHz 00026 wait(1); // 1 second for stable state 00027 00028 #endif 00029 00030 eth.init(); //Use DHCP 00031 printf("Initialized, MAC: %s\r\n", eth.getMACAddress()); 00032 eth.connect(); 00033 //printf("IP Address is %s\n\r", eth.getIPAddress()); 00034 printf("Connected, IP: %s, MASK: %s, GW: %s\r\n",eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); 00035 /* 00036 // as your env. change to real IP address and so on. 00037 //int ret = eth.init(your IP, Subnet, Gateway); 00038 int ret = eth.init("xxx.xxx.xxx.xxx", "255.255.255.0", "yyy.yyy.yyy.yyy"); 00039 if (!ret) { 00040 printf("Initialized, MAC: %s\r\n", eth.getMACAddress()); 00041 printf("Connected, IP: %s, MASK: %s, GW: %s\r\n", 00042 eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); 00043 } else { 00044 printf("Error eth.init() - ret = %d\r\n", ret); 00045 return -1; 00046 } 00047 */ 00048 00049 // Websocket ws("ws://sockets.mbed.org:443/ws/demo/wo"); 00050 // ws.connect(); 00051 00052 // this code from http://mbed.org/teams/mbed/code/Websocket_Ethernet_HelloWorld/file/bd0a76c1d9d0/main.cpp 00053 // view @ http://sockets.mbed.org/demo/viewer 00054 Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); 00055 ws.connect(); 00056 00057 char str[100]; 00058 00059 for(int i=0; i<0x10; ++i) { 00060 00061 sprintf(str, "%dth WebSocket message for WIZnet W5500 Hello World over Ethernet.", i); 00062 ws.send(str); 00063 // clear the buffer and wait a sec... 00064 memset(str, 0, 100); 00065 wait(0.5f); 00066 00067 // websocket server should echo whatever we sent it 00068 if (ws.read(str)) { 00069 printf("Recv : %s\r\n", str); 00070 } 00071 } 00072 ws.close(); 00073 eth.disconnect(); 00074 00075 while(1) { 00076 myled = 1; 00077 wait(0.2); 00078 myled = 0; 00079 wait(0.2); 00080 } 00081 }
Generated on Sun Jul 17 2022 10:03:26 by 1.7.2