Simple LED control project using CC3100 as Access Point and socket
Fork of cc3100_Test_Demo by
Diff: main.cpp
- Revision:
- 8:2acb25effa3a
- Parent:
- 7:0687d16b9781
- Child:
- 9:30d6c10d4eab
--- a/main.cpp Thu Sep 03 13:43:50 2015 +0000 +++ b/main.cpp Thu May 25 16:58:17 2017 +0000 @@ -36,7 +36,7 @@ /* * Application Name - Getting started with Wi-Fi Access-Point mode - * Application Overview - This sample application demonstrates how + * Application Overview - This sample application accessPointnstrates how * to configure CC3100 in Access-Point mode. Any * WLAN station in its range can connect/communicate * to/with it as per the standard networking protocols. @@ -56,7 +56,11 @@ using namespace mbed_cc3100; -#if (THIS_BOARD == MBED_BOARD_LPC1768) +#if (THIS_BOARD == MBED_BOARD_LPC4337) +//cc3100 _cc3100(p9, p10, p8, SPI(p5, p6, p7));//LPC1768 irq, nHib, cs, mosi, miso, sck +cc3100 _cc3100(P2_2, P3_5, P1_5, SPI(P1_4, P1_3, PF_4));//LPC4337 irq, nHib, cs, mosi, miso, sck +Serial pc(USBTX, USBRX);//lpc4337 +#elif (THIS_BOARD == MBED_BOARD_LPC1768) //cc3100 _cc3100(p9, p10, p8, SPI(p5, p6, p7));//LPC1768 irq, nHib, cs, mosi, miso, sck cc3100 _cc3100(p9, p10, p8, SPI(p11, p12, p13));//LPC1768 irq, nHib, cs, mosi, miso, sck Serial pc(USBTX, USBRX);//lpc1768 @@ -84,7 +88,7 @@ /* * GLOBAL VARIABLES -- Start */ -int32_t demo = 0; +int32_t accessPoint = 0; /* * GLOBAL VARIABLES -- End @@ -137,12 +141,12 @@ if(retVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == retVal) - printf(" Failed to configure the device to its default state \n\r"); + printf(" Impossibile completare la configurazione della CC3100 \n\r"); LOOP_FOREVER(); } - printf(" Device is configured in it's default state \n\r"); + printf(" CC3100 configurata nel suo stato di default \n\r"); /* * Assumption is that the device is configured in station mode already @@ -150,18 +154,18 @@ */ /* Initializing the CC3100 device */ - if(!(demo ==1)){ + if(!accessPoint){ retVal = _cc3100.sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ){ - printf(" Failed to start the device \n\r"); + printf(" Impossibile avviare la CC3100 nella modalita' richiesta \n\r"); LOOP_FOREVER(); } - printf(" Device started as STATION \n\r"); + printf(" CC3100 avviata come scheda di rete \n\r"); } - if(demo == 0 ){ + if(accessPoint == 0 ){ station_app(); }else{ AP_app(); @@ -178,16 +182,18 @@ */ static void displayBanner() { - if(!demo){ + //int choose; + + if(accessPoint){ printf("\n\r\n\r"); - printf(" Getting started with WLAN access-point application - Version "); - printf("%s",APPLICATION_VERSION); + printf(" CC3100 in avvio come Access Point "); printf("\n\r*******************************************************************************\n\r"); + //scanf("%s", &choose); + //printf("\n\r%d\n\r", choose); }else{ printf("\n\r\n\r"); - printf(" Getting started with station application - Version "); - printf(" %s", APPLICATION_VERSION); + printf(" CC3100 in avvio come scheda di rete "); printf("\n\r*******************************************************************************\n\r"); } } @@ -290,27 +296,82 @@ //return SUCCESS; } -void station_app(void){ +int32_t pingToHost(char* host) { + + SlPingStartCommand_t pingParams = {0}; + SlPingReport_t pingReport = {0}; + + uint32_t ipAddr = 0; + + int32_t retVal = -1; + + _cc3100.CLR_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE); + g_PingPacketsRecv = 0; + + /* Set the ping parameters */ + pingParams.PingIntervalTime = PING_INTERVAL; + pingParams.PingSize = PING_PKT_SIZE; + pingParams.PingRequestTimeout = PING_TIMEOUT; + pingParams.TotalNumberOfAttempts = PING_ATTEMPTS; + pingParams.Flags = 0; + pingParams.Ip = g_GatewayIP; + + /* Check for Internet connection */ + retVal = _cc3100._netapp.sl_NetAppDnsGetHostByName((unsigned char *)host, strlen(host), &ipAddr, SL_AF_INET); + if(retVal < 0) { + printf(" Impossibile trovare l'host \n\r"); + return retVal; + } else + printf(" Avvio ping\n"); + + /* Replace the ping address to match HOST_NAME's IP address */ + pingParams.Ip = ipAddr; + + /* Try to ping HOST_NAME */ + retVal = _cc3100._netapp.sl_NetAppPingStart( (SlPingStartCommand_t*)&pingParams, SL_AF_INET, + (SlPingReport_t*)&pingReport, SimpleLinkPingReport); + if(retVal < 0) { + printf(" Impossibile connettersi all'host \n\r"); + return retVal; + } + + /* Wait */ + while(!_cc3100.IS_PING_DONE(g_Status,STATUS_BIT_PING_DONE)) { _cc3100._nonos._SlNonOsMainLoopTask(); } + + if (0 == g_PingPacketsRecv) { + printf(" Il test non e' andato a buon fine \n\r"); + return retVal; + } else { + + printf("\n\r Pacchetti inviati -> %d \n\r Pacchetti ricevuti -> %d \n\r", pingReport.PacketsSent, pingReport.PacketsReceived); + printf("Tempo minimo -> %d s\n\r Tempo massimo -> %d s\n\r Tempo medio -> %d s\n\r Tempo di test %d s\n\r", pingReport.MinRoundTime, pingReport.MaxRoundTime, pingReport.AvgRoundTime ,pingReport.TestTime); + } + + return 0; + +} + +void station_app(void) { int32_t retVal = -1; + char host[100]; /* Connecting to WLAN AP */ retVal = _cc3100.establishConnectionWithAP(); if(retVal < 0) { - printf(" Failed to establish connection w/ an AP \n\r"); + printf(" Impossibile connettersi \n\r"); LOOP_FOREVER(); } - printf(" Connection established w/ AP and IP is acquired \n\r"); + printf(" Connessione stabilita con l'Access Point \n\r"); - printf(" Pinging...! \n\r"); + printf(" Test di connettivita' in corso... \n\r"); retVal = _cc3100.checkLanConnection(); - if(retVal < 0) - { + if(retVal < 0) { printf(" Device couldn't connect to LAN \n\r"); LOOP_FOREVER(); } - printf(" Device successfully connected to the LAN\r\n"); + printf(" Connesso alla rete locale con successo \r\n"); retVal = _cc3100.checkInternetConnection(); if(retVal < 0) @@ -319,7 +380,15 @@ LOOP_FOREVER(); } - printf(" Device successfully connected to the internet \n\r"); + printf(" Connesso ad internet con successo"); + + // Esegue ping finchè connesso + while(1) { + printf(" \n\rInserire un host a cui fare il ping \n\r"); + scanf("%s", host); + + if(pingToHost(host) == 0) + printf("\nTest completato senza errori\n\r"); + + } } - -