tes

Dependencies:   ASyncTicker EthernetInterface WebSocketClient mbed-rtos mbed MbedJSONValue xbee_lib

main.cpp

Committer:
ammanvedi
Date:
2014-01-27
Revision:
0:d73af3f5c81d
Child:
1:6c1df6c9be4d

File content as of revision 0:d73af3f5c81d:

#include "mbed.h"
#include "EthernetInterface.h"
#include <stdio.h>
#include <string.h>
#include "Websocket.h"
#include "Updateable.h"
#include "ASyncTicker.h"
#define PORT   80


EthernetInterface ethernet;
Websocket ws("ws://192.168.0.4:8080/");
Ticker pull_ticker;



void pull_updates(){
  wait(0.1f);
  printf("%s", "hello");

}

int main ()
{

    ethernet.init();    // connect with DHCP
    int ret_val = ethernet.connect();
 
    if (0 == ret_val) {
        printf("IP Address: %s\n\r", ethernet.getIPAddress());
    } else {
        error("ethernet failed to connect: %d.\n\r", ret_val);
    }
    
    
    ws.connect();
    
        char str[100];
    // string with a message
        sprintf(str, "PU");
        ws.send(str);
    
        // clear the buffer and wait a sec...
        memset(str, 0, 100);
        wait(0.5f);
    
        // websocket server should echo whatever we sent it
        if (ws.read(str)) {
            printf("rcv'd: %s\n\r", str);
        }
        ws.close();
        pull_ticker.attach(&pull_updates, 5.0);
        while(1){
            
            wait(0.1f);
            }

}