websocket and ble
Dependencies: WebSocketClient WiflyInterface mbed
main.cpp@0:92abfdf28c93, 2015-02-07 (annotated)
- Committer:
- mbedschool
- Date:
- Sat Feb 07 06:08:45 2015 +0000
- Revision:
- 0:92abfdf28c93
mbed websocket and BLE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedschool | 0:92abfdf28c93 | 1 | #include "mbed.h" |
mbedschool | 0:92abfdf28c93 | 2 | |
mbedschool | 0:92abfdf28c93 | 3 | |
mbedschool | 0:92abfdf28c93 | 4 | Serial device(p9,p10); |
mbedschool | 0:92abfdf28c93 | 5 | DigitalOut led1(LED1); |
mbedschool | 0:92abfdf28c93 | 6 | DigitalOut led2(LED2); |
mbedschool | 0:92abfdf28c93 | 7 | |
mbedschool | 0:92abfdf28c93 | 8 | #include "WiflyInterface.h" |
mbedschool | 0:92abfdf28c93 | 9 | #include "Websocket.h" |
mbedschool | 0:92abfdf28c93 | 10 | WiflyInterface wifly(p13, p14, p19, p26, "WWNet", "mmmmmmmm", WPA); |
mbedschool | 0:92abfdf28c93 | 11 | char buf[10]; |
mbedschool | 0:92abfdf28c93 | 12 | |
mbedschool | 0:92abfdf28c93 | 13 | int main() { |
mbedschool | 0:92abfdf28c93 | 14 | |
mbedschool | 0:92abfdf28c93 | 15 | wifly.init(); //Use DHCP |
mbedschool | 0:92abfdf28c93 | 16 | while (!wifly.connect()); |
mbedschool | 0:92abfdf28c93 | 17 | led1=1; |
mbedschool | 0:92abfdf28c93 | 18 | |
mbedschool | 0:92abfdf28c93 | 19 | Websocket ws("ws://sockets.mbed.org/ws/mbedschool/viewer"); |
mbedschool | 0:92abfdf28c93 | 20 | while (!ws.connect()); |
mbedschool | 0:92abfdf28c93 | 21 | led2=1; |
mbedschool | 0:92abfdf28c93 | 22 | ws.send("ws connect"); |
mbedschool | 0:92abfdf28c93 | 23 | |
mbedschool | 0:92abfdf28c93 | 24 | int i=0; |
mbedschool | 0:92abfdf28c93 | 25 | //set mbed baud rate the same as BLE mini baud rate |
mbedschool | 0:92abfdf28c93 | 26 | device.baud(38400); |
mbedschool | 0:92abfdf28c93 | 27 | //simple polling demonstrate serial communication |
mbedschool | 0:92abfdf28c93 | 28 | while(1) { |
mbedschool | 0:92abfdf28c93 | 29 | if(device.readable()) { |
mbedschool | 0:92abfdf28c93 | 30 | char data[1]; |
mbedschool | 0:92abfdf28c93 | 31 | data[0] = device.getc(); |
mbedschool | 0:92abfdf28c93 | 32 | ws.send(data); |
mbedschool | 0:92abfdf28c93 | 33 | |
mbedschool | 0:92abfdf28c93 | 34 | i++; |
mbedschool | 0:92abfdf28c93 | 35 | } |
mbedschool | 0:92abfdf28c93 | 36 | wait(0.1); |
mbedschool | 0:92abfdf28c93 | 37 | } |
mbedschool | 0:92abfdf28c93 | 38 | } |