Skip to content

Commit

Permalink
WifiStation.waitConnection is marked as obsolete and will be removed …
Browse files Browse the repository at this point in the history
…in coming versions. (#1071)

Use WifiEvents instead.
The Basic_Wifi example is changed and should be used as a starting point for the migration of your own code.
  • Loading branch information
slaff committed Apr 11, 2017
1 parent d6f29cc commit a963639
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Sming/SmingCore/Platform/Station.h
Expand Up @@ -219,6 +219,10 @@ class StationClass : protected ISystemReadyHandler
* @param successfulConnected Function to call when WiFi station connects to network
* @param secondsTimeOut Quantity of seconds to wait for connection
* @param connectionNotEstablished Function to call if WiFi station fails to connect to network
*
* @deprecated This method is deprecated and will be removed in the next versions. Use WifiEvents instead.
* For an example of WifiEvents take a look at the Basic_Wifi sample code.
*
*/
void waitConnection(ConnectionDelegate successfulConnected, int secondsTimeOut, ConnectionDelegate connectionNotEstablished);

Expand Down
19 changes: 11 additions & 8 deletions samples/Basic_WiFi/app/application.cpp
Expand Up @@ -28,17 +28,17 @@ void listNetworks(bool succeeded, BssList list)
}

// Will be called when WiFi station was connected to AP
void connectOk()
void connectOk(IPAddress ip, IPAddress mask, IPAddress gateway)
{
debugf("I'm CONNECTED");
Serial.println(WifiStation.getIP().toString());
Serial.println(ip.toString());
}

// Will be called when WiFi station timeout was reached
void connectFail()
// Will be called when WiFi station was disconnected
void connectFail(String ssid, uint8_t ssidLength, uint8_t *bssid, uint8_t reason)
{
debugf("I'm NOT CONNECTED!");
WifiStation.waitConnection(connectOk, 10, connectFail); // Repeat and check again
// The different reason codes can be found in user_interface.h. in your SDK.
debugf("Disconnected from %s. Reason: %d", ssid.c_str(), reason);
}

// Will be called when WiFi hardware and software initialization was finished
Expand Down Expand Up @@ -76,6 +76,9 @@ void init()
// Print available access points
WifiStation.startScan(listNetworks); // In Sming we can start network scan from init method without additional code

// Run our method when station was connected to AP (or not connected)
WifiStation.waitConnection(connectOk, 30, connectFail); // We recommend 20+ seconds at start
// Set callback that should be triggered when we have assigned IP
WifiEvents.onStationGotIP(connectOk);

// Set callback that should be triggered if we are disconnected or connection attempt failed
WifiEvents.onStationDisconnect(connectFail);
}

0 comments on commit a963639

Please sign in to comment.