コード例 #1
0
int wlan_connect(const char *ssid, const char *pass, unsigned char sec_type)
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = (signed char*)pass;
    secParams.KeyLen = strlen(pass);
    secParams.Type = sec_type;

    lRetVal = sl_WlanConnect((signed char*)ssid, strlen(ssid), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
        _SlNonOsMainLoopTask();   

    SlDateTime_t dateTime= {0};
    dateTime.sl_tm_day =   1;          // Day of month (DD format) range 1-13
    dateTime.sl_tm_mon =   1;           // Month (MM format) in the range of 1-12
    dateTime.sl_tm_year =  1970;        // Year (YYYY format)
    dateTime.sl_tm_hour =  0;          // Hours in the range of 0-23
    dateTime.sl_tm_min =   0;          // Minutes in the range of 0-59
    dateTime.sl_tm_sec =   1;          // Seconds in the range of  0-59

    lRetVal = sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME,
              sizeof(SlDateTime_t),(unsigned char *)(&dateTime));
    ASSERT_ON_ERROR(lRetVal);

    return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: bigcat26/cc3200-sdk
//****************************************************************************
//
//! \brief Connecting to a WLAN Accesspoint
//!
//!  This function connects to the required AP (SSID_NAME) with Security
//!  parameters specified in te form of macros at the top of this file
//!
//! \param  None
//!
//! \return  0 on success else error code 
//!
//! \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
long WlanConnect()
{
   long lRetVal = -1;
   SlSecParams_t secParams;

   secParams.Key = SECURITY_KEY;
   secParams.KeyLen = strlen(SECURITY_KEY);
   secParams.Type = SECURITY_TYPE;

   lRetVal = sl_WlanConnect(SSID_NAME,strlen(SSID_NAME),0,&secParams,0);
   ASSERT_ON_ERROR(lRetVal);
   
   while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
   {
       // Toggle LEDs to Indicate Connection Progress
       GPIO_IF_LedOff(MCU_IP_ALLOC_IND);
       MAP_UtilsDelay(800000);
       GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
       MAP_UtilsDelay(800000);

   }
   //
   // Red LED on to indicate AP connection
   //
   GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
   return SUCCESS;
}
コード例 #3
0
ファイル: cc3200_wifi.c プロジェクト: zikalino/mongoose-iot
int miot_wifi_connect(void) {
  int ret;
  SlSecParams_t sp;

  if (!ensure_role_sta()) return 0;

  if (s_wifi_sta_config.static_ip.ipV4 != 0) {
    ret = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,
                       IPCONFIG_MODE_ENABLE_IPV4,
                       sizeof(s_wifi_sta_config.static_ip),
                       (unsigned char *) &s_wifi_sta_config.static_ip);
  } else {
    _u8 val = 1;
    ret = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,
                       IPCONFIG_MODE_ENABLE_IPV4, sizeof(val), &val);
  }
  if (ret != 0) return 0;

  /* Turning the device off and on for the role change to take effect. */
  if (!restart_nwp()) return 0;

  sp.Key = (_i8 *) s_wifi_sta_config.pass;
  sp.KeyLen = strlen(s_wifi_sta_config.pass);
  sp.Type = sp.KeyLen ? SL_SEC_TYPE_WPA : SL_SEC_TYPE_OPEN;

  ret = sl_WlanConnect((const _i8 *) s_wifi_sta_config.ssid,
                       strlen(s_wifi_sta_config.ssid), 0, &sp, 0);
  if (ret != 0) return 0;

  sl_WlanRxStatStart();

  LOG(LL_INFO, ("Connecting to %s", s_wifi_sta_config.ssid));

  return 1;
}
コード例 #4
0
ファイル: main.c プロジェクト: ClarePhang/SimpleLink-CC3200
//****************************************************************************
//
//! \brief Connecting to a WLAN Accesspoint
//!
//!  This function connects to the required AP (SSID_NAME) with Security
//!  parameters specified in te form of macros at the top of this file
//!
//! \param  None
//!
//! \return  None
//!
//! \warning    If the WLAN connection fails or we don't aquire an IP 
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = (signed char*)SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    lRetVal = sl_WlanConnect((signed char*)SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    // Wait for WLAN Event
    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) 
    { 
        // Toggle LEDs to Indicate Connection Progress
        GPIO_IF_LedOff(MCU_IP_ALLOC_IND);
        MAP_UtilsDelay(800000);
        GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
        MAP_UtilsDelay(800000);
    }

    return SUCCESS;
   
}
コード例 #5
0
ファイル: WiFi.cpp プロジェクト: AmirRajabifar/Energia
//!!Ignore key index!!//
int WiFiClass::begin(char* ssid, uint8_t key_idx, char* key)
{
    //
    // If we already called begin and are already connecting
    // then return the status. This prevents sl_WlanConnect() 
    // from being called repeatedly.
    //
    if(_connecting) {
        delay(500);
        return status();
    }
 
    //
    //initialize the simplelink driver and make sure it was a success
    //
    bool init_success = WiFiClass::init();
    if (!init_success) {
        return WL_CONNECT_FAILED;
    }

    sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES);

    //
    // Set IP address configuration to DHCP if needed
    //
    setIpDefaults();

    sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,1,0,0,0), 0, 0);

    //
    //get name length and set security type to WEP
    //add key and keylength to security parameters
    //
    int NameLen = strlen(ssid);
    SlSecParams_t SecParams = {0};
    SecParams.Type = SL_SEC_TYPE_WEP;
    SecParams.Key = (signed char *)key;
    SecParams.KeyLen = strlen(key);
    
    //
    //Connect to the access point (non enterprise, so 5th argument is NULL);
    //also mac address parameter set as null (3rd argument)
    //
    int iRet = sl_WlanConnect((signed char*)ssid, NameLen, NULL, &SecParams, NULL);
    
    //
    //return appropriate status as described by arduino wifi library
    //the WiFiClass:WiFi_status is handled by the WlanEvenHandler
    //in SimpleLinkCallbacks.cpp. However, if iRet < 0, there was an error
    //
    if (iRet == 0) {
        sl_WlanProfileAdd((signed char*)ssid, NameLen, 0, &SecParams, 0, 6, 0);
        _connecting = true;
        return status();
    } else {
        return WL_CONNECT_FAILED;
    }
    
}
コード例 #6
0
ファイル: main.c プロジェクト: dlugaz/All
//****************************************************************************
//
//!  \brief Connecting to a WLAN Access point
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in the form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return                 None
//!
//!   \warning    If the WLAN connection fails or we don't acquire an IP 
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = (signed char *)P2P_SECURITY_KEY;
    secParams.KeyLen = strlen(P2P_SECURITY_KEY);
    secParams.Type = P2P_SECURITY_TYPE;

    lRetVal = sl_WlanConnect((signed char *)P2P_REMOTE_DEVICE,
                            strlen((const char *)P2P_REMOTE_DEVICE), 0,
                            &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    // Wait till Device acquired an IP in P2P mode
    while(! IS_P2P_REQ_RCVD(g_ulStatus))
    { 
        _SlNonOsMainLoopTask();
    }

    // Connect with the device requesting the connection
    lRetVal = sl_WlanConnect((signed char *)g_p2p_dev,
                           strlen((const char *)g_p2p_dev),
                           0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);
    
#ifdef P2P_ROLE_TYPE_NEGOTIATE
    while(! IS_IP_ACQUIRED(g_ulStatus))
#else
    while(! IS_IP_LEASED(g_ulStatus))
#endif
    {
        _SlNonOsMainLoopTask();
        if(IS_CONNECT_FAILED(g_ulStatus))
        {
            // Error, connection is failed
            ASSERT_ON_ERROR(NETWORK_CONNECTION_FAILED);
        }
    }

    return SUCCESS;
}
コード例 #7
0
ファイル: main.c プロジェクト: Balu1991/Wifly_Light
//****************************************************************************
//
//!  \brief Connecting to a WLAN Access point
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in the form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return                 None
//!
//!   \warning    If the WLAN connection fails or we don't acquire an IP 
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long retVal = 0;

    secParams.Key = SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    retVal = sl_WlanConnect(P2P_REMOTE_DEVICE, strlen(P2P_REMOTE_DEVICE), 0,
                            &secParams, 0);
    ASSERT_ON_ERROR(__LINE__, retVal);

    // Wait till Device acquired an IP in P2P mode
    while(! IS_P2P_REQ_RCVD(g_ulStatus))
    { 
        _SlNonOsMainLoopTask();
    }

    // Connect with the device requesting the connection
    retVal = sl_WlanConnect(g_p2p_dev, strlen(g_p2p_dev), 0, &secParams, 0);
    ASSERT_ON_ERROR(__LINE__, retVal);
    
