Using BLE to control WIFI configuration as SSID and PW.

Dependencies:   BLE_API WIFI_API_32kRAM mbed nRF51822

Fork of NNN40_WiFi by Delta

BLE_WIFIControl enables user to setup Wifi connection via BLE link. Here is iPhone app that teaches you how to use this BLE_WIFIControl example. /media/uploads/Marcomissyou/ios_app_for_wifi_configure.pdf

Revision:
8:d39bc94f139b
Parent:
7:5d82c92ec2a3
Child:
9:16ac259b2ce7
--- a/main.cpp	Mon May 18 07:13:04 2015 +0000
+++ b/main.cpp	Tue Jun 30 03:12:25 2015 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-#include "BLEDevice.h"
+#include "BLE.h"
 #include "BLEControlWIFIService.h"
 #include "DeviceInformationService.h"
 #include "WIFIDevice.h"
@@ -17,7 +17,9 @@
 DigitalOut led2(LED2);
 DigitalOut RFSWIO(p19);
 
-const static char     DEVICE_NAME[]        = "BLE WCS";
+bool is_AP_connect = false;
+
+const static char     DEVICE_NAME[]        = "TSUNGTA_BLE WCS";
 static volatile bool  triggerSensorPolling = false;
  
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
@@ -25,12 +27,14 @@
     ble.startAdvertising(); // restart advertising
 }
 
-const char* PC_SERVER_ADDRESS = "192.168.1.234";
+const char* PC_SERVER_ADDRESS = "192.168.15.101";
 uint16_t PC_PORT = 5222;
  
 int main(void)
 {
-    eth.init(); //Use DHCP
+    NRF_CLOCK->XTALFREQ = 0x00; //Tsungta, Used to active radio correctly external when XTAL 32MHz is loaded
+    TCPSocketConnection sock;
+                
     RFSWIO = 0;
     ble.init();
     ble.onDisconnection(disconnectionCallback);
@@ -53,17 +57,25 @@
     while (1) {
         if (ble.getGapState().connected && BLEWIFIService.is_config) {
             BLEWIFIService.is_config = false;
-            eth.connect(40000);
-            TCPSocketConnection sock;
-            sock.connect(PC_SERVER_ADDRESS,PC_PORT);
-            led1 = 1;
-                if(sock.is_connected()){
-                    led2 = 1;   
-                    char msg[] = "Hello World";
-                    sock.send(msg, sizeof(msg));
-                }
+            //ble.shutdown();
+            eth.init(); //Use DHCP
+
+            while (eth.connect()) {}
+            is_AP_connect = true;
+
             
         } else {
+            
+          if (is_AP_connect) {
+            if(!sock.is_connected()){ 
+                sock.connect(PC_SERVER_ADDRESS,PC_PORT);
+                led1 = 1;
+            } else {
+                char msg[] = "Hello World";
+                sock.send(msg, sizeof(msg));
+                wait(1);
+            }
+          }
             ble.waitForEvent(); // low power wait for event
         }
     }