Jump to content
dmalawey

Problem reconnecting to Wifi on CC3100 with Launchpad MSP430F5529

Recommended Posts

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 network
Waiting for an ip address
...............
IP Address obtained
SSID: MXET
IP Address: 192.168.137.93
signal strength (RSSI):-58 dBm
Waiting... 9999
Waiting... 8997
Waiting... 7997
Waiting... 6996
Waiting... 5996
Waiting... 4995
Waiting... 3994
Waiting... 2994
Waiting... 1993
Waiting... 992
Disconnecting from WiFi....Disconnected
Waiting... 9426
Waiting... 8424
Waiting... 7424
Waiting... 6423
Waiting... 5422
Waiting... 4422
Waiting... 3421
Waiting... 2421
Waiting... 1420
Waiting... 419
Attempting to connect to Network named: MXET
............................................................

reconnectWiFi.ino

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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");
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×