Jump to content
43oh

CC3200 can't connect to Wlan after being set as AP


Recommended Posts

Have been having great strides with CC3200 and Energia, but I hit a snag, hoping someone can assist.

 

I am attempting to use a AP server to display to surrounding available SSIDs and connect to it. Unfortunately as soon as I try to connect to the Wlan using WiFi.Begin it just fails. 

 

I have attached the test code below. When removing the WiFi.BeginNetwork(); the CC3200 connects to the WLan mentioned. But as soon as you introduce the AP it just doesn't connect.

//Include Files
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WString.h>

//stage 1
String security = "WPA";
String ssidconnect = "SSID";
String Passstr = "PASSWORD";
char ssid[50];
char Password[50];

char wifi_name[] = "APtest";     //create mem location, allow to be change in setup
char wifi_password[] = "APPassword"; //create mem location, allow to be change in setup

//Create Wifi server
WiFiServer server(80);

void setup()
{

  //Initialize serial and wait for port to open:
  Serial.begin(115200);
  Serial.println("Serial Terminal Initiated...");
  
  // Initiate Wifi
  WiFi.init();
  Serial.println("Wifi Initiated...");


  // Start WiFi and create a network with wifi_name as the network name
  // with wifi_password as the password.
  Serial.print("Starting network...");
  //WiFi.beginNetwork(wifi_name, wifi_password);
  Serial.println("done.");
  
  Serial.println("Starting webserver on port 80");
  server.begin();                           // start the web server on port 80
  Serial.println("Webserver started!");  
}

void loop()
{
  
    int keyIndex = 1;
    int stringlen = ssidconnect.length() + 1;
    ssidconnect.toCharArray(ssid, stringlen);
    stringlen = Passstr.length() + 1;
    Passstr.toCharArray(Password,stringlen);
    Serial.print("Security:  "); 
    Serial.println(security); 
    
    if(security == "WEP") {    
      Serial.println("Connecting to WEP encryption"); 
      // print the network name (SSID);
      Serial.println(ssid); 
      // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
      WiFi.begin(ssid, keyIndex,  Password);
    }
    else if (security == "WPA") {  
      Serial.println("Connecting to WPA encryption");
      // print the network name (SSID);
      Serial.print("SSID:  "); 
      Serial.println(ssid); 
      Serial.print("Password:  "); 
      Serial.println(Password); 
      // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
      WiFi.begin(ssid, Password);
    }
    else if (security == "None") {    
      Serial.println("Connecting to NO encryption");
      // print the network name (SSID);
      Serial.println(ssid); 
      // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
      WiFi.begin(ssid);
    }
    else {
      Serial.println("Can't pick up encryption type");      
      // Couldnt find Encryption type
      delay(1);
    }
    while ( WiFi.status() != WL_CONNECTED) {
      // print dots while we wait to connect
      Serial.print(".");
      delay(300);
    }
    Serial.println("\nYou're connected to the network");
    Serial.println("Waiting for an ip address");
  
    while (WiFi.localIP() == INADDR_NONE) {
      // print dots while we wait for an ip addresss
      Serial.print(".");
      delay(300);
    }

  Serial.println("\nIP Address obtained");
  // continue 
}

I'd appreciate any assistance in determining how to stop the AP or just getting the Wlan to run.

 

Thank you,

Abrie

Link to post
Share on other sites
  • 2 weeks later...
  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Go ahead and try #4!  It probably won't hurt.

My application never freeze from my last fix. I tried with a netgear and tplink router and a lot of brand of WiFi repeater

This method seems to work fine before beginNetwork() is used. Afterwards, it freezes at WiFi.disconnect() (before the "theoretically disconnected" prompt is displayed). Without the disconnect(), it would freeze at begin(...).

void SetupSTA()
{
  wifiMode = WIFI_MODE_STA;  // Initiates Station Mode
  
  Serial.print("Connecting to Access Point: ");
  Serial.println(sta_ssid);
  
  WiFi.disconnect();
  delay(5000);
  Serial.print("Theoretically disconnected");
  
  if(sta_key != 0)                               // If WEP Key exists...
     WiFi.begin(sta_ssid, sta_key, sta_password);  // Connect to WEP protected AP
  else if(sta_password != "")                    // If password exists...
    WiFi.begin(sta_ssid, sta_password);            // Connect to WPA protected AP
  else                                           // Else...
    WiFi.begin(sta_ssid);                          // Connect to open AP
    
  delay(5000);  // Connects better with this delay
  
  if(WiFi.status() == WL_CONNECTED)  // If connected...
  {
    Serial.println("Connection Successful");
    
    Serial.println("Awaiting IP Address...");
    while (WiFi.localIP() == INADDR_NONE) {}
    
    PrintWifiStatus();
    
    server.begin();
  }
  else
    Serial.println("Connection Failed");
}
Link to post
Share on other sites

