Modifed version from Samuel Mokrani Changed URL to push data to sensor page Added visualisation page URL as a comment

Dependencies:   EthernetInterface MMA7660 WebSocketClient mbed-rtos mbed LM75B

Fork of Websocket_Ethernet_acc by Samuel Mokrani

main.cpp

Committer:
samux
Date:
2013-02-08
Revision:
2:1fae595547d5
Parent:
1:1ca9c7ae7e0b

File content as of revision 2:1fae595547d5:

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

// accelerometer
MMA7660 acc(p28, p27);

// temperature sensor
LM75B tmp(p28,p27);

DigitalOut l1(LED1);
 
int main() {
    char json_str[100];
    
    if (acc.testConnection())
        l1 = 1;
 
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address is %s\n\r", eth.getIPAddress());
    
    // See the output on http://sockets.mbed.org/app-board/viewer
    Websocket ws("ws://sockets.mbed.org:443/ws/app-board/wo");
    ws.connect();
 
    while (1) {
        // create json string with acc/tmp data
        sprintf(json_str, "{\"id\":\"app_board_eth_EW2013\",\"ax\":%d,\"ay\":%d,\"az\":%d, \"tmp\":%d}", (int)(acc.x()*360), (int)(acc.y()*360), (int)(acc.z()*360), (int)tmp.read());
        
        // send str
        ws.send(json_str);
        
        wait(0.1);
    }
}