cc3100_Socket_Wifi_Server with Ethernet Interface not working

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of cc3100_Test_Demo by David Fletcher

Revision:
5:d3b320ebd469
Parent:
3:b89198ac2efe
Child:
7:0687d16b9781
--- a/main.cpp	Mon Feb 23 21:10:13 2015 +0000
+++ b/main.cpp	Thu Mar 19 14:35:32 2015 +0000
@@ -72,11 +72,14 @@
 #elif (THIS_BOARD == ST_MBED_NUCLEOF103)
 cc3100 _cc3100(PA_9, PC_7, PB_6, SPI(PA_7, PA_6, PA_5));//nucleoF103  irq, nHib, cs, mosi, miso, sck
 Serial pc(SERIAL_TX, SERIAL_RX);
+#elif (THIS_BOARD == Seed_Arch_Max)
+cc3100 _cc3100(PE_5, PE_4, PE_6, SPI(PB_5, PB_4, PB_3));//Seeed_Arch_Max  irq, nHib, cs, mosi, miso, sck
+Serial pc(USBTX, USBRX);
 #else
 
 #endif
 
-#define APPLICATION_VERSION "1.1.0"
+#define APPLICATION_VERSION "1.2.0"
 
 /*
  * GLOBAL VARIABLES -- Start
@@ -193,8 +196,8 @@
     
     SlPingStartCommand_t PingParams = {0};
     SlPingReport_t Report = {0};
-    SlNetCfgIpV4Args_t ipV4 = {0};
-    SlNetAppDhcpServerBasicOpt_t dhcpParams = {0};
+//    SlNetCfgIpV4Args_t ipV4 = {0};
+//    SlNetAppDhcpServerBasicOpt_t dhcpParams = {0};
 
     uint8_t SecType = 0;
     int32_t role = ROLE_STA;
@@ -215,6 +218,22 @@
         retVal = _cc3100._wlan.sl_WlanSetMode(ROLE_AP);
         if(retVal < 0)
             LOOP_FOREVER();
+            
+        /* Configure the SSID of the CC3100 */
+        retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID,
+                strlen(SSID_AP_MODE), (uint8_t *)SSID_AP_MODE);
+        if(retVal < 0)
+            LOOP_FOREVER();
+
+        SecType = SEC_TYPE_AP_MODE;
+        /* Configure the Security parameter the AP mode */
+        retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1, (uint8_t *)&SecType);
+        if(retVal < 0)
+            LOOP_FOREVER();
+
+        retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, strlen(PASSWORD_AP_MODE), (uint8_t *)PASSWORD_AP_MODE);
+        if(retVal < 0)
+            LOOP_FOREVER();    
 
         retVal = _cc3100.sl_Stop(SL_STOP_TIMEOUT);
         if(retVal < 0)
@@ -233,61 +252,6 @@
             LOOP_FOREVER();
         }
     }
-    
-    printf(" Ready to configue SSID\r\n");
-
-    /* Configure the SSID of the CC3100 */
-    retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, strlen(SSID_AP_MODE), (uint8_t *)SSID_AP_MODE);
-    if(retVal < 0)
-        LOOP_FOREVER();
-
-    SecType = SEC_TYPE_AP_MODE;
-    /* Configure the Security parameter the AP mode */
-    retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1, (uint8_t *)&SecType);
-    if(retVal < 0)
-        LOOP_FOREVER();
-
-    retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, strlen(PASSWORD_AP_MODE), (uint8_t *)PASSWORD_AP_MODE);
-    if(retVal < 0){
-        LOOP_FOREVER();
-    }
-    
-    ipV4.ipV4 = _cc3100._netcfg.SL_IPV4_VAL(192,168,0,1);//CONFIG_IP;
-    ipV4.ipV4Mask = _cc3100._netcfg.SL_IPV4_VAL(255,255,255,0);//CONFIG_MASK;
-    ipV4.ipV4Gateway = _cc3100._netcfg.SL_IPV4_VAL(192,168,0,1);//CONFIG_GATEWAY;
-    ipV4.ipV4DnsServer = _cc3100._netcfg.SL_IPV4_VAL(192,168,0,1);//CONFIG_DNS;
-
-    /* Configure the Static IP */
-    retVal = _cc3100._netcfg.sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE,1,sizeof(SlNetCfgIpV4Args_t), (uint8_t *)&ipV4);
-    if(retVal < 0)
-        LOOP_FOREVER();
-
-    dhcpParams.lease_time      =  IP_LEASE_TIME;
-    dhcpParams.ipv4_addr_start =  _cc3100._netcfg.SL_IPV4_VAL(192,168,0,100);//DHCP_START_IP;
-    dhcpParams.ipv4_addr_last  =  _cc3100._netcfg.SL_IPV4_VAL(192,168,0,200);//DHCP_END_IP;
-
-    retVal = _cc3100._netapp.sl_NetAppSet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT, sizeof(SlNetAppDhcpServerBasicOpt_t), (uint8_t*)&dhcpParams);
-    if(retVal < 0)
-        LOOP_FOREVER();
-
-    /* Restart the CC3100 */
-    retVal = _cc3100.sl_Stop(SL_STOP_TIMEOUT);
-    if(retVal < 0)
-        LOOP_FOREVER();
-
-    g_Status = 0;
-    
-    role = _cc3100.sl_Start(0, 0, 0);
-    
-    if (ROLE_AP == role) {
-        /* If the device is in AP mode, we need to wait for this event before doing anything */
-        while(!_cc3100.IS_IP_ACQUIRED(g_Status,STATUS_BIT_IP_ACQUIRED)) {
-            _cc3100._nonos._SlNonOsMainLoopTask();
-        }
-    } else {
-        printf(" Device couldn't enter AP mode \n\r");
-        LOOP_FOREVER();
-    }
     printf(" Device started as Access Point\n\r");
 
     /* Wait */
@@ -329,16 +293,16 @@
 void station_app(void){
     
     int32_t retVal = -1;
-
+    
     /* Connecting to WLAN AP */
     retVal = _cc3100.establishConnectionWithAP();
     if(retVal < 0)
     {
         printf(" Failed to establish connection w/ an AP \n\r");
         LOOP_FOREVER();
-    }
-
+    }    
     printf(" Connection established w/ AP and IP is acquired \n\r");
+    
     printf(" Pinging...! \n\r");
     retVal = _cc3100.checkLanConnection();
     if(retVal < 0)
@@ -346,7 +310,8 @@
         printf(" Device couldn't connect to LAN \n\r");
         LOOP_FOREVER();
     }
-
+    printf(" Device successfully connected to the LAN\r\n");
+    
     retVal = _cc3100.checkInternetConnection();
     if(retVal < 0)
     {
@@ -354,7 +319,7 @@
         LOOP_FOREVER();
     }
 
-    printf(" Device successfully connected to the LAN and internet \n\r");
+    printf(" Device successfully connected to the internet \n\r");
 }