Example application of the WifiPlusClick library for use of WifiPlusClick HW Module from Mikroe.com
Dependencies: WifiPlusClick mbed
WifiPlusClick Example
This is a sample application to demonstrate the usage of the WifiPlusClick library.
Import libraryWifiPlusClick
Implementation of the WifiPlusClick hardware module.
main.cpp@0:0a7aeb6d4526, 2013-07-29 (annotated)
- Committer:
- leihen
- Date:
- Mon Jul 29 16:03:21 2013 +0000
- Revision:
- 0:0a7aeb6d4526
General example application for use with the WifiPlusClick Module from MikroElektronika.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leihen | 0:0a7aeb6d4526 | 1 | #include "mbed.h" |
leihen | 0:0a7aeb6d4526 | 2 | #include "WifiPlusClick.h" |
leihen | 0:0a7aeb6d4526 | 3 | #include "TCPSocketServer.h" |
leihen | 0:0a7aeb6d4526 | 4 | |
leihen | 0:0a7aeb6d4526 | 5 | //#define WPA2_PASSWORD |
leihen | 0:0a7aeb6d4526 | 6 | |
leihen | 0:0a7aeb6d4526 | 7 | #ifndef WPA2_PASSWORD |
leihen | 0:0a7aeb6d4526 | 8 | |
leihen | 0:0a7aeb6d4526 | 9 | |
leihen | 0:0a7aeb6d4526 | 10 | // Please note that when using this binary passphrase a connection can be made much faster. |
leihen | 0:0a7aeb6d4526 | 11 | static const char passphrase[32] = { |
leihen | 0:0a7aeb6d4526 | 12 | 0xac, 0x4d, 0x41, 0x29, 0xa4, 0xd8, 0xfd, 0x15, |
leihen | 0:0a7aeb6d4526 | 13 | 0xaf, 0x29, 0xd7, 0x8d, 0xb2, 0x50, 0x3c, 0xd9, |
leihen | 0:0a7aeb6d4526 | 14 | 0xa7, 0x4f, 0x5e, 0x64, 0x5d, 0x82, 0x01, 0x76, |
leihen | 0:0a7aeb6d4526 | 15 | 0x1d, 0x7f, 0xda, 0xdc, 0x43, 0xcd, 0xa0, 0xd8}; |
leihen | 0:0a7aeb6d4526 | 16 | static const WPA_SECURITY_t sec = WPA_OR_WPA2_PSK; |
leihen | 0:0a7aeb6d4526 | 17 | static const char ssid[] = "<your ssid>"; |
leihen | 0:0a7aeb6d4526 | 18 | #else |
leihen | 0:0a7aeb6d4526 | 19 | // Please note that it will take approximately 30 seconds if using an ascii password because the module has to calculate the binary password before making the actual connection |
leihen | 0:0a7aeb6d4526 | 20 | static char passphrase[] = "<Password>"; |
leihen | 0:0a7aeb6d4526 | 21 | static WPA_SECURITY_t sec = WPA_OR_WPA2_PASSPHRASE; |
leihen | 0:0a7aeb6d4526 | 22 | static const char ssid[] = "<your ssid>"; |
leihen | 0:0a7aeb6d4526 | 23 | #endif |
leihen | 0:0a7aeb6d4526 | 24 | |
leihen | 0:0a7aeb6d4526 | 25 | |
leihen | 0:0a7aeb6d4526 | 26 | |
leihen | 0:0a7aeb6d4526 | 27 | |
leihen | 0:0a7aeb6d4526 | 28 | Serial pc(USBTX, USBRX, "pc"); |
leihen | 0:0a7aeb6d4526 | 29 | |
leihen | 0:0a7aeb6d4526 | 30 | |
leihen | 0:0a7aeb6d4526 | 31 | const char *response = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nServer: mbed embedded\r\n\n\r<HTML><HEAD><META content=\"text/html\" http-equiv=Content-Type></HEAD><BODY><h1>Strike</h1><P>It just works !<P></BODY></HTML>\r\n\r\n"; |
leihen | 0:0a7aeb6d4526 | 32 | |
leihen | 0:0a7aeb6d4526 | 33 | |
leihen | 0:0a7aeb6d4526 | 34 | int main() { |
leihen | 0:0a7aeb6d4526 | 35 | |
leihen | 0:0a7aeb6d4526 | 36 | WifiPlusClick wifi(p13, p14, p21, true, ssid, sec, passphrase, 32); |
leihen | 0:0a7aeb6d4526 | 37 | |
leihen | 0:0a7aeb6d4526 | 38 | pc.baud(460800); // WARNING : I am using a higher baud rate !!!! You may need to adjust your telnet connection !!! |
leihen | 0:0a7aeb6d4526 | 39 | pc.printf("Good day !\n"); |
leihen | 0:0a7aeb6d4526 | 40 | |
leihen | 0:0a7aeb6d4526 | 41 | if (wifi.connect() ) { |
leihen | 0:0a7aeb6d4526 | 42 | wait(0.2); |
leihen | 0:0a7aeb6d4526 | 43 | |
leihen | 0:0a7aeb6d4526 | 44 | pc.printf("Trying to setup a server socket !\n\n"); |
leihen | 0:0a7aeb6d4526 | 45 | TCPSocketServer svr; |
leihen | 0:0a7aeb6d4526 | 46 | |
leihen | 0:0a7aeb6d4526 | 47 | svr.set_blocking(true, 60000); |
leihen | 0:0a7aeb6d4526 | 48 | pc.printf("Trying to bind to port 80 !\n\n"); |
leihen | 0:0a7aeb6d4526 | 49 | if (svr.bind(80) == 0) { |
leihen | 0:0a7aeb6d4526 | 50 | pc.printf("Successfully bound to port 80 !\n\n"); |
leihen | 0:0a7aeb6d4526 | 51 | |
leihen | 0:0a7aeb6d4526 | 52 | if (svr.listen(1) == 0) { |
leihen | 0:0a7aeb6d4526 | 53 | pc.printf("Successfully listening !\n\n"); |
leihen | 0:0a7aeb6d4526 | 54 | TCPSocketConnection client; |
leihen | 0:0a7aeb6d4526 | 55 | if (svr.accept(client) == 0) { |
leihen | 0:0a7aeb6d4526 | 56 | pc.printf("Successfully received incoming connection !\n\n"); |
leihen | 0:0a7aeb6d4526 | 57 | |
leihen | 0:0a7aeb6d4526 | 58 | client.send_all((char*)response, strlen(response)); |
leihen | 0:0a7aeb6d4526 | 59 | svr.close(); |
leihen | 0:0a7aeb6d4526 | 60 | } else { |
leihen | 0:0a7aeb6d4526 | 61 | pc.printf("Failed to serve incoming connections !\n\n"); |
leihen | 0:0a7aeb6d4526 | 62 | } |
leihen | 0:0a7aeb6d4526 | 63 | } else { |
leihen | 0:0a7aeb6d4526 | 64 | pc.printf("Failed to listen !\n\n"); |
leihen | 0:0a7aeb6d4526 | 65 | } |
leihen | 0:0a7aeb6d4526 | 66 | } else { |
leihen | 0:0a7aeb6d4526 | 67 | pc.printf("Failed to bind to port 80 !\n\n"); |
leihen | 0:0a7aeb6d4526 | 68 | } |
leihen | 0:0a7aeb6d4526 | 69 | } |
leihen | 0:0a7aeb6d4526 | 70 | } |