mbed_websocket_client_for_gps
Dependencies: WebSocketClient WiflyInterface mbed
main.cpp@0:ba2e56067722, 2015-02-04 (annotated)
- Committer:
- mbedschool
- Date:
- Wed Feb 04 04:37:48 2015 +0000
- Revision:
- 0:ba2e56067722
mbed_sebsocket_client_for_gps
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedschool | 0:ba2e56067722 | 1 | #include "mbed.h" |
mbedschool | 0:ba2e56067722 | 2 | #include "WiflyInterface.h" |
mbedschool | 0:ba2e56067722 | 3 | #include "Websocket.h" |
mbedschool | 0:ba2e56067722 | 4 | |
mbedschool | 0:ba2e56067722 | 5 | |
mbedschool | 0:ba2e56067722 | 6 | |
mbedschool | 0:ba2e56067722 | 7 | |
mbedschool | 0:ba2e56067722 | 8 | |
mbedschool | 0:ba2e56067722 | 9 | /* wifly interface: |
mbedschool | 0:ba2e56067722 | 10 | * - p9 and p10 are for the serial communication |
mbedschool | 0:ba2e56067722 | 11 | * - p19 is for the reset pin |
mbedschool | 0:ba2e56067722 | 12 | * - p26 is for the connection status |
mbedschool | 0:ba2e56067722 | 13 | * - "mbed" is the ssid of the network |
mbedschool | 0:ba2e56067722 | 14 | * - "password" is the password |
mbedschool | 0:ba2e56067722 | 15 | * - WPA is the security |
mbedschool | 0:ba2e56067722 | 16 | */ |
mbedschool | 0:ba2e56067722 | 17 | WiflyInterface wifly(p28, p27, p19, p26, "SEEED-MKT", "depot0510", WPA); |
mbedschool | 0:ba2e56067722 | 18 | DigitalOut led1(LED1); |
mbedschool | 0:ba2e56067722 | 19 | Serial gps(p9, p10); |
mbedschool | 0:ba2e56067722 | 20 | char buffer[65]; |
mbedschool | 0:ba2e56067722 | 21 | int count=0; |
mbedschool | 0:ba2e56067722 | 22 | void clearBufferArray() // function to clear buffer array |
mbedschool | 0:ba2e56067722 | 23 | { |
mbedschool | 0:ba2e56067722 | 24 | for (int i=0; i<count;i++) |
mbedschool | 0:ba2e56067722 | 25 | { buffer[i]=NULL;} // clear all index of array with command NULL |
mbedschool | 0:ba2e56067722 | 26 | } |
mbedschool | 0:ba2e56067722 | 27 | |
mbedschool | 0:ba2e56067722 | 28 | int main() { |
mbedschool | 0:ba2e56067722 | 29 | //wifly.init(); //Use DHCP |
mbedschool | 0:ba2e56067722 | 30 | wifly.init("192.168.21.45","255.255.255.0","192.168.21.2"); |
mbedschool | 0:ba2e56067722 | 31 | while (!wifly.connect()); |
mbedschool | 0:ba2e56067722 | 32 | led1=1; |
mbedschool | 0:ba2e56067722 | 33 | printf("IP Address is %s\n\r", wifly.getIPAddress()); |
mbedschool | 0:ba2e56067722 | 34 | |
mbedschool | 0:ba2e56067722 | 35 | Websocket ws("ws://192.168.21.123:8888"); |
mbedschool | 0:ba2e56067722 | 36 | while (!ws.connect()); |
mbedschool | 0:ba2e56067722 | 37 | led1=2; |
mbedschool | 0:ba2e56067722 | 38 | |
mbedschool | 0:ba2e56067722 | 39 | count=0; |
mbedschool | 0:ba2e56067722 | 40 | while (1) { |
mbedschool | 0:ba2e56067722 | 41 | char locatedata[256]; |
mbedschool | 0:ba2e56067722 | 42 | |
mbedschool | 0:ba2e56067722 | 43 | while(gps.readable ()) // reading data into char array |
mbedschool | 0:ba2e56067722 | 44 | { |
mbedschool | 0:ba2e56067722 | 45 | char data[1]; |
mbedschool | 0:ba2e56067722 | 46 | data[0] = gps.getc(); |
mbedschool | 0:ba2e56067722 | 47 | |
mbedschool | 0:ba2e56067722 | 48 | ws.send(data); |
mbedschool | 0:ba2e56067722 | 49 | } |
mbedschool | 0:ba2e56067722 | 50 | // ws.send(buffer); // if no data transmission ends, write buffer to hardware serial port |
mbedschool | 0:ba2e56067722 | 51 | clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array |
mbedschool | 0:ba2e56067722 | 52 | count = 0; |
mbedschool | 0:ba2e56067722 | 53 | |
mbedschool | 0:ba2e56067722 | 54 | wait(1.0); |
mbedschool | 0:ba2e56067722 | 55 | } |
mbedschool | 0:ba2e56067722 | 56 | } |