dmalawey 0 Posted May 17, 2018 Share Posted May 17, 2018 I am unable to reconnect to my WPA wifi access point after disconnecting. Using the code posted in the link: Problem in Reconnecting with CC3200 I was able to successfully run the code with a Launchpad CC3200 device I was NOT able to run the code with a Launchpad MSP430F5529 and CC3100 Boosterpack When I use this setup, I connect the first time, disconnect, and fail to reconnect. My serial screen outputs the following: Attempting to connect to Network named: MXET ..........................................You're connected to the networkWaiting for an ip address...............IP Address obtainedSSID: MXETIP Address: 192.168.137.93signal strength (RSSI):-58 dBmWaiting... 9999Waiting... 8997Waiting... 7997Waiting... 6996Waiting... 5996Waiting... 4995Waiting... 3994Waiting... 2994Waiting... 1993Waiting... 992Disconnecting from WiFi....DisconnectedWaiting... 9426Waiting... 8424Waiting... 7424Waiting... 6423Waiting... 5422Waiting... 4422Waiting... 3421Waiting... 2421Waiting... 1420Waiting... 419Attempting to connect to Network named: MXET............................................................ reconnectWiFi.ino Quote Link to post Share on other sites
zeke 693 Posted May 17, 2018 Share Posted May 17, 2018 @dmalawey If you are using the code from the link you provided then I bet you haven't setup the wifi credentials properly. This is a snippet from that code: Quote // your network name also called SSID char ssid[] = "energia1"; // your network password char password[] = "launchpad"; Is your wifi router called "energia1"? Is its password "launchpad"? Check those two details first and then try again. Quote Link to post Share on other sites
dmalawey 0 Posted May 17, 2018 Author Share Posted May 17, 2018 Yes my code reflects the true WiFi credentials. As I said, the code works 100% on my cc3200 launchpad, and logon works the FIRST time on the CC3100. My only issue is upon reconnect with CC3100. Quote Link to post Share on other sites
energia 485 Posted May 17, 2018 Share Posted May 17, 2018 For some reason the stored profile get's deleted and hence it won't reconnect since there is nothing stored to connect to. I have not looked at it in detail. Below is a Sketch with a small work-around: #include <WiFi.h> // your network name also called SSID char ssid[] = "energia"; // your network password char password[] = "launchpad"; // Connect / Disconnect every 10 sec; #define CONNECTION_INTERVAL_MS 3000 uint32_t lastConnected = 0; void setup() { Serial.begin(115200); // WiFi.init(); initialConnection(); lastConnected = millis(); } void loop() { Serial.print("Waiting... "); Serial.println(CONNECTION_INTERVAL_MS - (millis() - lastConnected)); delay(1000); if (millis() - lastConnected > CONNECTION_INTERVAL_MS) { lastConnected = millis(); if (WiFi.status() == WL_CONNECTED) { disconnectFromWiFi(); } else { connectToWiFi(); } } } void initialConnection() { // attempt to connect to Wifi network: Serial.print("Attempting to connect to Network named: "); // print the network name (SSID); Serial.println(ssid); // Connect to WPA/WPA2 network. WiFi.begin(ssid, password); 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); } printWifiStatus(); } void connectToWiFi() { sl_Start(0, 0, 0); delay(100); sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1, 1, 0, 0, 0), 0, 0); int NameLen = strlen(ssid); SlSecParams_t SecParams = {0}; SecParams.Type = SL_SEC_TYPE_WPA; SecParams.Key = (signed char *)password; SecParams.KeyLen = strlen(password); int iRet = sl_WlanConnect((signed char *)ssid, NameLen, NULL, &SecParams, NULL); // attempt to connect to Wifi network: Serial.print("Attempting to connect to Network named: "); // print the network name (SSID); Serial.println(ssid); // Connect to WPA/WPA2 network. // WiFi.begin(ssid, password); 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"); // We are connected and have an IP address. // Print the WiFi status. printWifiStatus(); } // ---------------------------- void disconnectFromWiFi() { Serial.print("Disconnecting from WiFi...."); sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(0, 0, 0, 0, 0), 0, 0); delay(500); sl_WlanDisconnect(); while (WiFi.status() == WL_CONNECTED) { Serial.print("."); delay(300); } sl_Stop(0); Serial.println("Disconnected"); } // ---------------------------- void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); } Quote Link to post Share on other sites
dmalawey 0 Posted May 18, 2018 Author Share Posted May 18, 2018 That works! Thank you. So the secret is this sl_WlanConnect function? This wiki says that the function "connects to a wlan network as a station." What is a station? 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.