/*---------------------------------------------------------------------------*
 * Routine:  WIFI_Associate
 *---------------------------------------------------------------------------*
 * Description:
 *      Association and show result on the LCD
 * Inputs:
 *      void
 * Outputs:
 *      ATLIBGS_MSG_ID_E
 *---------------------------------------------------------------------------*/
ATLIBGS_MSG_ID_E WIFI_Associate(void)
{
  ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;

  DisplayLCD(LCD_LINE7, " Connecting ");

  /* Associate to a particular AP specified by SSID  */
  if (strlen(GNV_Setting.webprov.ssid) > 0)
  {
    DisplayLCD(LCD_LINE8, (const uint8_t *)GNV_Setting.webprov.ssid);
    rxMsgId = AtLibGs_Assoc(GNV_Setting.webprov.ssid,NULL,HOST_APP_AP_CHANNEL);
  }
  else
  {
    DisplayLCD(LCD_LINE8, HOST_APP_AP_SSID);
    rxMsgId = AtLibGs_Assoc(HOST_APP_AP_SSID, NULL, HOST_APP_AP_CHANNEL);
  }
  if (ATLIBGS_MSG_ID_OK != rxMsgId) {
    /* Association error - we can retry */
#ifdef HOST_APP_DEBUG_ENABLE
        ConsolePrintf("\n Association error - retry now \n");
#endif
    DisplayLCD(LCD_LINE7, " Connecting..");
    MSTimerDelay(2000);
    DisplayLCD(LCD_LINE7, "");
  } else {
    /* Association success */
    AtLibGs_SetNodeAssociationFlag();
    DisplayLCD(LCD_LINE7, " Connected ");
    MSTimerDelay(2000);
    DisplayLCD(LCD_LINE7, "");
  }

  return rxMsgId;
}
Example #2
0
/*---------------------------------------------------------------------------*
 * Routine:  WIFI_Associate
 *---------------------------------------------------------------------------*
 * Description:
 *      Association and show result on the LCD
 * Inputs:
 *      void
 * Outputs:
 *      ATLIBGS_MSG_ID_E
 *---------------------------------------------------------------------------*/
ATLIBGS_MSG_ID_E WIFI_Associate(void)
{
    ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;
    static ATLIBGS_AUTHMODE_E WEPMode=ATLIBGS_AUTHMODE_OPEN_WEP;
    int retVal;

    DisplayLCD(LCD_LINE4, "wl_trycon.. ");

    /* Associate to a particular AP specified by SSID  */
    if (strlen(GNV_Setting.webprov.ssid) > 0)
    {
        rxMsgId = AtLibGs_Assoc(GNV_Setting.webprov.ssid,NULL,HOST_APP_AP_CHANNEL);
    }
    else
    {
        rxMsgId = AtLibGs_Assoc(HOST_APP_AP_SSID, NULL, HOST_APP_AP_CHANNEL);
    }
    if (ATLIBGS_MSG_ID_OK != rxMsgId) 
    {
        /* Association error - we can retry */
        if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP)
        {
            if(WEPMode==ATLIBGS_AUTHMODE_OPEN_WEP)
            {
                rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_SHARED_WEP);// Potenially it's a WEP shared AP
                WEPMode=ATLIBGS_AUTHMODE_SHARED_WEP;
            }
            else
            {
                rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_OPEN_WEP);// Potenially it's a WEP shared AP
                WEPMode=ATLIBGS_AUTHMODE_OPEN_WEP;         
            }
        }
        DisplayLCD(LCD_LINE4, "Assoc failed...");
        MSTimerDelay(2000);
        DisplayLCD(LCD_LINE4, "Trying again...");
    } 
    else 
    {
        /* Association success */
        AtLibGs_SetNodeAssociationFlag();
        DisplayLCD(LCD_LINE4, "wl_connect  ");
        MSTimerDelay(2000);
        retVal = App_ConnectMqtt();
        switch(retVal)
        {
        case 0:    
            DisplayLCD(LCD_LINE5, "MQTT Connected");
            break;
        case -1:    
            DisplayLCD(LCD_LINE5, "MQTT packet error");
            break;
        case -2:    
            DisplayLCD(LCD_LINE5, "MQTT connack error");
            break;      
        }
    }

    return rxMsgId;
}