![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
qsdasd
main.cpp@6:2fae6e37c5ca, 2017-03-16 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Mar 16 21:15:06 2017 +0000
- Revision:
- 6:2fae6e37c5ca
- Parent:
- 3:9bd22e5386cd
- Child:
- 8:e8ebb98f3c83
Updated example to utilize mbed-os and the new websocket client library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 6:2fae6e37c5ca | 1 | /* Copyright C2014 ARM, MIT License |
mbed_official | 6:2fae6e37c5ca | 2 | * |
mbed_official | 6:2fae6e37c5ca | 3 | * Author: Doug Anson (doug.anson@arm.com) |
mbed_official | 6:2fae6e37c5ca | 4 | * |
mbed_official | 6:2fae6e37c5ca | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
mbed_official | 6:2fae6e37c5ca | 6 | * and associated documentation files the "Software", to deal in the Software without restriction, |
mbed_official | 6:2fae6e37c5ca | 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
mbed_official | 6:2fae6e37c5ca | 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
mbed_official | 6:2fae6e37c5ca | 9 | * furnished to do so, subject to the following conditions: |
mbed_official | 6:2fae6e37c5ca | 10 | * |
mbed_official | 6:2fae6e37c5ca | 11 | * The above copyright notice and this permission notice shall be included in all copies or |
mbed_official | 6:2fae6e37c5ca | 12 | * substantial portions of the Software. |
mbed_official | 6:2fae6e37c5ca | 13 | * |
mbed_official | 6:2fae6e37c5ca | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
mbed_official | 6:2fae6e37c5ca | 15 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
mbed_official | 6:2fae6e37c5ca | 16 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
mbed_official | 6:2fae6e37c5ca | 17 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mbed_official | 6:2fae6e37c5ca | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
mbed_official | 6:2fae6e37c5ca | 19 | */ |
mbed_official | 6:2fae6e37c5ca | 20 | |
samux | 1:1c1802ec42a2 | 21 | #include "mbed.h" |
samux | 1:1c1802ec42a2 | 22 | #include "EthernetInterface.h" |
samux | 1:1c1802ec42a2 | 23 | #include "Websocket.h" |
sam_grove | 3:9bd22e5386cd | 24 | |
mbed_official | 6:2fae6e37c5ca | 25 | // Blinky |
sam_grove | 3:9bd22e5386cd | 26 | DigitalOut led(LED1); |
mbed_official | 6:2fae6e37c5ca | 27 | |
mbed_official | 6:2fae6e37c5ca | 28 | int main() { |
mbed_official | 6:2fae6e37c5ca | 29 | |
mbed_official | 6:2fae6e37c5ca | 30 | // announce |
mbed_official | 6:2fae6e37c5ca | 31 | printf("Websocket Example v1.0.0\r\n"); |
sam_grove | 3:9bd22e5386cd | 32 | |
mbed_official | 6:2fae6e37c5ca | 33 | // Create a network interface and connect |
mbed_official | 6:2fae6e37c5ca | 34 | EthernetInterface eth; |
mbed_official | 6:2fae6e37c5ca | 35 | eth.connect(); |
mbed_official | 6:2fae6e37c5ca | 36 | printf("IP Address is %s\n\r", eth.get_ip_address()); |
sam_grove | 3:9bd22e5386cd | 37 | |
mbed_official | 6:2fae6e37c5ca | 38 | // Create a websocket instance |
mbed_official | 6:2fae6e37c5ca | 39 | Websocket ws("ws://example.com:8080/", ð); |
mbed_official | 6:2fae6e37c5ca | 40 | int connect_error = ws.connect(); |
sam_grove | 3:9bd22e5386cd | 41 | |
mbed_official | 6:2fae6e37c5ca | 42 | // begin main loop |
mbed_official | 6:2fae6e37c5ca | 43 | while (true) { |
mbed_official | 6:2fae6e37c5ca | 44 | |
mbed_official | 6:2fae6e37c5ca | 45 | // blink... |
mbed_official | 6:2fae6e37c5ca | 46 | led = !led; |
mbed_official | 6:2fae6e37c5ca | 47 | wait(0.5); |
mbed_official | 6:2fae6e37c5ca | 48 | |
mbed_official | 6:2fae6e37c5ca | 49 | int error_c = ws.send("Hello World\r\n"); |
samux | 1:1c1802ec42a2 | 50 | } |
samux | 1:1c1802ec42a2 | 51 | } |