Team E1

Fork of HTTPServer by Sam Kirsch

Revision:
9:c2a1462b9b71
Parent:
6:fe661fa9d18a
Child:
11:3943841e1798
--- a/HTTPServer.cpp	Sat Jun 01 17:47:45 2013 +0000
+++ b/HTTPServer.cpp	Sun Jun 02 00:33:56 2013 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "HTTPServer.h"
 
-#define _DEBUG      0
+#define _DEBUG      1
 
 #ifdef _DEBUG
 DigitalOut led1(LED1);
@@ -11,9 +11,9 @@
 #endif
 
 #if (_DEBUG && !defined(TARGET_LPC11U24))
-#define INFO(x, ...) if (m_pDbg) m_pDbg->printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__); else printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
-#define WARN(x, ...) if (m_pDbg) m_pDbg->printf("[HttpServer : WARN]"x"\r\n", ##__VA_ARGS__); else printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
-#define ERR(x, ...) if (m_pDbg) m_pDbg->printf("[HttpServer : ERR]"x"\r\n", ##__VA_ARGS__); else printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
+#define INFO(x, ...) std::printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
+#define ERR(x, ...) std::printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
 #else
 #define INFO(x, ...)
 #define WARN(x, ...)
@@ -23,11 +23,11 @@
 
 /* Constructor */
 /* initialize all members and set the standard error handler. */
-HTTPServer::HTTPServer(Serial *dbg)
+HTTPServer::HTTPServer(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec)
+    : m_wifly(tx, rx, reset, tcp_status, ssid, phrase, sec)
 {
-    m_pDbg = dbg;
+    m_pErrorHandler = StdErrorHandler;
     m_pSvr = NULL;
-    m_pErrorHandler = StdErrorHandler;
 }
 
 HTTPServer::~HTTPServer()
@@ -58,6 +58,20 @@
         ERR("start function was already called, server is already in listening state.");
         return -1;
     }
+    INFO("Initializing wifly\n");    
+    //  Initialize the wifly wlan device
+    m_wifly.init();
+
+    INFO("Connecting to network...");
+    //  Try join the network
+    while(!m_wifly.connect());
+    INFO("connected\n");
+
+    // check if the start member was called already once
+    if (m_pSvr != NULL) {
+        ERR("start function was already called, server is already in listening state.");
+        return -1;
+    }
     
     //  Create a new server object
     m_pSvr = new TCPSocketServer();