#ifdef P2P_ROLE_TYPE_NEGOTIATE
    while(! IS_IP_ACQUIRED(g_ulStatus))
#else
    while(! IS_IP_LEASED(g_ulStatus))
#endif
    {
        _SlNonOsMainLoopTask();
        if(IS_CONNECT_FAILED(g_ulStatus))
        {
            // Error, connection is failed
            UART_PRINT("Connection Failed\r\n");
            return -1;
        }
    }

    return SUCCESS;
}
コード例 #8
0
//******************************************************************************
//    \brief Connecting to a WLAN Access point
//
//    This function connects to the required AP (SSID_NAME).
//    This code example can use OPEN, WPA, or WEP security.
//    The function will return once we are connected and have acquired IP address
//
//    \param[in]  None
//
//    \return     None
//
//    \note
//
//    \warning    If the WLAN connection fails or we don't aquire an IP address,
//                We will be stuck in this function forever.
//******************************************************************************
void WlanConnect(void){
  SlSecParams_t secParams;

  secParams.Key = PASSKEY;
  secParams.KeyLen = strlen(PASSKEY);
  secParams.Type = SEC_TYPE; // OPEN, WPA, or WEP

  sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);

  while((0 == (g_Status & CONNECTED)) || (0 == (g_Status & IP_AQUIRED))){
    _SlNonOsMainLoopTask();
  }
}
コード例 #9
0
ファイル: main.c プロジェクト: JohnStarich/ee445l
void Wifi_Connect(char *pConfig, SlSecParams_t *secParams) {
	int32_t retVal;
	retVal = configureSimpleLinkToDefaultState(pConfig); // set policies
  if(retVal < 0)Crash(4000000);
  retVal = sl_Start(0, pConfig, 0);
  if((retVal < 0) || (ROLE_STA != retVal) ) Crash(8000000);
  secParams->Key = PASSKEY;
  secParams->KeyLen = strlen(PASSKEY);
  secParams->Type = SEC_TYPE; // OPEN, WPA, or WEP
  sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, secParams, 0);
  while((0 == (g_Status&CONNECTED)) || (0 == (g_Status&IP_AQUIRED))){
    _SlNonOsMainLoopTask();
  }
  UARTprintf("Connected\n");
}
コード例 #10
0
ファイル: starter1.c プロジェクト: manavm/Classes
//******************************************************************************
//    \brief Connecting to a WLAN Access point
//
//    This function connects to the required AP (SSID_NAME).
//    This code example assumes the AP doesn't use WIFI security.
//    The function will return once we are connected and have acquired IP address
//
//    \param[in]  None
//
//    \return     None
//
//    \note
//
//    \warning    If the WLAN connection fails or we don't aquire an IP address,
//                We will be stuck in this function forever.
//******************************************************************************
void WlanConnect()
{
    SlSecParams_t secParams;

    secParams.Key = "";
    secParams.KeyLen = 0;
    secParams.Type = SL_SEC_TYPE_OPEN;

    sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);

    while((0 == (g_Status & CONNECTED)) || (0 == (g_Status & IP_AQUIRED)))
    {
        _SlNonOsMainLoopTask();
    }
}
コード例 #11
0
ファイル: wifi.c プロジェクト: LorDClockaN/AdAway
bool wifi_setup_sta(const char *ssid, const char *pass) {
    SlSecParams_t sp;
    LOG(LL_INFO, ("WiFi: connecting to %s", ssid));
    if (sl_WlanSetMode(ROLE_STA) != 0) return false;
    sl_Stop(0);
    sl_Start(NULL, NULL, NULL);
    sl_WlanDisconnect();
    sp.Key = (_i8 *) pass;
    sp.KeyLen = strlen(pass);
    sp.Type = sp.KeyLen ? SL_SEC_TYPE_WPA : SL_SEC_TYPE_OPEN;
    if (sl_WlanConnect((const _i8 *) ssid, strlen(ssid), 0, &sp, 0) != 0) {
        return false;
    }
    return true;
}
コード例 #12
0
//****************************************************************************
//
//!	\brief Connecting to a WLAN Accesspoint
//!
//!	This function connects to the required AP (SSID_NAME) with Security
//! parameters specified in te form of macros at the top of this file
//!
//!	\param[in] 			        None
//!
//!	\return	                    None
//!
//!	\warning	If the WLAN connection fails or we don't aquire an IP address,
//!				We will be stuck in this function forever.
//
//****************************************************************************
void WlanConnect()
{
   SlSecParams_t secParams;
   secParams.Key = SECURITY_KEY;
   secParams.KeyLen = strlen(SECURITY_KEY);
   secParams.Type = SECURITY_TYPE;

  // sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
   
   sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, NULL, 0);

   while ((g_uiConnectionStatus == 0) || (g_uiIpObtained == 0))
   {
       //looping till ip is acquired
   }
}
コード例 #13
0
ファイル: main.c プロジェクト: DavidUser/CC3100
/*!
    \brief Connecting to a WLAN Access point

    This function connects to the required AP (SSID_NAME).
    The function will return once we are connected and have acquired IP address

    \param[in]  None

    \return     0 on success, negative error-code on error

    \note

    \warning    If the WLAN connection fails or we don't acquire an IP address,
                We will be stuck in this function forever.
*/
static _i32 establishConnectionWithAP()
{
    SlSecParams_t secParams = {0};
    _i32 retVal = 0;

    secParams.Key = "";
    secParams.KeyLen = 0;
    secParams.Type = SL_SEC_TYPE_OPEN;

    retVal = sl_WlanConnect(UNSEC_SSID_NAME, pal_Strlen(UNSEC_SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(retVal);

    /* Wait */
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

    return SUCCESS;
}
コード例 #14
0
ファイル: ControlServer.c プロジェクト: yajun0601/CC3200
uint8_t WlanConnect() {

	SlSecParams_t secParams = { 0 };

	secParams.Key = g_sSLCon.PW;
	secParams.KeyLen = strlen(g_sSLCon.PW);
	secParams.Type = CONFIG_HOST_SEC_TYPE;

	sl_Start(0, 0, 0);
	sl_WlanConnect(g_sSLCon.SSID, strlen(g_sSLCon.SSID), 0, &secParams, 0);

	while ((!STATUS_GET(g_sSLCon.Status, STATUS_BIT_CONNECTED))
			|| (!STATUS_GET(g_sSLCon.Status, STATUS_BIT_IP_ACQUIRED))) {
	}

	return 0;
}
コード例 #15
0
ファイル: connection.c プロジェクト: callalilychen/TIOT
/*!
    \brief Connecting to a WLAN Access point

    This function connects to the required AP (SSID_NAME).
    The function will return once we are connected and have acquired IP address

    \param[in]  None

    \return     0 on success, negative error-code on error

    \note

    \warning    If the WLAN connection fails or we don't acquire an IP address,
                We will be stuck in this function forever.
*/
_i32 establishConnectionWithAP()
{

  _i32 retVal = 0;
    SlSecParams_t secParams = {0};

    secParams.Key = (_i8 *)PASSKEY;
    secParams.KeyLen = pal_Strlen(PASSKEY);
    secParams.Type = SEC_TYPE;

    retVal = sl_WlanConnect((_i8 *)SSID_NAME, pal_Strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(retVal);

    /* Wait */
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

    return SUCCESS;
}
コード例 #16
0
ファイル: main.c プロジェクト: CaptFrank/CC3200-Linux-SDK
//*****************************************************************************
//
//!    \brief Connecting to a WLAN Accesspoint
//!    This function connects to the required AP (SSID_NAME).
//!    This code example assumes the AP doesn't use WIFI security.
//!    The function will return only once we are connected 
//!    and have acquired IP address
//!
//!    \param[in] None
//!
//!    \return None
//!
//!    \note 0 on success else error code
//!
//!    \warning    If the WLAN connection fails or we don't aquire an IP address,
//!                We will be stuck in this function forever.
//
//*****************************************************************************
long 
WpsConnectPinCode()
{
    SlSecParams_t secParams;
    long lRetVal = -1;

    secParams.Key = WPS_PIN_CODE;
    secParams.KeyLen = strlen(WPS_PIN_CODE);
    secParams.Type = SL_SEC_TYPE_WPS_PIN;

    lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        _SlNonOsMainLoopTask();
    }
    return SUCCESS;
}
コード例 #17
0
ファイル: main.c プロジェクト: Balu1991/Wifly_Light
void WlanConnect()
{
    //Add Profile
    sl_WlanProfileAdd(g_cWlanSSID, strlen((char*)g_cWlanSSID), 0, &g_SecParams,
                        0,g_ucPriority,0);

    //Connecting to the Access point
    sl_WlanConnect(g_cWlanSSID, strlen((char*)g_cWlanSSID), 0, &g_SecParams, 0);

    //waiting for the device to connect to the AP and obtain ip address
    while (g_uiConnectTimeoutCnt<CONNECTION_TIMEOUT_COUNT && 
                ((g_ucConnectionStatus == 0) || (g_ucIpObtained == 0)))
    {
        osi_Sleep(1); //Sleep 1 millisecond
        g_uiConnectTimeoutCnt++;
    }

    g_uiConnectTimeoutCnt = 0;

}
コード例 #18
0
ファイル: main.c プロジェクト: gale320/cc3200
//****************************************************************************
//
//! \brief Connecting to a WLAN Accesspoint
//!
//!  This function connects to the required AP (SSID_NAME) with Security
//!  parameters specified in te form of macros at the top of this file
//!
//! \param  None
//!
//! \return  None
//!
//! \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    // Wait for WLAN Event
    while((!IS_CONNECTED(g_ulStatus))|| (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        _SlNonOsMainLoopTask();
    }

    return SUCCESS;
}
コード例 #19
0
ファイル: main.c プロジェクト: CaptFrank/CC3200-Linux-SDK
//****************************************************************************
//
//!  \brief Connecting to a WLAN Accesspoint
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in te form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return       status value
//!
//!   \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = (signed char*)SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    lRetVal = sl_WlanConnect((signed char*)SSID_NAME, strlen(SSID_NAME), 0, \
                                    &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    while(g_ulStatus != 1)
    {
        // Wait for WLAN Event
        _SlNonOsMainLoopTask();
    }

    return SUCCESS;
}
コード例 #20
0
ファイル: net.c プロジェクト: CaptFrank/CC3200-Linux-SDK
//****************************************************************************
//
//!  \brief Connecting to a WLAN Accesspoint
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in te form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return       status value
//!
//!   \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
long NetWlanConnect(const char *cssid, SlSecParams_t *secParams)
{
    long lRetVal = 0;

    lRetVal = sl_WlanConnect((signed char *)cssid, strlen(cssid), 0, secParams, 0);
    if( lRetVal != 0)
    {
      return lRetVal;
    }

    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        // Wait for WLAN Event
#ifndef SL_PLATFORM_MULTI_THREADED
              _SlNonOsMainLoopTask();
#endif

    }

    return SUCCESS;

}
コード例 #21
0
ファイル: WiFi.cpp プロジェクト: LCPINAGE/Energia
//!!Ignore key index!!//
int WiFiClass::begin(char* ssid, uint8_t key_idx, char* key)
{
    //
    //initialize the simplelink driver and make sure it was a success
    //
    bool init_success = WiFiClass::init();
    if (!init_success) {
        return WL_CONNECT_FAILED;
    }
    
    //
    //get name length and set security type to WEP
    //add key and keylength to security parameters
    //
    int NameLen = strlen(ssid);
    SlSecParams_t SecParams = {0};
    SecParams.Type = SL_SEC_TYPE_WEP;
    SecParams.Key = key;
    SecParams.KeyLen = strlen(key);
    
    //
    //Connect to the access point (non enterprise, so 5th argument is NULL);
    //also mac address parameter set as null (3rd argument)
    //
    int iRet = sl_WlanConnect(ssid, NameLen, NULL, &SecParams, NULL);
    
    //
    //return appropriate status as described by arduino wifi library
    //the WiFiClass:WiFi_status is handled by the WlanEvenHandler
    //in SimpleLinkCallbacks.cpp. However, if iRet < 0, there was an error
    //
    if (iRet == 0) {
        return status();
    } else {
        return WL_CONNECT_FAILED;
    }
    
}
コード例 #22
0
ファイル: cc3200_wifi.c プロジェクト: yonglehou/smart.js
int sj_wifi_connect() {
  int ret;
  SlSecParams_t sp;

  if (sl_WlanSetMode(ROLE_STA) != 0) {
    return 0;
  }
  /* Turning the device off and on for the role change to take effect. */
  sl_Stop(0);
  sl_Start(NULL, NULL, NULL);

  sp.Key = (_i8 *) s_wifi_sta_config.pass;
  sp.KeyLen = strlen(s_wifi_sta_config.pass);
  sp.Type = sp.KeyLen ? SL_SEC_TYPE_WPA : SL_SEC_TYPE_OPEN;

  ret = sl_WlanConnect((const _i8 *) s_wifi_sta_config.ssid,
                       strlen(s_wifi_sta_config.ssid), 0, &sp, 0);
  if (ret != 0) {
    fprintf(stderr, "WlanConnect error: %d\n", ret);
    return 0;
  }
  return 1;
}
コード例 #23
0
ファイル: main.c プロジェクト: gale320/cc3200
//****************************************************************************
//
//!  \brief Connecting to a WLAN Accesspoint
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in te form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return       status value
//!
//!   \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = (signed char*)SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    lRetVal = sl_WlanConnect((signed char*)SSID_NAME, strlen(SSID_NAME), 0, \
                                    &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        // Wait for WLAN Event
