Icion 0 Posted January 2, 2015 Share Posted January 2, 2015 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 Quote Link to post Share on other sites
Zeyber 0 Posted January 13, 2015 Share Posted January 13, 2015 I am also facing this problem. Quote Link to post Share on other sites
spirilis 1,265 Posted January 14, 2015 Share Posted January 14, 2015 Can you guys try using- WiFi.disconnect() before running WiFi.begin(...) in your examples? Does that work? Quote Link to post Share on other sites
Zeyber 0 Posted January 14, 2015 Share Posted January 14, 2015 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"); } Quote Link to post Share on other sites
PaoloIT 2 Posted January 18, 2015 Share Posted January 18, 2015 Hello, I've the same problem. If I start in STA mode all work fine, with start AP and after STA mode nothing to do.... Quote Link to post Share on other sites
PaoloIT 2 Posted January 19, 2015 Share Posted January 19, 2015 SOLVED!!! As soon as I will post the solution. The problem is in the library Quote Link to post Share on other sites
Zeyber 0 Posted January 19, 2015 Share Posted January 19, 2015 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. Quote Link to post Share on other sites
spirilis 1,265 Posted January 19, 2015 Share Posted January 19, 2015 Yes please post your fixes and example code... I'll test them this week and propose a pull request for Energia. Sent from my Galaxy Note II with Tapatalk 4 Quote Link to post Share on other sites
Zeyber 0 Posted January 19, 2015 Share Posted January 19, 2015 I seem to have a shakey begin() method now. Sometimes it works (will connect to ap) and others it just seems to freeze. Quote Link to post Share on other sites
PaoloIT 2 Posted January 20, 2015 Share Posted January 20, 2015 Hello, Sorry for delay. I'll post this night (night in italy!). Quote Link to post Share on other sites
PaoloIT 2 Posted January 20, 2015 Share Posted January 20, 2015 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.... Quote Link to post Share on other sites
Zeyber 0 Posted January 22, 2015 Share Posted January 22, 2015 Its... working. Quote Link to post Share on other sites
PaoloIT 2 Posted January 22, 2015 Share Posted January 22, 2015 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... Quote Link to post Share on other sites
nitred 2 Posted January 22, 2015 Share Posted January 22, 2015 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! Quote Link to post Share on other sites
PaoloIT 2 Posted January 22, 2015 Share Posted January 22, 2015 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... Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.