IWifi¶
- class
Interface for Wifi setup methods.
Subclasses that implement this interface will control Wifi hardware and encapsulate connection processes inside this convenient interface.
You need only to call the connect method and wait the connected callback event.
The implementation of this interface must take care of associating with a Wifi Access Point and getting an dynamic IP address from AP’s DHCP.
Sleep mode
When mono enters sleep, the wifi will loose power. Upon wake-up this interface will notify you with a disconnected callback.
Example
You should have only one IWifi based object in your application. Therefore add it as a member of your AppController class:
class AppController : public mono::IApplication { public: mono::io::Wifi wifi; }
Then, when you need network access the first time, just call:
AppController::monoWakeFromReset() { bool connecting = wifi.connect(); if (!connecting) printf("Error, can not connect"); }
Public Types
-
enum type
mono::io::IWifi::
NetworkEvents
¶ The Wifi connection status event types.
Values:
When Wifi is connected and ready
Wifi failed to connect to access point
Wifi was disconnected
Public Functions
-
virtual bool
mono::io::IWifi::
connect
()¶
= 0 Connect to the Wifi network.
Use the parameters provided in the constructor to connect to the configured access point. This method will also obtain an IP address from the AP’s DHCP server.
You can all this method multiple times, even if you are already connected. The method will simply ignore attempt to connect, when already connected.
- Return
true
is configuration is valid and Wifi hardware is OK.
-
virtual bool
mono::io::IWifi::
isConnected
()¶
const = 0 Return
true
Wifi is connected.This will return
true
only if a connection is currently present. This means it will returnfalse
even if the Wifi hardware is currently in process of connecting to an access point or obtaining an IP address.
-
void
mono::io::IWifi::
setConnectedCallback
(void (*cfunc)(void))¶ Set a callback for the connected event.
Set a callback function to get notified when network access is established.
- Parameters
cfunc
-A pointer to the C function that handles the event
- template <typename Context>
-
void mono::io::IWifi::setConnectedCallback(Context * cnxt, void(Context::*)(void) memptr)
Set a callback for the connected event.
Set a callback function to get notified when network access is established.
- Parameters
cnxt
-A pointer to the object that handles the event
memptr
-A pointer to the method on the class that handles the event
-
void
mono::io::IWifi::
setConnectErrorCallback
(void (*cfunc)(void))¶ Set a callback for the connect failed event.
Set a callback function to get notified when network access could not be established, and the Wifi hardware has given up.
- Parameters
cfunc
-A pointer to the C function that handles the event
- template <typename Context>
-
void mono::io::IWifi::setConnectErrorCallback(Context * cnxt, void(Context::*)(void) memptr)
Set a callback for the connect failed event.
Set a callback function to get notified when network access could not be established, and the Wifi hardware has given up.
- Parameters
cnxt
-A pointer to the object that handles the event
memptr
-A pointer to the method on the class that handles the event
- template <typename Context>
-
void mono::io::IWifi::setDisconnectedCallback(Context * cnxt, void(Context::*)(void) memptr)
Set a callback for the disconnected event.
Set a callback function to get notified when network access is terminated.
this event will always fire after mono comes out of sleep, if network was established when it went to sleep.
- Parameters
cnxt
-A pointer to the object that handles the event
memptr
-A pointer to the method on the class that handles the event
-
void
mono::io::IWifi::
setDisconnectedCallback
(void (*cfunc)(void))¶ Set a callback for the disconnected event.
Set a callback function to get notified when network access is terminated.
this event will always fire after mono comes out of sleep, if network was established when it went to sleep.
- Parameters
cfunc
-A pointer to the C function that handles the event
-
void
mono::io::IWifi::
setEventCallback
(void (*cfunc)(NetworkEvents))¶ Set a callback for the all events.
Set a callback function to get notified when network access state is changed.
- Parameters
cfunc
-A pointer to the C function that handles the event
- template <typename Context>
-
void mono::io::IWifi::setEventCallback(Context * cnxt, void(Context::*)( NetworkEvents ) memptr)
Set a callback for the all events.
Set a callback function to get notified when network access state is changed.
- Parameters
cnxt
-A pointer to the object that handles the event
memptr
-A pointer to the method on the class that handles the event
-
enum type