WebSocket test using WiflyInterface Tested with FRDM-K64F
Dependencies: WebSocketClient WiflyInterface mbed
Fork of Websocket_Wifly_HelloWorld by
main.cpp@3:5c16d0d73e81, 2014-09-12 (annotated)
- Committer:
- MACRUM
- Date:
- Fri Sep 12 02:09:55 2014 +0000
- Revision:
- 3:5c16d0d73e81
- Parent:
- 1:31e50fea8be8
Initial release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 1:31e50fea8be8 | 1 | #include "mbed.h" |
samux | 1:31e50fea8be8 | 2 | #include "WiflyInterface.h" |
samux | 1:31e50fea8be8 | 3 | #include "Websocket.h" |
samux | 1:31e50fea8be8 | 4 | |
samux | 1:31e50fea8be8 | 5 | |
samux | 1:31e50fea8be8 | 6 | /* wifly interface: |
MACRUM | 3:5c16d0d73e81 | 7 | * - p9 (TX) and p10 (RX) are for the serial communication |
MACRUM | 3:5c16d0d73e81 | 8 | * - p30 is for the reset pin |
MACRUM | 3:5c16d0d73e81 | 9 | * - p29 is for the connection status |
MACRUM | 3:5c16d0d73e81 | 10 | * - "ssid" is the ssid of the network |
samux | 1:31e50fea8be8 | 11 | * - "password" is the password |
samux | 1:31e50fea8be8 | 12 | * - WPA is the security |
samux | 1:31e50fea8be8 | 13 | */ |
MACRUM | 3:5c16d0d73e81 | 14 | #if TARGET_LPC1768 |
MACRUM | 3:5c16d0d73e81 | 15 | WiflyInterface wifly(p9, p10, p30, p29, "ssid", "password", WPA); |
MACRUM | 3:5c16d0d73e81 | 16 | #else |
MACRUM | 3:5c16d0d73e81 | 17 | WiflyInterface wifly(D1, D0, D3, D2, "ssid", "pasword", WPA); |
MACRUM | 3:5c16d0d73e81 | 18 | #endif |
MACRUM | 3:5c16d0d73e81 | 19 | |
MACRUM | 3:5c16d0d73e81 | 20 | DigitalOut led(LED1); |
samux | 1:31e50fea8be8 | 21 | |
samux | 1:31e50fea8be8 | 22 | int main() { |
MACRUM | 3:5c16d0d73e81 | 23 | printf("Wifly WebSocket test\n"); |
samux | 1:31e50fea8be8 | 24 | wifly.init(); //Use DHCP |
samux | 1:31e50fea8be8 | 25 | while (!wifly.connect()); |
MACRUM | 3:5c16d0d73e81 | 26 | printf("IP Address is %s\n", wifly.getIPAddress()); |
samux | 1:31e50fea8be8 | 27 | |
MACRUM | 3:5c16d0d73e81 | 28 | Websocket ws("ws://sockets.mbed.org/ws/443/wo"); |
samux | 1:31e50fea8be8 | 29 | while (!ws.connect()); |
samux | 1:31e50fea8be8 | 30 | |
samux | 1:31e50fea8be8 | 31 | while (1) { |
MACRUM | 3:5c16d0d73e81 | 32 | led = !led; |
samux | 1:31e50fea8be8 | 33 | ws.send("WebSocket Hello World over Wifly"); |
samux | 1:31e50fea8be8 | 34 | wait(1.0); |
samux | 1:31e50fea8be8 | 35 | } |
samux | 0:64c683256184 | 36 | } |