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.

Files at this revision

API Documentation at this revision

Comitter:
leihen
Date:
Mon Jul 29 16:03:21 2013 +0000
Commit message:
General example application for use with the WifiPlusClick Module from MikroElektronika.

Changed in this revision

WifiPlusClick.lib Show annotated file Show diff for this revision Revisions of this file
debug.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 0a7aeb6d4526 WifiPlusClick.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WifiPlusClick.lib	Mon Jul 29 16:03:21 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/leihen/code/WifiPlusClick/#2a179bd4cc02
diff -r 000000000000 -r 0a7aeb6d4526 debug.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug.h	Mon Jul 29 16:03:21 2013 +0000
@@ -0,0 +1,27 @@
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+
+#ifdef DEBUG
+#define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#else
+#define INFO(x, ...)
+#define WARN(x, ...)
+//#define ERR(x, ...)
+#endif
+#define ERR(x, ...) std::printf("[ERR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+
+
+#ifdef ENABLE_STACK_CHECK
+#define BEGIN_STACK_CHECK()     char _stack_check; _stack_check = 0xA5
+#define RETURN_STACK_CHECK(x)   if (_stack_check != 0xA5){ error("STACK CHECK"); while(1); } return (x)
+#define END_STACK_CHECK()       if (_stack_check != 0xA5){ error("STACK CHECK"); while(1); } return
+#else
+#define BEGIN_STACK_CHECK()
+#define RETURN_STACK_CHECK(x)   return (x)
+#define END_STACK_CHECK()       return
+#endif
+
+
+#endif //   __DEBUG_H__
\ No newline at end of file
diff -r 000000000000 -r 0a7aeb6d4526 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 29 16:03:21 2013 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "WifiPlusClick.h"
+#include "TCPSocketServer.h"
+
+//#define WPA2_PASSWORD
+
+#ifndef WPA2_PASSWORD
+
+
+//  Please note that when using this binary passphrase a connection can be made much faster.
+static const char passphrase[32] = {
+    0xac, 0x4d, 0x41, 0x29, 0xa4, 0xd8, 0xfd, 0x15, 
+    0xaf, 0x29, 0xd7, 0x8d, 0xb2, 0x50, 0x3c, 0xd9, 
+    0xa7, 0x4f, 0x5e, 0x64, 0x5d, 0x82, 0x01, 0x76,
+    0x1d, 0x7f, 0xda, 0xdc, 0x43, 0xcd, 0xa0, 0xd8};
+static const WPA_SECURITY_t sec = WPA_OR_WPA2_PSK;
+static const char ssid[] = "<your ssid>";
+#else
+//  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
+static char passphrase[] = "<Password>";
+static WPA_SECURITY_t sec = WPA_OR_WPA2_PASSPHRASE;
+static const char ssid[] = "<your ssid>";
+#endif
+
+
+
+
+Serial pc(USBTX, USBRX, "pc");
+
+
+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";
+
+
+int main() {
+
+    WifiPlusClick   wifi(p13, p14, p21, true, ssid, sec, passphrase, 32);
+        
+    pc.baud(460800);                            //  WARNING : I am using a higher baud rate !!!! You may need to adjust your telnet connection !!!
+    pc.printf("Good day !\n");
+
+    if (wifi.connect() ) {
+        wait(0.2);
+
+        pc.printf("Trying to setup a server socket !\n\n");
+        TCPSocketServer svr;
+        
+        svr.set_blocking(true, 60000);
+        pc.printf("Trying to bind to port 80 !\n\n");
+        if (svr.bind(80) == 0) {
+            pc.printf("Successfully bound to port 80 !\n\n");
+
+            if (svr.listen(1) == 0) {
+                pc.printf("Successfully listening !\n\n");
+                TCPSocketConnection client;
+                if (svr.accept(client) == 0) {
+                    pc.printf("Successfully received incoming connection !\n\n");
+                    
+                    client.send_all((char*)response, strlen(response));
+                    svr.close();
+                } else {
+                    pc.printf("Failed to serve incoming connections !\n\n");
+                }
+            } else {
+                pc.printf("Failed to listen !\n\n");
+            }
+        } else {
+            pc.printf("Failed to bind to port 80 !\n\n");
+        }
+    }
+}
diff -r 000000000000 -r 0a7aeb6d4526 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jul 29 16:03:21 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file