Jump to content
43oh

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

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.

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

 

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