#ifndef SL_PLATFORM_MULTI_THREADED
        _SlNonOsMainLoopTask();
#endif
      
    }

    return SUCCESS;
}
コード例 #24
0
ファイル: main.c プロジェクト: DavidUser/CC3100
/*!
    \brief Connecting to a WLAN Access point

    This function connects to the required AP (ENT_SSID_NAME).
    The function will return once we are connected and have acquired IP address

    \param[in]  None

    \return     0 on success, negative error-code on error

    \note

    \warning    If the WLAN connection fails or we don't acquire an IP address,
                We will be stuck in this function forever.
*/
static _i32 establishConnectionWithAP()
{
    SlSecParams_t secParams = {0};
    SlSecParamsExt_t eapParams = {0};

    _i32 retVal = -1;

    secParams.Key = ENT_PASS_KEY;
    secParams.KeyLen = pal_Strlen(ENT_PASS_KEY);
    secParams.Type = ENT_SEC_TYPE;

    eapParams.EapMethod = ENT_SEC_METHOD;
    eapParams.User = ENT_USER_NAME;
    eapParams.UserLen = pal_Strlen(ENT_USER_NAME);
    eapParams.AnonUserLen = 0;

    retVal = sl_WlanConnect(ENT_SSID_NAME, pal_Strlen(ENT_SSID_NAME), NULL, &secParams, &eapParams);
    ASSERT_ON_ERROR(retVal);

    /* Wait */
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

    return SUCCESS;
}
コード例 #25
0
ファイル: main.c プロジェクト: jsnowboard/EE-445L
int main(void){int32_t retVal;  SlSecParams_t secParams;
  char *pConfig = NULL; INT32 ASize = 0; SlSockAddrIn_t  Addr;
	ADC0_InitSWTriggerSeq3_Ch9();         // allow time to finish activating
  initClk();        // PLL 50 MHz
	Output_On();
	UART_Init();      // Send data to PC, 115200 bps
  Timer1_Init();
  LED_Init();       // initialize LaunchPad I/O 
  UARTprintf("Weather App\n");
  retVal = configureSimpleLinkToDefaultState(pConfig); // set policies
  if(retVal < 0)Crash(4000000);
  retVal = sl_Start(0, pConfig, 0);
  if((retVal < 0) || (ROLE_STA != retVal) ) Crash(8000000);
  secParams.Key = PASSKEY;
  secParams.KeyLen = strlen(PASSKEY);
  secParams.Type = SEC_TYPE; // OPEN, WPA, or WEP
  sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
  while((0 == (g_Status&CONNECTED)) || (0 == (g_Status&IP_AQUIRED))){
    _SlNonOsMainLoopTask();
  }
  UARTprintf("Connected\n");
  while(1){
		int i = 0;
		while(i < 10){
			int sendc = 0;
			strcpy(HostName,"openweathermap.org");
			retVal = sl_NetAppDnsGetHostByName(HostName,
							 strlen(HostName),&DestinationIP, SL_AF_INET);
			if(retVal == 0){
				Addr.sin_family = SL_AF_INET;
				Addr.sin_port = sl_Htons(80);
				Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);// IP to big endian 
				ASize = sizeof(SlSockAddrIn_t);
				SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
				if( SockID >= 0 ){
					retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, ASize);
				}
				if((SockID >= 0)&&(retVal >= 0)){
					strcpy(SendBuff,REQUEST); 
					sl_Send(SockID, SendBuff, strlen(SendBuff), 0);// Send the HTTP GET 
					sl_Recv(SockID, Recvbuff, MAX_RECV_BUFF_SIZE, 0);// Receive response 
					sl_Close(SockID);
					LED_GreenOn();
					UARTprintf("\r\n\r\n");
					UARTprintf(Recvbuff);  UARTprintf("\r\n");
				}
			}
			ST7735_OutUDec(sendc);
			ST7735_OutString("\n");
			i++;
		}
		
		//while(Board_Input()==0){}; // wait for touch
		LED_GreenOff();
		//Temp Part e
		getTemp(Recvbuff);
		ST7735_OutChar('T');
		ST7735_OutChar('e');
		ST7735_OutChar('m');
		ST7735_OutChar('p');
		ST7735_OutChar(' ');
		ST7735_OutChar('=');
		ST7735_OutChar(' ');
		for(int i = 0; i < 5; i++){
			ST7735_OutChar(myArray[i]);
		}
		ST7735_OutChar('\n');

		//ADC Part f
		ADC0_SAC_R = ADC_SAC_AVG_64X;    //enable 64 times average before obtaining result
    int voltage = ADC0_InSeq3();
		ST7735_OutString("Voltage~");
		ST7735_sDecOut3(voltage);
		
		char* voltageString;
		char voltageStringNum[5];
		sprintf(voltageStringNum, "%.1d.%.3d", voltage/1000, voltage%1000);
		//ST7735_OutString(voltageStringNum);
		
		char* sendString;
		char str1[173] = "GET /query?city=Austin%20Texas&id=Ty%20Winkler%20Jeremiah%20Bartlett&greet=Voltage%3D";
		strcat(str1, voltageStringNum);
		strcat(str1, "V&edxcode=8086 HTTP/1.1\r\nUser-Agent: Keil\r\nHost: embsysmooc.appspot.com\r\n\r\n");
		
		
		strcpy(HostName,"embsysmooc.appspot.com");
		retVal = sl_NetAppDnsGetHostByName(HostName,
						 strlen(HostName),&DestinationIP, SL_AF_INET);
		if(retVal == 0){
			Addr.sin_family = SL_AF_INET;
			Addr.sin_port = sl_Htons(80);
			Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);// IP to big endian 
			ASize = sizeof(SlSockAddrIn_t);
			SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
			if( SockID >= 0 ){
				retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, ASize);
			}
			if((SockID >= 0)&&(retVal >= 0)){
				strcpy(SendBuff, str1);
				count = 0;					
				sl_Send(SockID, SendBuff, strlen(SendBuff), 0);// Send the HTTP GET 
				sl_Recv(SockID, Recvbuff, MAX_RECV_BUFF_SIZE, 0);// Receive response 
				sl_Close(SockID);
				LED_GreenOn();
				UARTprintf("\r\n\r\n");
				//ST7735_OutString(Recvbuff);  
				UARTprintf("\r\n");
			}
		}
		while(1);
	}
}
コード例 #26
0
//*****************************************************************************
//
//! Network_IF_ConnectAP  Connect to an Access Point using the specified SSID
//!
//! \param  pcSsid is a string of the AP's SSID
//!
//! \return none
//
//*****************************************************************************
int
Network_IF_ConnectAP(char *pcSsid, SlSecParams_t SecurityParams)
{
    char acCmdStore[128];
    unsigned short usConnTimeout;
    int iRetVal;
    unsigned long ulIP = 0;
    unsigned long ulSubMask = 0;
    unsigned long ulDefGateway = 0;
    unsigned long ulDns = 0;
    unsigned char ucRecvdAPDetails;

    Network_IF_DisconnectFromAP();

    //
    // This triggers the CC3200 to connect to specific AP
    //
    sl_WlanConnect(pcSsid, strlen(pcSsid), NULL, &SecurityParams, NULL);

    //
    // Wait to check if connection to DIAGNOSTIC_AP succeeds
    //
    while(g_usConnectIndex < 10)
    {
        MAP_UtilsDelay(8000000);
        g_usConnectIndex++;
        if(IS_CONNECTED(g_ulStatus))
        {
            break;
        }
    }

    //
    // Check and loop until async event from network processor indicating Wlan
    // Connect success was received
    //
    while(!(IS_CONNECTED(g_ulStatus)))
    {
        //
        // Disconnect the previous attempt
        //
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
        UART_PRINT("Device could not connect to %s\n\r",pcSsid);

        do
        {
            ucRecvdAPDetails = 0;

            UART_PRINT("\n\r\n\rPlease enter the AP(open) SSID name # ");

            //
            // Get the AP name to connect over the UART
            //
            iRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
            if(iRetVal > 0)
            {
                //
                // Parse the AP name
                //
                pcSsid = strtok(acCmdStore, ":");
                if(pcSsid != NULL)
                {

                    ucRecvdAPDetails = 1;

                }
            }
        } while(ucRecvdAPDetails == 0);

        UART_PRINT("\n\rTrying to connect to AP: %s ...\n\r",pcSsid);
        /*UART_PRINT("Key: %s, Len: %d, KeyID: %d, Type: %d\n\r",
                    SecurityParams.Key, SecurityParams.KeyLen
                      , SecurityParams.Type);
        */

        //
        // Get the current timer tick and setup the timeout accordingly
        //
        usConnTimeout = g_usConnectIndex + 10;

        //
        // This triggers the CC3200 to connect to specific AP
        //
        sl_WlanConnect(pcSsid, strlen(pcSsid), NULL, &SecurityParams, NULL);

        //
        // Wait to check if connection to specifed AP succeeds
        //
        while(!(IS_CONNECTED(g_ulStatus)))
        {
            if(g_usConnectIndex >= usConnTimeout)
            {
                break;
            }
            MAP_UtilsDelay(8000000);
            g_usConnectIndex++;
        }
    }

    //
    // Wait until IP is acquired
    //
    while(!(IS_IP_ACQUIRED(g_ulStatus)));

    //
    // Put message on UART
    //
    UART_PRINT("\n\rDevice has connected to %s\n\r",pcSsid);

    //
    // Get IP address
    //
    Network_IF_IpConfigGet(&ulIP,&ulSubMask,&ulDefGateway,&ulDns);

    //
    // Send the information
    //
    UART_PRINT("Device IP Address is %d.%d.%d.%d \n\r\n\r",
               SL_IPV4_BYTE(ulIP, 3),SL_IPV4_BYTE(ulIP, 2),
               SL_IPV4_BYTE(ulIP, 1),SL_IPV4_BYTE(ulIP, 0));
    return 0;
}
コード例 #27
0
//*****************************************************************************
//
//! Network_IF_ConnectAP  Connect to an Access Point using the specified SSID
//!
//! \param[in]  pcSsid is a string of the AP's SSID
//! \param[in]  SecurityParams is Security parameter for AP
//!
//! \return On success, zero is returned. On error, -ve value is returned
//
//*****************************************************************************
long
Network_IF_ConnectAP(char *pcSsid, SlSecParams_t SecurityParams)
{
#ifndef NOTERM  
    char acCmdStore[128];
    unsigned short usConnTimeout;
    unsigned char ucRecvdAPDetails;
#endif
    long lRetVal;
    unsigned long ulIP = 0;
    unsigned long ulSubMask = 0;
    unsigned long ulDefGateway = 0;
    unsigned long ulDns = 0;

    //
    // Disconnect from the AP
    //
    Network_IF_DisconnectFromAP();
    
    //
    // This triggers the CC3200 to connect to specific AP
    //
    lRetVal = sl_WlanConnect((signed char *)pcSsid, strlen((const char *)pcSsid),
                        NULL, &SecurityParams, NULL);
    ASSERT_ON_ERROR(lRetVal);

    //
    // Wait for ~10 sec to check if connection to desire AP succeeds
    //
    while(g_usConnectIndex < 15)
    {
#ifndef SL_PLATFORM_MULTI_THREADED
        _SlNonOsMainLoopTask();
#else
              osi_Sleep(1);
#endif
        MAP_UtilsDelay(8000000);
        if(IS_CONNECTED(g_ulStatus) && IS_IP_ACQUIRED(g_ulStatus))
        {
            break;
        }
        g_usConnectIndex++;
    }

#ifndef NOTERM
    //
    // Check and loop until AP connection successful, else ask new AP SSID name
    //
    while(!(IS_CONNECTED(g_ulStatus)) || !(IS_IP_ACQUIRED(g_ulStatus)))
    {
        //
        // Disconnect the previous attempt
        //
        Network_IF_DisconnectFromAP();

        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
        UART_PRINT("Device could not connect to %s\n\r",pcSsid);

        do
        {
            ucRecvdAPDetails = 0;

            UART_PRINT("\n\r\n\rPlease enter the AP(open) SSID name # ");

            //
            // Get the AP name to connect over the UART
            //
            lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
            if(lRetVal > 0)
            {
                // remove start/end spaces if any
                lRetVal = TrimSpace(acCmdStore);

                //
                // Parse the AP name
                //
                strncpy(pcSsid, acCmdStore, lRetVal);
                if(pcSsid != NULL)
                {
                    ucRecvdAPDetails = 1;
                    pcSsid[lRetVal] = '\0';

                }
            }
        }while(ucRecvdAPDetails == 0);

        //
        // Reset Security Parameters to OPEN security type
        //
        SecurityParams.Key = (signed char *)"";
        SecurityParams.KeyLen = 0;
        SecurityParams.Type = SL_SEC_TYPE_OPEN;

        UART_PRINT("\n\rTrying to connect to AP: %s ...\n\r",pcSsid);

        //
        // Get the current timer tick and setup the timeout accordingly
        //
        usConnTimeout = g_usConnectIndex + 15;

        //
        // This triggers the CC3200 to connect to specific AP
        //
        lRetVal = sl_WlanConnect((signed char *)pcSsid,
                                  strlen((const char *)pcSsid), NULL,
                                  &SecurityParams, NULL);
        ASSERT_ON_ERROR(lRetVal);

        //
        // Wait ~10 sec to check if connection to specifed AP succeeds
        //
        while(!(IS_CONNECTED(g_ulStatus)) || !(IS_IP_ACQUIRED(g_ulStatus)))
        {
#ifndef SL_PLATFORM_MULTI_THREADED
            _SlNonOsMainLoopTask();
#else
              osi_Sleep(1);
#endif
            MAP_UtilsDelay(8000000);
            if(g_usConnectIndex >= usConnTimeout)
            {
                break;
            }
            g_usConnectIndex++;
        }

    }
#endif
    //
    // Put message on UART
    //
    UART_PRINT("\n\rDevice has connected to %s\n\r",pcSsid);

    //
    // Get IP address
    //
    lRetVal = Network_IF_IpConfigGet(&ulIP,&ulSubMask,&ulDefGateway,&ulDns);
    ASSERT_ON_ERROR(lRetVal);

    //
    // Send the information
    //
    UART_PRINT("Device IP Address is %d.%d.%d.%d \n\r\n\r",
            SL_IPV4_BYTE(ulIP, 3),SL_IPV4_BYTE(ulIP, 2),
            SL_IPV4_BYTE(ulIP, 1),SL_IPV4_BYTE(ulIP, 0));
    return 0;
}
コード例 #28
0
ファイル: main.c プロジェクト: bigcat26/cc3200-sdk
//*****************************************************************************
//
//! \brief Connecting to a WLAN Accesspoint
//! This function connects to the required AP (SSID_NAME).
//! This code example assumes the AP doesn't use WIFI security.
//! The function will return only once we are connected
//! and have acquired IP address
//!
//! \param[in] None
//!
//! \return 0 means success, -1 means failure
//!
//! \note
//!
//! \warning    If the WLAN connection fails or we don't aquire an IP address,
//!             We will be stuck in this function forever.
//
//*****************************************************************************
int WlanConnect()
{
    int iRetCode = 0;
    int iRetVal = 0;
    int iConnect = 0;
    unsigned char ucQueueMsg = 0;
    SlSecParams_t secParams;

    secParams.Key = (signed char *)SECURITY_KEY;
    secParams.KeyLen = strlen((const char *)secParams.Key);
    secParams.Type = SECURITY_TYPE;

    //
    // Set up the watchdog interrupt handler.
    //
    WDT_IF_Init(WatchdogIntHandler, MILLISECONDS_TO_TICKS(WD_PERIOD_MS));
    /* Enabling the Sleep clock for the Watch Dog Timer*/
    MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_SLP_MODE_CLK);
    
    g_ucFeedWatchdog = 1;
    g_ucWdogCount = 0;
    while(!(ucQueueMsg & (EVENT_IP_ACQUIRED|CONNECTION_FAILED)))
    {
        UART_PRINT("Trying to connect to AP: ");
        UART_PRINT(SSID_NAME);
        UART_PRINT("\n\r");
        sl_WlanConnect((signed char *)SSID_NAME,
                        strlen((const char *)SSID_NAME), 0, &secParams, 0);
        iConnect = 0;
        do{
            osi_MsgQRead(&g_tConnection, &ucQueueMsg, OSI_WAIT_FOREVER);

            switch(ucQueueMsg)
            {
                case EVENT_CONNECTION:
                    iConnect = 1;
                    break;

                case EVENT_IP_ACQUIRED:
                    iRetVal = 0;
                    break;

                case WDOG_EXPIRED:

                    //
                    // disconnect from the Access Point
                    //
                    if(iConnect)
                    {
                        WlanDisconnect();
                    }

                    //
                    // stop the simplelink with reqd. timeout value (30 ms)
                    //
                    sl_Stop(SL_STOP_TIMEOUT);

                    UART_PRINT("sl stop\n\r");

                    MAP_UtilsDelay(8000);

                    //
                    // starting the simplelink
                    //
                    sl_Start(NULL, NULL, NULL);

                    UART_PRINT("sl start\n\r");
                    break;

                case EVENT_DISCONNECTION:
                    iConnect = 0;
                    break;

                case CONNECTION_FAILED:
                    iRetVal = -1;
                    break;

                default:
                    UART_PRINT("unexpected event\n\r");
                    break;
            }
        }while(ucQueueMsg == (unsigned char)EVENT_CONNECTION);
    }
    iRetCode = MAP_WatchdogRunning(WDT_BASE);
    if(iRetCode)
    {
       WDT_IF_DeInit();
       MAP_PRCMPeripheralClkDisable(PRCM_WDT, PRCM_RUN_MODE_CLK);
    }
    ASSERT_ON_ERROR(iRetVal);
    return(iRetVal);
}
コード例 #29
0
ファイル: main.c プロジェクト: bigcat26/cc3200-sdk
//****************************************************************************
//
//! \brief Configuring the Connection Policy
//!
//! This function configures different Connection Policy such as FAST,AUTO,OPEN
//!
//! \param[in]         None
//!
//! \return            0 on success else error code
//!
//!    \note
//
//****************************************************************************
static long SetConnectionPolicy()
{
    unsigned char policyVal;
    long lRetVal = -1;

    /* Clear all stored profiles and reset the policies */
    lRetVal = sl_WlanProfileDel(0xFF);    
    ASSERT_ON_ERROR(lRetVal);
    
    lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), 0, 0);    
    ASSERT_ON_ERROR(lRetVal);
    
    
    //Add Profile
    /* user needs to change SSID_NAME = "<Secured AP>"
             SECURITY_TYPE = SL_SEC_TYPE_WPA
             SECURITY_KEY = "<password>"
      and set the priority as per requirement 
      to connect with a secured AP */
    SlSecParams_t secParams;
    secParams.Key = SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;
    lRetVal = sl_WlanProfileAdd(SSID_NAME,strlen(SSID_NAME),0,&secParams,0,1,0);
    ASSERT_ON_ERROR(lRetVal);

    //set AUTO policy
    lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
                      SL_CONNECTION_POLICY(1,0,0,0,0),
                      &policyVal, 1 /*PolicyValLen*/);    
    ASSERT_ON_ERROR(lRetVal);
    
    //wait until IP is acquired
    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        _SlNonOsMainLoopTask();
    }
    CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
    CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);

    //
    // ****** Put breakpoint here ******
    // If control comes here- means device connected to AP in auto mode
    //

    // Disconnect from AP
    lRetVal = sl_WlanDisconnect();
    if(0 == lRetVal)
    {
        // Wait
        while(IS_CONNECTED(g_ulStatus))
        {
#ifndef SL_PLATFORM_MULTI_THREADED
              _SlNonOsMainLoopTask();
#endif
        }
    }

    //delete profiles
    lRetVal = sl_WlanProfileDel(0xFF);    
    ASSERT_ON_ERROR(lRetVal);

    //set Auto SmartConfig policy
    lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
                       SL_CONNECTION_POLICY(1,0,0,0,1),
                   &policyVal,0);    
    ASSERT_ON_ERROR(lRetVal);
    
    // reset the NWP
    lRetVal = ResetNwp();
    ASSERT_ON_ERROR(lRetVal);
    
    // wait for smart config to complete and device to connect to an AP
    //wait until IP is acquired
    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        _SlNonOsMainLoopTask();
    }
    CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
    CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);

    //
    // ****** Put breakpoint here ******
    // If control comes here- means device connected to AP in smartconfig mode
    //

    /* Delete all profiles (0xFF) stored */
    lRetVal = sl_WlanProfileDel(0xFF);    
    ASSERT_ON_ERROR(lRetVal);
    
    // reset the NWP
    lRetVal = ResetNwp();
    ASSERT_ON_ERROR(lRetVal);

    /* Set connection policy to Fast, Device will connect to last connected AP.
     * This feature can be used to reconnect to AP */
    lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , \
                                SL_CONNECTION_POLICY(1,1,0,0,0), 0, 0);
    ASSERT_ON_ERROR(lRetVal);

    /* Connect to the open AP */
    lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, 0, 0);
    ASSERT_ON_ERROR(lRetVal);
    
    //wait until IP is acquired
    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        _SlNonOsMainLoopTask();
    }
    CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
    CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
    
    // Add unsecured AP profile with priority 6 (7 is highest)
    // Because of a limitation in SDK-0.5 which prevents the automatic addition
    // of the profile (fast), the application is required to explicitly add it.
    // The limitation shall be addressed in subsequent SDK release, and the below
    // lines for adding the profile can be removed then...! 
    secParams.Key = "";
    secParams.KeyLen = 0;
    secParams.Type = SL_SEC_TYPE_OPEN;
    lRetVal = sl_WlanProfileAdd((signed char*)SSID_NAME,
                      strlen(SSID_NAME), 0, &secParams, 0, 6, 0);
    ASSERT_ON_ERROR(lRetVal);

    // reset the NWP
    lRetVal = ResetNwp();
    ASSERT_ON_ERROR(lRetVal);

    /* Wait for the connection to be established */
    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        _SlNonOsMainLoopTask();
    }
    
    //
    // ****** Put breakpoint here ******
    // If control comes here- means device connected to AP in FAST mode
    //
    
    //remove all policies
    lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
                   SL_CONNECTION_POLICY(0,0,0,0,0),
                   &policyVal,0);    
    ASSERT_ON_ERROR(lRetVal);

    return SUCCESS;

}
コード例 #30
0
void APP_Tasks(void) {
    /*
     * Processing CC3100 Tasks
     * It looks like SYS task and might be processed in SYS_Tasks
     * But for this demo it is here to make this call
     * visible
     */
    _SlNonOsMainLoopTask();

    /* Check the application's current state. */
    switch (appData.state) {
    /* Application's initial state. */
    case APP_STATE_INIT: {
        SYS_PRINT("\n\r*** PIC32 MQTT CLIENT ***\n\r");

        SYS_PRINT("\n\rInitializing CC3100\n\r");
        int res = sl_Start(NULL, NULL, NULL);
        if (res != 0) {
            SYS_PRINT("FAILED\n\r");
            appData.state = APP_STATE_DONE;
            break;
        }

        SlSecParams_t sec_params;
        memset(&sec_params, 0, sizeof(sec_params));
        sec_params.Key = NET_PWD;
        sec_params.KeyLen = sizeof(NET_PWD) - 1;
        sec_params.Type = NET_SECURITY;

        SYS_PRINT("Connecting to WiFi\n\r");

        sl_WlanConnect(NET_SSID, sizeof(NET_SSID) - 1, 0, &sec_params, NULL);

        SYS_PRINT("Initialization done\n\r");

        appData.state = APP_STATE_SERVICE_TASKS;

        break;
    }

    case APP_STATE_CONNECT_BROKER: {
        if (mg_connect(&mgr, MQTT_BROKER_ADDRESS, ev_handler) == NULL) {
            SYS_PRINT("Failed to create connection\n\r");
            appData.state = APP_STATE_DONE;
        } else {
            appData.state = APP_STATE_SERVICE_TASKS;
        }
        break;
    }
    case APP_STATE_SERVICE_TASKS: {
        static uint32_t prev_poll_time = 0;
        uint32_t now = DRV_RTCC_TimeGet();
        if (now - prev_poll_time > 100) {
            /*
             * We cannot call mg_mgr_poll every cycle
             * it leads to SPI overload (internaly mg_mgr_poll calls
             * CC3100 via SPI
             */
            mg_mgr_poll(&mgr, 1);
            prev_poll_time = now;
        }
        break;
    }

    case APP_STATE_DONE: {
        /* Do nothing here */
        break;
    }
    default: {
        /* TODO: Handle error in application's state machine. */
        break;
    }
    }
}