/*! * \brief Start the device in STA mode * * Following function configures the device to default state by cleaning * the persistent settings stored in NVMEM (viz. connection profiles & * policies, power policy etc) * * Applications may choose to skip this step if the developer is sure * that the device is in its default state at start of application * * Note that all profiles and persistent settings that were done on the * device will be lost */ _i32 startWlanStion(void){ _i32 retVal = configureSimpleLinkToDefaultState(); if(retVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == retVal) CLI_Write((_u8 *)" Failed to configure the device in its default state \n\r"); LOOP_FOREVER(); } CLI_Write((_u8 *)" Device is configured in default state \n\r"); /* * Assumption is that the device is configured in station mode already * and it is in its default state */ retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write((_u8 *)" Failed to start the device \n\r"); LOOP_FOREVER(); } CLI_Write((_u8 *)" Device started as STATION \n\r"); /* Connecting to WLAN AP */ retVal = establishConnectionWithAP(); if(retVal < 0) { CLI_Write((_u8 *)" Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } CLI_Write((_u8 *)" Connection established w/ AP and IP is acquired \n\r"); return retVal; }
/* * Application's entry point */ int main(int argc, char** argv) { SlSecParams_t secParams = {0}; _i32 retVal = -1; retVal = initializeAppVariables(); ASSERT_ON_ERROR(retVal); /* Stop WDT and initialize the system-clock of the MCU */ stopWDT(); initClk(); /* Configure command line interface */ CLI_Configure(); displayBanner(); /* * Following function configures the device to default state by cleaning * the persistent settings stored in NVMEM (viz. connection profiles & * policies, power policy etc.) * * Applications may choose to skip this step if the developer is sure * that the device is in its default state at start of application * * Note that all profiles and persistent settings that were done on the * device will be lost */ retVal = configureSimpleLinkToDefaultState(); if(retVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == retVal) CLI_Write(" Failed to configure the device in its default state \n\r"); LOOP_FOREVER(); } CLI_Write(" Device is configured in default state \n\r"); /* * Initializing the CC3100 device * Assumption is that the device is configured in station mode already * and it is in its default state */ retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } CLI_Write(" Device started as STATION \n\r"); /* Delete all profiles (0xFF) stored and reset policy settings */ retVal = sl_WlanProfileDel(0xFF); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(0, 0, 0, 0, 0), 0, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Add unsecured AP profile with priority 6 (7 is highest) */ retVal = sl_WlanProfileAdd((_i8 *)UNSEC_SSID_NAME, pal_Strlen(UNSEC_SSID_NAME), g_BSSID, 0, 0, 6, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Add WPA2 secured AP profile with priority 7 (highest) */ secParams.Type = SL_SEC_TYPE_WPA; secParams.Key = SEC_SSID_KEY; secParams.KeyLen = pal_Strlen(SEC_SSID_KEY); retVal = sl_WlanProfileAdd((_i8 *)SEC_SSID_NAME, pal_Strlen(SEC_SSID_NAME), g_BSSID, &secParams, 0, 7, 0); if(retVal < 0) { LOOP_FOREVER(); } /* * Enable auto connect (connection to stored profiles according to priority) * Connection should first be established to higher (secured) profile as in * this example */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,0,0,0,0), 0, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Wait for the connection to be established */ while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); } CLI_Write(" Device connected to the AP using 'auto' connection policy\n\r"); /* Delete all profiles (0xFF) stored */ retVal = sl_WlanProfileDel(0xFF); if(retVal < 0) { LOOP_FOREVER(); } g_Status = 0; /* Restart the device */ retVal = sl_Stop(SL_STOP_TIMEOUT); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } /* * Set connection policy to Fast - Device will connect to the last connected AP. * This feature can be used to reconnect to AP */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 1, 0, 0, 0), 0, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Connect to the open AP */ retVal = establishConnectionWithAP(); if(retVal < 0) { CLI_Write(" Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } CLI_Write(" Device was connected to the AP using host-driver API \n\r"); g_Status = 0; /* Status variable */ /* Restart the Device */ retVal = sl_Stop(SL_STOP_TIMEOUT); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } /* Wait for the connection to be established */ while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); } CLI_Write(" Device connected to the AP using 'fast' connection policy\n\r"); /* Delete all profiles (0xFF) stored */ retVal = sl_WlanProfileDel(0xFF); if(retVal < 0) { LOOP_FOREVER(); } /* Set Auto SmartConfig policy */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,0,0,0,1), 0, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Restart the Device */ g_Status = 0; retVal = sl_Stop(SL_STOP_TIMEOUT); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } /* * After restarting , device will wait for a command for 2 second and start * the SmartConfig process if no command is received */ CLI_Write(" Device waiting to be connected using SmartConfig technology \n\r"); while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); } CLI_Write(" Device connected to the AP \n\r"); /* * Cleaning all profiles and setting the default connection policy before exiting the application * Set connection policy to Auto + SmartConfig (Device's default connection policy) */ retVal = sl_WlanProfileDel(0xFF); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); if(retVal < 0) { LOOP_FOREVER(); } return 0; }
/* * Application's entry point */ int main(int argc, char** argv) { _i32 retVal = -1; retVal = initializeAppVariables(); ASSERT_ON_ERROR(retVal); /* Stop WDT and initialize the system-clock of the MCU */ stopWDT(); initClk(); /* Configure command line interface */ CLI_Configure(); displayBanner(); /* * Following function configures the device to default state by cleaning * the persistent settings stored in NVMEM (viz. connection profiles & * policies, power policy etc) * * Applications may choose to skip this step if the developer is sure * that the device is in its default state at start of application * * Note that all profiles and persistent settings that were done on the * device will be lost */ retVal = configureSimpleLinkToDefaultState(); if(retVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == retVal) CLI_Write((_u8 *)" Failed to configure the device in its default state \n\r"); LOOP_FOREVER(); } CLI_Write((_u8 *)" Device is configured in default state \n\r"); /* * Assumption is that the device is configured in station mode already * and it is in its default state */ retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write((_u8 *)" Failed to start the device \n\r"); LOOP_FOREVER(); } CLI_Write((_u8 *)" Device started as STATION \n\r"); /* Connecting to WLAN AP */ retVal = establishConnectionWithAP(); if(retVal < 0) { CLI_Write((_u8 *)" Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } CLI_Write((_u8 *)" Connection established w/ AP and IP is acquired \n\r"); CLI_Write((_u8 *)" Pinging...! \n\r"); retVal = checkLanConnection(); if(retVal < 0) { CLI_Write((_u8 *)" Device couldn't connect to LAN \n\r"); LOOP_FOREVER(); } CLI_Write((_u8 *)" Device successfully connected to the LAN\r\n"); retVal = checkInternetConnection(); if(retVal < 0) { CLI_Write((_u8 *)" Device couldn't connect to the internet \n\r"); LOOP_FOREVER(); } CLI_Write((_u8 *)" Device successfully connected to the internet \n\r"); return 0; }
int main(int argc, char** argv) { SlSockAddrIn_t Addr = {0}; _u32 cipher = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA; _u32 googleIP = 0; _u8 method = SL_SO_SEC_METHOD_SSLV3; _i32 AddrSize = -1; _i32 g_SockID = -1; _i32 retVal = -1; retVal = initializeAppVariables(); ASSERT_ON_ERROR(retVal); /* Stop WDT and initialize the system-clock of the MCU These functions needs to be implemented in PAL */ stopWDT(); initClk(); /* Configure command line interface */ CLI_Configure(); displayBanner(); /* * Following function configures the device to default state by cleaning * the persistent settings stored in NVMEM (viz. connection profiles & * policies, power policy etc) * * Applications may choose to skip this step if the developer is sure * that the device is in its default state at start of application * * Note that all profiles and persistent settings that were done on the * device will be lost */ retVal = configureSimpleLinkToDefaultState(); if(retVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == retVal) { CLI_Write(" Failed to configure the device in its default state \n\r"); } LOOP_FOREVER(); } CLI_Write(" Device is configured in default state \n\r"); /* * Assumption is that the device is configured in station mode already * and it is in its default state */ /* Initializing the CC3100 device */ retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } CLI_Write(" Device started as STATION \n\r"); /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ retVal = establishConnectionWithAP(); if(retVal < 0) { CLI_Write(" Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } CLI_Write(" Connection established w/ AP and IP is acquired \n\r"); /* Update the CC3100 time */ retVal = SetTime(); if (retVal < 0) { CLI_Write(" Failed to set the device time \n\r"); LOOP_FOREVER(); } CLI_Write(" Establishing secure connection w/ google server \n\r"); /* get the server name via a DNS request */ retVal = sl_NetAppDnsGetHostByName(g_Google, pal_Strlen(g_Google), &googleIP, SL_AF_INET); if( retVal < 0 ) { CLI_Write(" Failed to get the IP address \n\r"); LOOP_FOREVER(); } Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons(GOOGLE_DST_PORT); Addr.sin_addr.s_addr = sl_Htonl(googleIP); AddrSize = sizeof(SlSockAddrIn_t); /* opens a secure socket */ g_SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET); if( g_SockID < 0 ) { CLI_Write(" Failed to open socket \n\r"); LOOP_FOREVER(); } /* configure the socket as SSLV3.0 */ retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, &method, sizeof(method)); if( retVal < 0 ) { CLI_Write(" Failed to configure the socket \n\r"); LOOP_FOREVER(); } /* configure the socket as RSA with RC4 128 SHA */ retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECURE_MASK, &cipher, sizeof(cipher)); if( retVal < 0 ) { CLI_Write(" Failed to configure the socket \n\r"); LOOP_FOREVER(); } /* configure the socket with GOOGLE CA certificate-for server verification*/ retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECURE_FILES_CA_FILE_NAME, SL_SSL_CA_CERT, pal_Strlen(SL_SSL_CA_CERT)); if( retVal < 0 ) { CLI_Write(" Failed to configure the socket \n\r"); LOOP_FOREVER(); } /* connect to the peer device - GMail server */ retVal = sl_Connect(g_SockID, ( SlSockAddr_t *)&Addr, AddrSize); if (retVal < 0 ) { CLI_Write(" Failed to connect w/ google server \n\r"); LOOP_FOREVER(); } CLI_Write(" Connection w/ google server established successfully \n\r"); /* Stop the CC3100 device */ retVal = sl_Stop(SL_STOP_TIMEOUT); if(retVal < 0) LOOP_FOREVER(); return 0; }
/* * Application's entry point */ int main(int argc, char** argv) { _i32 retVal = -1; retVal = initializeAppVariables(); ASSERT_ON_ERROR(retVal); /* Stop WDT and initialize the system-clock of the MCU */ stopWDT(); initClk(); /* Configure command line interface */ CLI_Configure(); displayBanner(); /* * Following function configures the device to default state by cleaning * the persistent settings stored in NVMEM (viz. connection profiles & * policies, power policy etc) * * Applications may choose to skip this step if the developer is sure * that the device is in its default state at start of application * * Note that all profiles and persistent settings that were done on the * device will be lost */ retVal = configureSimpleLinkToDefaultState(); if(retVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == retVal) CLI_Write(" Failed to configure the device in its default state \n\r"); LOOP_FOREVER(); } CLI_Write(" Device is configured in default state \n\r"); /* * Assumption is that the device is configured in station mode already * and it is in its default state */ retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } CLI_Write(" Device started as STATION \n\r"); /* Connecting to WLAN AP */ retVal = establishConnectionWithAP(); if(retVal < 0) { CLI_Write(" Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } CLI_Write(" Connection established w/ AP and IP is acquired \n\r"); // // Main Program Loop // while(1) { // // Get the current time from an SNTP server // retVal = GetCurrentTime(); if(retVal < 0) { CLI_Write(" Failed to GetCurrentTime.\n\r"); } // // Send the JSON packet with temperature to Event Hub // retVal = PostEventHubSSL(); if(retVal < 0) { CLI_Write(" Failed to PostEventHubSSL.\n\r"); } // // Wait a while before resuming. // This is an estimate, for more accuracy other methods should be implemented. // Delay(SLEEP_TIME); } }