Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call m2m_wifi_handle_events from WiFiClass::status() #45

Merged

Conversation

sandeepmistry
Copy link
Contributor

For sketches that want to check the WiFi status and re-connect if
disconnected.

Example:

#include <WiFi101.h>

char ssid[] = "yourNetwork";     //  your network SSID (name)
char pass[] = "password";  // your network password

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
}

void loop() {
  if (WiFi.status() != WL_CONNECTED) {
    Serial.print("WiFi not connected, attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    if (WiFi.begin(ssid, pass) == WL_CONNECTED) {
      Serial.println("You're connected to the network");
    } else {
      Serial.println("Network connection failed");
    }
  }

  delay(5000);
}

Without this change WiFi.status() will always return WL_CONNECTED once connected, even if access point is disconnected later.

For sketches that want to check the WiFi status and re-connect if
disconnected.
@agdl
Copy link
Member

agdl commented Mar 16, 2016

This is great to be put in an RTC based standby interrupts. Users are asking for MKR1000 to switch wifi off with an end method. This example will be great to do it since you will need to reconnect after the end method

agdl added a commit that referenced this pull request Mar 16, 2016
Call m2m_wifi_handle_events from WiFiClass::status()
@agdl agdl merged commit 691b991 into arduino-libraries:master Mar 16, 2016
@sandeepmistry sandeepmistry deleted the status-call-handle-events branch July 11, 2016 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants