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 Samuel Mokrani

main.cpp

Committer:
chris
Date:
2012-10-26
Revision:
3:d1d4b7d317d1
Parent:
1:31e50fea8be8
Child:
4:79f9caf3d109

File content as of revision 3:d1d4b7d317d1:

#include "mbed.h"
#include "WiflyInterface.h"
#include "Websocket.h"


/* wifly interface:
*     - p9 and p10 are for the serial communication
*     - p30 is for the reset pin
*     - p29 is for the connection status
*     - "mbed" is the ssid of the network
*     - "password" is the password
*     - WPA is the security
*/

WiflyInterface wifly(p9, p10, p30, p29, "mbed", "password", WPA);

int main()
{
    int i=0;
    char mystr[32];

    wifly.init(); //Use DHCP
    while (!wifly.connect());
    printf("IP Address is %s\n\r", wifly.getIPAddress());

    Websocket ws("ws://sockets.mbed.org:443/ws/app-board/wo");
    // See the output on http://sockets.mbed.org/app-board/viewer
    while (!ws.connect());

    ws.send("mbed application board");
    ws.send("Hello world!");

    while (1) {
        sprintf(mystr,"%d",i);
        ws.send(mystr);
        wait(1.0);
        i++;
    }
}