|
1 | 1 | MBED WIC Wrapper |
2 | 2 | ================ |
3 | 3 |
|
| 4 | +This example makes it a breeze to use WIC on MBED. |
| 5 | + |
| 6 | +## WICClient |
| 7 | + |
| 8 | +This is a wrapper class for client mode. |
| 9 | + |
| 10 | +- supports TCP and TLS modes (determined by target URL) |
| 11 | +- supports redirects (with configurable maximum number of redirects) |
| 12 | +- blocking interfaces which must be called from a non-interrupt |
| 13 | + context |
| 14 | +- handles full-duplex socket 'backpressure' |
| 15 | + |
| 16 | +WICClient makes use of a number of synchronisation features in |
| 17 | +order to work reliably in a multithreaded MBED application. These |
| 18 | +include: |
| 19 | + |
| 20 | +- dedicated threads for reading and writing |
| 21 | +- mailboxes for incoming and outgoing messages/fragments |
| 22 | +- event loop for serialising access to wic_inst and managing timing |
| 23 | +- mutex and condition variable on application facing interfaces to |
| 24 | + implement blocking |
| 25 | + |
| 26 | +The application below will try to connect every 10 seconds. Once connected, it will |
| 27 | +send "hello world!" every 5 seconds. If the connection fails, it will return |
| 28 | +to trying to open the connection. |
| 29 | + |
| 30 | +~~~ c++ |
| 31 | +#include "wic_client.hpp" |
| 32 | +#include "EthernetInterface.h" |
| 33 | + |
| 34 | +int main() |
| 35 | +{ |
| 36 | + static EthernetInterface eth; |
| 37 | + |
| 38 | + eth.connect(); |
| 39 | + |
| 40 | + static WICClient client(eth); |
| 41 | + |
| 42 | + for(;;){ |
| 43 | + |
| 44 | + if(client.open("ws://echo.websocket.org/")){ |
| 45 | + |
| 46 | + while(client.is_open()){ |
| 47 | + |
| 48 | + client.text("hello world!"); |
| 49 | + wait_us(5000); |
| 50 | + } |
| 51 | + } |
| 52 | + else{ |
| 53 | + |
| 54 | + wait_us(10000); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | +~~~ |
| 59 | + |
| 60 | +## WICServer |
| 61 | + |
| 62 | +No support for this mode at this time. |
| 63 | + |
| 64 | +## Installation |
| 65 | + |
| 66 | +Clone the WIC repository into a directory in your MBED project. |
| 67 | +The `.mbed-ignore` file is written in such a way that the right sources |
| 68 | +will be found by the build system. |
| 69 | + |
| 70 | +## License |
| 71 | + |
| 72 | +MIT |
| 73 | + |
0 commit comments