cc3000 websocket demo for cc3000
Dependencies: NVIC_set_all_priorities WebSocketClient cc3000_hostdriver_mbedsocket mbed
main.cpp@10:a7f01c5e1e19, 2013-11-07 (annotated)
- Committer:
- Kojto
- Date:
- Thu Nov 07 20:18:18 2013 +0000
- Revision:
- 10:a7f01c5e1e19
- Parent:
- 9:822a9333d544
- updated to the host driver rev 45; - using the new EthernetInterface
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 6:62b6aa700f85 | 1 | /* mbed Microcontroller Library |
Kojto | 6:62b6aa700f85 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Kojto | 6:62b6aa700f85 | 3 | * |
Kojto | 6:62b6aa700f85 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Kojto | 6:62b6aa700f85 | 5 | * you may not use this file except in compliance with the License. |
Kojto | 6:62b6aa700f85 | 6 | * You may obtain a copy of the License at |
Kojto | 6:62b6aa700f85 | 7 | * |
Kojto | 6:62b6aa700f85 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Kojto | 6:62b6aa700f85 | 9 | * |
Kojto | 6:62b6aa700f85 | 10 | * Unless required by applicable law or agreed to in writing, software |
Kojto | 6:62b6aa700f85 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Kojto | 6:62b6aa700f85 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Kojto | 6:62b6aa700f85 | 13 | * See the License for the specific language governing permissions and |
Kojto | 6:62b6aa700f85 | 14 | * limitations under the License. |
Kojto | 6:62b6aa700f85 | 15 | */ |
Kojto | 6:62b6aa700f85 | 16 | #include "mbed.h" |
Kojto | 6:62b6aa700f85 | 17 | #include "cc3000.h" |
Kojto | 6:62b6aa700f85 | 18 | #include "main.h" |
Kojto | 6:62b6aa700f85 | 19 | |
Kojto | 6:62b6aa700f85 | 20 | #include "Websocket.h" |
Kojto | 6:62b6aa700f85 | 21 | |
Kojto | 6:62b6aa700f85 | 22 | using namespace mbed_cc3000; |
Kojto | 6:62b6aa700f85 | 23 | |
Kojto | 6:62b6aa700f85 | 24 | /* cc3000 module declaration specific for user's board. Check also init() */ |
Kojto | 6:62b6aa700f85 | 25 | #if (MY_BOARD == WIGO) |
Kojto | 10:a7f01c5e1e19 | 26 | cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false); |
Kojto | 6:62b6aa700f85 | 27 | Serial pc(USBTX, USBRX); |
Kojto | 6:62b6aa700f85 | 28 | #elif (MY_BOARD == WIFI_DIPCORTEX) |
Kojto | 10:a7f01c5e1e19 | 29 | cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false); |
Kojto | 6:62b6aa700f85 | 30 | Serial pc(UART_TX, UART_RX); |
Kojto | 10:a7f01c5e1e19 | 31 | #elif (MY_BOARD == MBED_BOARD_EXAMPLE) |
Kojto | 10:a7f01c5e1e19 | 32 | cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false); |
Kojto | 10:a7f01c5e1e19 | 33 | Serial pc(USBTX, USBRX); |
Kojto | 6:62b6aa700f85 | 34 | #else |
Kojto | 6:62b6aa700f85 | 35 | |
Kojto | 6:62b6aa700f85 | 36 | #endif |
Kojto | 6:62b6aa700f85 | 37 | |
Kojto | 6:62b6aa700f85 | 38 | /** |
Kojto | 6:62b6aa700f85 | 39 | * \brief Websocket demo |
Kojto | 6:62b6aa700f85 | 40 | * \param none |
Kojto | 6:62b6aa700f85 | 41 | * \return int |
Kojto | 6:62b6aa700f85 | 42 | */ |
Kojto | 6:62b6aa700f85 | 43 | int main() { |
Kojto | 6:62b6aa700f85 | 44 | init(); /* board dependent init */ |
Kojto | 6:62b6aa700f85 | 45 | pc.baud(115200); |
Kojto | 6:62b6aa700f85 | 46 | |
Kojto | 6:62b6aa700f85 | 47 | printf("cc3000 Websocket demo. \r\n"); |
Kojto | 10:a7f01c5e1e19 | 48 | wifi.init(); |
Kojto | 10:a7f01c5e1e19 | 49 | if (wifi.connect() == -1) { |
Kojto | 10:a7f01c5e1e19 | 50 | printf("Failed to connect. Please verify connection details and try again. \r\n"); |
Kojto | 6:62b6aa700f85 | 51 | } else { |
Kojto | 10:a7f01c5e1e19 | 52 | printf("IP address: %s \r\n", wifi.getIPAddress()); |
Kojto | 6:62b6aa700f85 | 53 | } |
Kojto | 6:62b6aa700f85 | 54 | |
Kojto | 9:822a9333d544 | 55 | /* change your_channel to your defined nickname */ |
Kojto | 9:822a9333d544 | 56 | Websocket ws("ws://sockets.mbed.org/ws/your_channel/wo"); |
Kojto | 6:62b6aa700f85 | 57 | while (!ws.connect()); |
Kojto | 6:62b6aa700f85 | 58 | |
Kojto | 6:62b6aa700f85 | 59 | printf("Connected to websocket server. \r\n"); |
Kojto | 6:62b6aa700f85 | 60 | while (1) { |
Kojto | 6:62b6aa700f85 | 61 | ws.send("WebSocket Hello World over cc3000"); |
Kojto | 6:62b6aa700f85 | 62 | wait(1.0); |
Kojto | 6:62b6aa700f85 | 63 | } |
Kojto | 6:62b6aa700f85 | 64 | } |