websocket and ble

Dependencies:   WebSocketClient WiflyInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 
00004 Serial device(p9,p10);
00005 DigitalOut led1(LED1);
00006 DigitalOut led2(LED2);
00007 
00008 #include "WiflyInterface.h"
00009 #include "Websocket.h"
00010 WiflyInterface wifly(p13, p14, p19, p26, "WWNet", "mmmmmmmm", WPA);
00011 char buf[10];
00012 
00013 int main() {
00014     
00015     wifly.init(); //Use DHCP
00016     while (!wifly.connect());
00017     led1=1;
00018     
00019     Websocket ws("ws://sockets.mbed.org/ws/mbedschool/viewer");
00020     while (!ws.connect());
00021     led2=1;
00022     ws.send("ws connect");
00023     
00024     int i=0;
00025     //set mbed baud rate the same as BLE mini baud rate
00026     device.baud(38400);
00027     //simple polling demonstrate serial communication
00028     while(1) {
00029         if(device.readable()) {
00030             char data[1];          
00031             data[0] = device.getc();
00032             ws.send(data);           
00033                         
00034             i++;  
00035         }
00036         wait(0.1);
00037     }
00038 }