Simple LED control project using CC3100 as Access Point and socket

Dependencies:   mbed

Fork of cc3100_Test_Demo by David Fletcher

Revision:
10:d24deb1afd1b
Parent:
9:30d6c10d4eab
Child:
11:43bc5ac03428
--- a/main.cpp	Fri May 26 07:25:06 2017 +0000
+++ b/main.cpp	Fri May 26 11:17:43 2017 +0000
@@ -95,7 +95,7 @@
 /*
  * GLOBAL VARIABLES -- Start
  */
-int32_t accessPoint = 1;
+int32_t accessPoint = 0;
 
 /*
  * GLOBAL VARIABLES -- End
@@ -230,6 +230,7 @@
         printf("\n\r\n\r");
         printf(" CC3100 in avvio come Access Point ");
         printf("\n\r*******************************************************************************\n\r");
+        //ledShow();
         //scanf("%s", &choose);
         //printf("\n\r%d\n\r", choose);
     
@@ -307,26 +308,72 @@
                 _cc3100._socket.sl_Close(SockID);
                 printf(" Errore in ricezione \n\r");
                 ASSERT_ON_ERROR(TCP_RECV_ERROR);
-            } else {
-                printf("\n\r Ricevuto -> %s %d \n\r", buf, strlen(buf));
-            
+            } else {            
                 // Rimuovo i caratteri strani
                 for(i = 0; i < strlen(buf); i++) {
                     if((buf[i] >= 65 && buf[i] <= 90) || (buf[i] >= 97 && buf[i] <= 122)){
-                        printf("%c ", buf[i]);
+                        //printf("%c ", buf[i]);
                         len = i + 1;
                     }
                 }
                 buf[len] = '\0'; 
+                printf("Ricevuto -> %s \n\r", buf);
                 
-                printf("%s %d \n\r", buf, strlen(buf));
-                sprintf(tmp, "Ricevuto -> %s \n\r", buf);
-                _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
-                
-                if(strcmp(buf,"Blu") != 0 || strcmp(buf,"blu") != 0) {
+                //Scelgo il colore da utilizzare
+                if(strstr(buf,"Blu") != NULL || strstr(buf,"blu") != NULL) {
                     white();
                     myled1 = 1;
                     myled3 = 1;
+                    sprintf(tmp, "Led colorato di Blu \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
+                    
+                } else if (strstr(buf,"Azzurro") != NULL || strstr(buf,"azzurro") != NULL){
+                    white();
+                    myled1 = 1;
+                    sprintf(tmp, "Led colorato di Azzurro \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
+                    
+                } else if (strstr(buf,"Rosso") != NULL || strstr(buf,"rosso") != NULL){
+                    white();
+                    myled2 = 1;
+                    myled3 = 1;
+                    sprintf(tmp, "Led colorato di Rosso \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
+                    
+                } else if (strstr(buf,"Verde") != NULL || strstr(buf,"verde") != NULL){
+                    white();
+                    myled1 = 1;
+                    myled2 = 1;
+                    sprintf(tmp, "Led colorato di Verde \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
+                    
+                } else if (strstr(buf,"Giallo") != NULL || strstr(buf,"giallo") != NULL){
+                    white();
+                    myled2 = 1;
+                    sprintf(tmp, "Led colorato di Giallo \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
+                    
+                } else if (strstr(buf,"Viola") != NULL || strstr(buf,"viola") != NULL){
+                    white();
+                    myled3 = 1;
+                    sprintf(tmp, "Led colorato di Viola \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
+                    
+                } else if (strstr(buf,"Bianco") != NULL || strstr(buf,"bianco") != NULL){
+                    white();
+                    sprintf(tmp, "Led colorato di Bianco \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
+                    
+                } else if (strstr(buf,"Off") != NULL || strstr(buf,"off") != NULL || strstr(buf,"Nero") != NULL || strstr(buf,"nero") != NULL){
+                    myled1 = 1;
+                    myled2 = 1;
+                    myled3 = 1;
+                    sprintf(tmp, "Led spento \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
+                    
+                } else {
+                    sprintf(tmp, "Hai inviato un colore non valido \n");
+                    _cc3100._socket.sl_Send(newSockID, &(tmp), strlen(tmp),0);
                 }
             }
 
@@ -356,6 +403,7 @@
     uint8_t SecType = 0;
     int32_t role = ROLE_STA;
     int32_t retVal = -1;
+    char answer[20];
     
     /*
      * Assumption is that the device is configured in station mode already
@@ -414,22 +462,22 @@
         _cc3100._nonos._SlNonOsMainLoopTask();
     }
     printf(" Un client sta tentando di connettersi \n\r");
-    printf(" In corso test di connettivita'... \n\r");
+    /*printf(" In corso test di connettivita'... \n\r");
 
-    /* Set the ping parameters */
+    // Set the ping parameters 
     PingParams.PingIntervalTime = PING_INTERVAL;
     PingParams.PingSize = PING_SIZE;
     PingParams.PingRequestTimeout = PING_TIMEOUT;
     PingParams.TotalNumberOfAttempts = PING_ATTEMPTS;
     PingParams.Flags = 0;
-    PingParams.Ip = g_StationIP; /* Fill the station IP address connected to CC3100 */
+    PingParams.Ip = g_StationIP; // Fill the station IP address connected to CC3100 
 
-    /* Ping client connected to CC3100 */
+    // Ping client connected to CC3100
     retVal = _cc3100._netapp.sl_NetAppPingStart((SlPingStartCommand_t*)&PingParams, SL_AF_INET, (SlPingReport_t*)&Report, &SimpleLinkPingReport);
     if(retVal < 0)
         LOOP_FOREVER();
 
-    /* Wait */
+    // Wait
     while(!_cc3100.IS_PING_DONE(g_Status,STATUS_BIT_PING_DONE)) {
         _cc3100._nonos._SlNonOsMainLoopTask();
     }
@@ -438,15 +486,18 @@
         printf(" Impossibile connettersi correttamente al client \n\r");
         //ASSERT_ON_ERROR(LAN_CONNECTION_FAILED);
         printf(" ERRORE numero %d\n\r", LAN_CONNECTION_FAILED);
-    }
+    }*/
 
     printf(" Client correttamente connesso \n\r");
-    printf(" Socket in apertura \n\r");
     
     //Funzione che gestisce e crea la socket
-    retVal = TcpServer(PORT_NUM);
-    if(retVal < 0)
-        printf(" Impossibile avviare la comunicazione \n\r");
+    sprintf(answer,"si");
+    while(1) {
+        printf(" Socket in apertura \n\r");
+        retVal = TcpServer(PORT_NUM);
+        if(retVal < 0)
+            printf(" Socket chiuso \n\r");
+    }
 }
 
 int32_t pingToHost(char* host) {