Simple example demonstrating WiConnect host library web setup feature.

Dependencies:   WiConnect mbed

Revision:
11:3f4ad7cb7bd4
Parent:
10:63f9df429d05
--- a/example.cpp	Thu Nov 27 00:01:47 2014 -0800
+++ b/example.cpp	Thu Nov 27 10:26:39 2014 +0000
@@ -46,11 +46,6 @@
 
 
 
-/******************************************************************************
- * Local Functions
- */
-static void webSetupCompleteCallback(WiconnectResult result, void *arg1, void *arg2);
-
 
 /******************************************************************************
  * Global Defines
@@ -63,8 +58,6 @@
 // Buffer used internally by WiConnect library, note that this is optional
 static uint8_t wiconnectInternalBuffer[256];
 
-// Flag that indicate websetup has completed
-static volatile bool webSetupCompleteFlag = false;
 
 
 /******************************************************************************
@@ -72,6 +65,7 @@
  */
 int main(int argc, char **argv)
 {
+    WiconnectResult result;
     consoleSerial.baud(115200); // console terminal to 115200 baud
 
     //-------------------------------------------------------------------------
@@ -95,12 +89,12 @@
     printf("Initializing WiConnect Library...\r\n");
 
     // Initialize communication with WiFi module
-    if(wiconnect.init(true) != WICONNECT_SUCCESS)
+    if(WICONNECT_FAILED(result, wiconnect.init()))
     {
         if(result == WICONNECT_FIRMWARE_OUTDATED)
         {
-            printf("The WiFi firmware is not supported. Run the ota example to update the firmware:\r\n");
-            printf("https://developer.mbed.org/teams/ACKme/code/wiconnect-ota_example");
+            printf("*** The WiFi firmware is not supported. Run the ota example to update the firmware:\r\n");
+            printf("https://developer.mbed.org/teams/ACKme/code/wiconnect-ota_example\r\n\r\n");
         }
         else
         {
@@ -118,7 +112,7 @@
     printf("Starting Websetup...\r\n");
 
     // Start web setup
-    if(wiconnect.startWebSetup(WEB_SETUP_SSID, WEB_SETUP_PASSWORD, Callback(webSetupCompleteCallback)) != WICONNECT_SUCCESS)
+    if(wiconnect.startWebSetup(WEB_SETUP_SSID, WEB_SETUP_PASSWORD) != WICONNECT_SUCCESS)
     {
         printf("Failed to start web setup\r\n");
         for(;;); // infinite loop
@@ -135,11 +129,18 @@
     printf("4. This will bringup a setup page, enter your router's credentials.\r\n");
     printf("5. Click the 'Save & Exit' button at the bottom of the webpage\r\n\r\n");
 
-    while(!webSetupCompleteFlag)
+    for(;;)
     {
-        // do nothing while we wait
-        // When the user exits web setup from the webpage
-        // webSetupCompleteCallback() will execute and set webSetupCompleteFlag TRUE
+        bool isRunning;
+        
+        if(wiconnect.isWebSetupRunning(&isRunning) != WICONNECT_SUCCESS)
+        {
+            printf("Failed to get websetup status\r\n");
+            for(;;);
+        }
+        delayMs(100);
+        if(!isRunning)
+            break;
     }
 
     //-------------------------------------------------------------------------
@@ -153,9 +154,3 @@
 }
 
 
-// this function is called when web setup completes
-// it is called in the background
-static void webSetupCompleteCallback(WiconnectResult result, void *arg1, void *arg2)
-{
-    webSetupCompleteFlag = true;
-}