An example program that uses a Wifly module to send messages over web sockets
Dependencies: WebSocketClient WiflyInterface mbed LM75B MMA7660
Fork of Websocket_Wifly_HelloWorld by
main.cpp@3:d1d4b7d317d1, 2012-10-26 (annotated)
- Committer:
- chris
- Date:
- Fri Oct 26 12:39:09 2012 +0000
- Revision:
- 3:d1d4b7d317d1
- Parent:
- 1:31e50fea8be8
- Child:
- 4:79f9caf3d109
First commit;
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: |
samux | 1:31e50fea8be8 | 7 | * - p9 and p10 are for the serial communication |
chris | 3:d1d4b7d317d1 | 8 | * - p30 is for the reset pin |
chris | 3:d1d4b7d317d1 | 9 | * - p29 is for the connection status |
samux | 1:31e50fea8be8 | 10 | * - "mbed" 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 | */ |
chris | 3:d1d4b7d317d1 | 14 | |
chris | 3:d1d4b7d317d1 | 15 | WiflyInterface wifly(p9, p10, p30, p29, "mbed", "password", WPA); |
samux | 1:31e50fea8be8 | 16 | |
chris | 3:d1d4b7d317d1 | 17 | int main() |
chris | 3:d1d4b7d317d1 | 18 | { |
chris | 3:d1d4b7d317d1 | 19 | int i=0; |
chris | 3:d1d4b7d317d1 | 20 | char mystr[32]; |
chris | 3:d1d4b7d317d1 | 21 | |
samux | 1:31e50fea8be8 | 22 | wifly.init(); //Use DHCP |
samux | 1:31e50fea8be8 | 23 | while (!wifly.connect()); |
samux | 1:31e50fea8be8 | 24 | printf("IP Address is %s\n\r", wifly.getIPAddress()); |
samux | 1:31e50fea8be8 | 25 | |
chris | 3:d1d4b7d317d1 | 26 | Websocket ws("ws://sockets.mbed.org:443/ws/app-board/wo"); |
chris | 3:d1d4b7d317d1 | 27 | // See the output on http://sockets.mbed.org/app-board/viewer |
samux | 1:31e50fea8be8 | 28 | while (!ws.connect()); |
samux | 1:31e50fea8be8 | 29 | |
chris | 3:d1d4b7d317d1 | 30 | ws.send("mbed application board"); |
chris | 3:d1d4b7d317d1 | 31 | ws.send("Hello world!"); |
chris | 3:d1d4b7d317d1 | 32 | |
samux | 1:31e50fea8be8 | 33 | while (1) { |
chris | 3:d1d4b7d317d1 | 34 | sprintf(mystr,"%d",i); |
chris | 3:d1d4b7d317d1 | 35 | ws.send(mystr); |
chris | 3:d1d4b7d317d1 | 36 | wait(1.0); |
chris | 3:d1d4b7d317d1 | 37 | i++; |
samux | 1:31e50fea8be8 | 38 | } |
samux | 0:64c683256184 | 39 | } |