Websocket demo for app board by C. Styles with updated libraries. DHCP service and a network cable is required.

Dependencies:   EthernetInterface LM75B MMA7660 WebSocketClient mbed-rtos mbed

Fork of app-board-Ethernet-Websocket by Chris Styles

main.cpp

Committer:
chris
Date:
2012-10-26
Revision:
1:1ca9c7ae7e0b
Parent:
0:11bb5faeb547
Child:
2:1fae595547d5

File content as of revision 1:1ca9c7ae7e0b:

#include "mbed.h"
#include "EthernetInterface.h"
#include "Websocket.h"
#include "MMA7660.h"

MMA7660 MMA(p28, p27);

DigitalOut l1(LED1);
 
int main() {
    char json_str[100];
    
    if (MMA.testConnection())
        l1 = 1;
 
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address is %s\n\r", eth.getIPAddress());
    
    Websocket ws("ws://sockets.mbed.org/ws/sensors/wo");
    // visit http://tools.mbed.org/iot/ to see the realtime graph
    ws.connect();
 
    while (1) {
        sprintf(json_str, "{\"id\":\"mbed-app-board\",\"ax\":\"%d\",\"ay\":\"%d\",\"az\":\"%d\"}", (int)(MMA.x()*200), (int)(MMA.y()*200), (int)(MMA.z()*200));
        ws.send(json_str);
        wait(0.2);
    }
}