WebSocket Ethernet HelloWorld for WIZnet W5500 chip. It uses "W5500Interface" for Ethernet Interface Library.
Dependencies: W5500Interface WebSocketClient mbed-rtos mbed
Fork of Websocket_Ethernet_HelloWorld by
main.cpp@3:f885a548a5ac, 2014-08-27 (annotated)
- Committer:
- Bongjun
- Date:
- Wed Aug 27 10:03:32 2014 +0000
- Revision:
- 3:f885a548a5ac
- Parent:
- 1:1c1802ec42a2
Websocket_Ethernet_HelloWorld for W5500 (WIZnet) - minimum change
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 1:1c1802ec42a2 | 1 | #include "mbed.h" |
samux | 1:1c1802ec42a2 | 2 | #include "EthernetInterface.h" |
samux | 1:1c1802ec42a2 | 3 | #include "Websocket.h" |
samux | 1:1c1802ec42a2 | 4 | |
samux | 1:1c1802ec42a2 | 5 | |
samux | 1:1c1802ec42a2 | 6 | int main() { |
samux | 1:1c1802ec42a2 | 7 | char recv[30]; |
samux | 1:1c1802ec42a2 | 8 | |
Bongjun | 3:f885a548a5ac | 9 | // EthernetInterface eth; |
Bongjun | 3:f885a548a5ac | 10 | // change for W5500 interface. |
Bongjun | 3:f885a548a5ac | 11 | #if defined(TARGET_LPC1114) |
Bongjun | 3:f885a548a5ac | 12 | SPI spi(dp2, dp1, dp6); // mosi, miso, sclk |
Bongjun | 3:f885a548a5ac | 13 | EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset |
Bongjun | 3:f885a548a5ac | 14 | |
Bongjun | 3:f885a548a5ac | 15 | #elif defined(TARGET_LPC1768) |
Bongjun | 3:f885a548a5ac | 16 | SPI spi(p11, p12, p13); // mosi, miso, sclk |
Bongjun | 3:f885a548a5ac | 17 | EthernetInterface eth(&spi, p14, p15); // spi, cs, reset |
Bongjun | 3:f885a548a5ac | 18 | |
Bongjun | 3:f885a548a5ac | 19 | #elif defined(TARGET_LPC11U68) |
Bongjun | 3:f885a548a5ac | 20 | SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk |
Bongjun | 3:f885a548a5ac | 21 | EthernetInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io |
Bongjun | 3:f885a548a5ac | 22 | spi.format(8,0); // 8bit, mode 0 |
Bongjun | 3:f885a548a5ac | 23 | spi.frequency(7000000); // 7MHz |
Bongjun | 3:f885a548a5ac | 24 | wait(1); // 1 second for stable state |
Bongjun | 3:f885a548a5ac | 25 | #endif |
Bongjun | 3:f885a548a5ac | 26 | |
samux | 1:1c1802ec42a2 | 27 | eth.init(); //Use DHCP |
samux | 1:1c1802ec42a2 | 28 | eth.connect(); |
samux | 1:1c1802ec42a2 | 29 | printf("IP Address is %s\n\r", eth.getIPAddress()); |
samux | 1:1c1802ec42a2 | 30 | |
samux | 1:1c1802ec42a2 | 31 | Websocket ws("ws://sockets.mbed.org:443/ws/demo/wo"); |
samux | 1:1c1802ec42a2 | 32 | ws.connect(); |
samux | 1:1c1802ec42a2 | 33 | |
samux | 1:1c1802ec42a2 | 34 | while (1) { |
samux | 1:1c1802ec42a2 | 35 | ws.send("WebSocket Hello World over Ethernet"); |
samux | 1:1c1802ec42a2 | 36 | wait(1.0); |
samux | 1:1c1802ec42a2 | 37 | } |
samux | 1:1c1802ec42a2 | 38 | } |