Me too! But my solution seems to freeze every now and again. I added this to the start of "int WiFiClass::begin(char* ssid, char *passphrase)" in WiFi.cpp:

int iRet = sl_Start(NULL, NULL, NULL);    

//
    //set the mode to station if it's not already in station mode
    //
    if (iRet != ROLE_STA) {
        sl_WlanSetMode(ROLE_STA);
        role = ROLE_STA;
        sl_Stop(0);
        sl_Start(NULL, NULL, NULL);
    }

There is likely a better solution as I am not completely sure what I'm doing so it'd be awesome to see yours PaoloIT,

 

Edit: The random freezing seems to have stopped now and the cc3200 is seemlessly switching between ap mode and sta mode.

Link to post
Share on other sites

Hello guys,

I tested my fix and work fine.... 

I tryed AP->STA, STA->AP->STA and everything work fine.

this is the fix in wifi.cpp file in /hardware/CC3200/Libraries/WIFI.

I added role = ROLE_STA;

 

int WiFiClass::begin(char* ssid, char *passphrase)

{

    //

    // 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();

    }

    

    role=ROLE_STA;

 

    //

    // Set IP address configuration to DHCP if needed

    //

    bool init_success = WiFiClass::init();

    if (!init_success) {

        return WL_CONNECT_FAILED;

    }

 

    setIpDefaults();

 

    //

    //initialize the simplelink driver and make sure it was a success

    //

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

 

    //

    //get name length and set security type to WPA

    //add passphrase and keylength to security parameters

    //

    int NameLen = strlen(ssid);

    SlSecParams_t SecParams = {0};

    SecParams.Type = SL_SEC_TYPE_WPA;

    SecParams.Key = passphrase;

    SecParams.KeyLen = strlen(passphrase);

    

    //

    //connect to the access point (non enterprise, so 5th argument is NULL)

    //also mac address parameters 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) {

        sl_WlanProfileAdd(ssid, NameLen, 0, &SecParams, 0, 6, 0);

        _connecting = true;

        return status();

    } else {

        return WL_CONNECT_FAILED;

    }

}

 

In the firmware is necessary add 

 

  WiFi._initialized = false;

  WiFi._connecting = false;
 
before call WiFi.begin.
 
an example here:
 
void TestConnectionAP(void){
  
  Serial.print("Attempting to connect to Network named: ");
  Serial.println(ssid); 
  
  Serial.print("Init wifi in STA mode");
  
  WiFi._initialized = false;
  WiFi._connecting = false;
  
  Serial.println(WiFi.begin(ssid_wifi,password_wifi),DEC);
  
  while ( WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(300);
  }
 
  Serial.println("\nYou're connected to the network");
  Serial.println("Waiting for an ip address");
 
  while (WiFi.localIP() == INADDR_NONE) {
    Serial.print(".");
    delay(300);
  }
 
  Serial.println("\nIP Address obtained");
  printWifiStatus();
}
 
 
give me a feedback about your test.... 
 
Link to post
Share on other sites
My system , after some firmware upgrades, started to freeze... 

To resolve I formatted the flash with Uniflash and after I uploaded firmware with Energia IDE and everything work fine...

I think that the code in flash is not deleted right and after some upload start to create problems... 

Link to post
Share on other sites

Hey @@PaoloIT , it works great!

 

Just one note, since you're asking us to add

- "WiFi._initialized = false;"

"WiFi._connecting = false;"

before WiFi.begin(*char ssid, *char pass) every time inside the sketch, I went ahead and added the two lines into the "WiFi.begin(*char ssid, *char pass)" method inside the WiFi.cpp file instead of adding them in my sketch.

 

Everything seems to work fine with that too (I hope what I did doesn't mess things up).

 

To make sure nothing is broken, I tested it in the following way:

[AP--->UDP.begin()----->Station---->UDP.begin()----->AP...]  x 10    (ten times)

 

To be honest the CC3200 switched between networks faster than I could on my laptop :|

Anyway it seems to work fine :)

Thanks!

Link to post
Share on other sites

Hey @@PaoloIT , it works great!

 

Just one note, since you're asking us to add

- "WiFi._initialized = false;"

"WiFi._connecting = false;"

before WiFi.begin(*char ssid, *char pass) every time inside the sketch, I went ahead and added the two lines into the "WiFi.begin(*char ssid, *char pass)" method inside the WiFi.cpp file instead of adding them in my sketch.

 

Everything seems to work fine with that too (I hope what I did doesn't mess things up).

 

To make sure nothing is broken, I tested it in the following way:

[AP--->UDP.begin()----->Station---->UDP.begin()----->AP...]  x 10    (ten times)

 

To be honest the CC3200 switched between networks faster than I could on my laptop :|

Anyway it seems to work fine :)

Thanks!

 

Yes, is better put they on library...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...