Wifiservice
You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a station or hotspot, query the station or hotspot status, and listen for events.
Since:
1.0
Version:
1.0
Summary
Files
Data Structures
Macros
Indicates the maximum number of Wi-Fi station configurations that can be added using . |
|
WIFI_CONFIG_INVALID (-1) |
Indicates the value of networkId when the configuration file is unavailable. |
Indicates the maximum length of a Wi-Fi MAC address or a Wi-Fi BSSID. |
|
WIFI_PSK_LEN 32 |
|
Indicates the maximum number of event listeners that can be registered using RegisterWifiEvent. |
|
Defines the maximum number of stations connected to a hotspot. |
|
Indicates the maximum number of hotspots that can be detected in a Wi-Fi scan. |
Typedefs
typedef struct WifiDeviceConfig Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device. |
Enumerations
{ WIFI_SEC_TYPE_INVALID = -1, , WIFI_SEC_TYPE_WEP, , WIFI_SEC_TYPE_SAE } |
|
{ WIFI_PSK_TYPE_ASCII = 0, } |
|
WifiScanType { , WIFI_SSID_SCAN, , WIFI_BAND_SCAN } |
|
{ WIFI_SUCCESS = 0, = -1, ERROR_WIFI_CHIP_INVALID = -2, = -3, ERROR_WIFI_RTT_CONTROLLER_INVALID = -4, = -5, ERROR_WIFI_NOT_AVAILABLE = -6, = -7, ERROR_WIFI_BUSY = -8, = -9 } |
|
WifiEventState { = 0, WIFI_STATE_AVALIABLE } |
|
{ RSSI_LEVEL_1 = 1, = 2, RSSI_LEVEL_3 = 3, = 4 } |
Enumerates received signal strength indicator (RSSI) levels. |
HotspotBandType { = 1, HOTSPOT_BAND_TYPE_5G = 2 } |
Enumerates frequency bands supported by the Wi-Fi hotspot mode. |
{ WIFI_DISCONNECTED, } |
Functions
EnableWifi (void) |
|
DisableWifi (void) |
|
IsWifiActive (void) |
|
(WifiScanInfo result, unsigned int size) |
|
AddDeviceConfig (const config, int result) |
Adds a specified hotspot configuration for connecting to a hotspot. |
(WifiDeviceConfig result, unsigned int size) |
|
RemoveDevice (int networkId) |
Removes a hotspot configuration matching a specified networkId. |
ConnectTo (int networkId) |
|
Disconnect (void) |
|
GetLinkedInfo ( result) |
|
(WifiEvent event) |
|
UnRegisterWifiEvent (const event) |
Unregisters a callback previously registered for a specified Wi-Fi event. |
(WifiScanParams params) |
|
EnableHotspot (void) |
|
(const HotspotConfig config) |
|
GetHotspotConfig ( result) |
|
GetStationList ( result, unsigned int size) |
|
Obtains the signal level indicated by a specified received signal strength indicator (RSSI) and frequency band. |
|
SetBand (int band) |
|
GetBand (int result) |
Details
Macro Definition Documentation
WIFI_CONFIG_INVALID
Description:
Indicates the value of networkId when the configuration file is unavailable.
Generally, the configuration file is unavailable because the configuration matching the networkId is uninitialized.
WIFI_HOTSPOT_ACTIVE
Description:
Indicates that the Wi-Fi hotspot mode is enabled.
WIFI_HOTSPOT_NOT_ACTIVE
#define WIFI_HOTSPOT_NOT_ACTIVE 0
Description:
Indicates that the Wi-Fi hotspot mode is disabled.
WIFI_MAC_LEN
#define WIFI_MAC_LEN 6
Description:
Indicates the maximum length of a Wi-Fi MAC address or a Wi-Fi BSSID.
WIFI_MAX_CONFIG_SIZE
#define WIFI_MAX_CONFIG_SIZE 10
Description:
Indicates the maximum number of Wi-Fi station configurations that can be added using .
If the maximum number is reached, an error will be returned. In this case, you must delete at least one configuration before you can add new ones.
WIFI_MAX_EVENT_SIZE
#define WIFI_MAX_EVENT_SIZE 10
Description:
Indicates the maximum number of event listeners that can be registered using .
When the maximum number is reached, you need to unregister at least one listener before registering new ones.
WIFI_MAX_KEY_LEN
#define WIFI_MAX_KEY_LEN 65
Description:
Indicates the maximum length of a Wi-Fi key.
The maximum length is 64, and the last bit is reserved and set to \0.
WIFI_MAX_SSID_LEN
Description:
Indicates the maximum length of a Wi-Fi SSID.
The maximum length is 32, and the last bit is reserved and set to \0.
WIFI_PSK_LEN
#define WIFI_PSK_LEN 32
Description:
Indicates the maximum length of a Wi-Fi PSK.
#define WIFI_STA_ACTIVE 1
Description:
Indicates that the Wi-Fi station mode is enabled.
WIFI_STA_NOT_ACTIVE
#define WIFI_STA_NOT_ACTIVE 0
Description:
Indicates that the Wi-Fi station mode is disabled.
Typedef Documentation
WifiDeviceConfig
typedef struct [WifiDeviceConfig]($api-api-LinkIoT-WifiDeviceConfig.md) [WifiDeviceConfig]($api-api-LinkIoT-WifiDeviceConfig.md)
Description:
Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.
Enumeration Type Documentation
HotspotBandType
enum [HotspotBandType]($api-api-LinkIoT-Wifiservice.md#ga37e10532da87571ee89193beac42d246)
Description:
Enumerates frequency bands supported by the Wi-Fi hotspot mode.
HOTSPOT_BAND_TYPE_2G | |
HOTSPOT_BAND_TYPE_5G |
RssiLevel
enum [RssiLevel]($api-api-LinkIoT-Wifiservice.md#gadb1b12fe6311711103e759aac7a470d4)
Description:
Enumerates received signal strength indicator (RSSI) levels.
Four RSSI levels are available: 1 to 4. The higher the RSSI level, the stronger the Wi-Fi signal.
WifiConnState
Description:
Enumerates Wi-Fi connection states.
WIFI_DISCONNECTED | |
WIFI_CONNECTED |
WifiErrorCode
Description:
Enumerates Wi-Fi error codes.
WifiEventState
enum [WifiEventState]($api-api-LinkIoT-Wifiservice.md#ga6be99f93ce0d2d222c1f5f0a8217354d)
Description:
Enumerates states in Wi-Fi events.
WifiPskType
enum [WifiPskType]($api-api-LinkIoT-Wifiservice.md#gaa1a44d23b8478232f14d2adfc82cee77)
Description:
Enumerates psk encryption types.
WIFI_PSK_TYPE_ASCII | |
WIFI_PSK_TYPE_HEX |
WifiScanType
enum [WifiScanType]($api-api-LinkIoT-Wifiservice.md#ga007bf5e22727debc02cad860e41a60a3)
Description:
Enumerates Wi-Fi scan types.
WIFI_FREQ_SCAN | |
WIFI_SSID_SCAN | |
WIFI_BSSID_SCAN | |
WIFI_BAND_SCAN |
WifiSecurityType
enum [WifiSecurityType]($api-api-LinkIoT-Wifiservice.md#ga97c133f7db7c1234babcde03c4ce1b05)
Description:
Enumerates Wi-Fi security types.
WIFI_SEC_TYPE_INVALID | |
WIFI_SEC_TYPE_OPEN | |
WIFI_SEC_TYPE_WEP | |
WIFI_SEC_TYPE_PSK | |
WIFI_SEC_TYPE_SAE |
Function Documentation
AddDeviceConfig()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) AddDeviceConfig (const [WifiDeviceConfig]($api-api-LinkIoT-WifiDeviceConfig.md) * config, int * result )
Description:
Adds a specified hotspot configuration for connecting to a hotspot.
This function generates a networkId.
Parameters:
config | Indicates the hotspot configuration to add. |
result | Indicates the generated networkId. Each networkId matches a hotspot configuration. |
Returns:
Returns WIFI_SUCCESS if the specified hotspot configuration is added; returns an error code defined in otherwise.
AdvanceScan()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) AdvanceScan ([WifiScanParams]($api-api-LinkIoT-WifiScanParams.md) * params)
Description:
Starts a Wi-Fi scan based on a specified parameter.
Only results matching the specified parameter will be returned for the Wi-Fi scan.
Parameters:
params | Indicates the pointer to the parameter for starting the Wi-Fi scan. For details, see WifiScanParams. |
Returns:
Returns if the Wi-Fi scan is started successfully; returns an error code defined in WifiErrorCode otherwise.
ConnectTo()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) ConnectTo (int networkId)
Description:
Connects to a hotspot matching a specified networkId.
Before calling this function, call AddDeviceConfig to add a hotspot configuration.
Parameters:
networkId | Indicates the networkId matching the target hotspot. |
Returns:
Returns if the hotspot is connected; returns an error code defined in WifiErrorCode otherwise.
DisableHotspot()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) DisableHotspot (void )
Description:
Disables the hotspot mode.
Returns:
Returns WIFI_SUCCESS if the hotspot mode is disabled; returns an error code defined in otherwise.
DisableWifi()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) DisableWifi (void )
Description:
Disables the station mode.
Returns:
Returns if the station mode is disabled; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) Disconnect (void )
Description:
Disconnects this Wi-Fi connection.
Returns:
Returns if this Wi-Fi connection is disconnected; returns an error code defined in WifiErrorCode otherwise.
EnableHotspot()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) EnableHotspot (void )
Description:
Enables the hotspot mode.
Before using this function, you need to invoke SetHotspotConfig and set at least the SSID, security type, and key.
Returns:
Returns if the hotspot mode is enabled; returns an error code defined in WifiErrorCode otherwise.
EnableWifi()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) EnableWifi (void )
Description:
Enables the station mode.
Returns:
Returns WIFI_SUCCESS if the station mode is enabled; returns an error code defined in otherwise.
GetBand()
Description:
Obtains the frequency band of this hotspot.
Parameters:
result | Indicates the obtained frequency band. |
Returns:
Returns WIFI_SUCCESS if the frequency band is obtained; returns an error code defined in otherwise.
GetDeviceConfigs()
Description:
Obtains all hotspot configurations.
Hotspot configurations were added using .
Parameters:
result | Indicates the array of all hotspot configurations. The array is requested and released by the caller. The value must be greater than or equal to . |
size | Indicates the size of the array. |
Returns:
Returns WIFI_SUCCESS if all hotspot configurations are obtained; returns an error code defined in otherwise.
GetDeviceMacAddress()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetDeviceMacAddress (unsigned char * result)
Description:
Obtains the MAC address of this device.
Parameters:
result | Indicates the MAC address of this device. It is a char array whose length is 6. |
Returns:
Returns WIFI_SUCCESS if the MAC address of this device is obtained; returns an error code defined in otherwise.
GetHotspotConfig()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetHotspotConfig ([HotspotConfig]($api-api-LinkIoT-HotspotConfig.md) * result)
Description:
Obtains a specified hotspot configuration.
The hotspot configuration includes the SSID, security type, and key.
Parameters:
Returns:
Returns WIFI_SUCCESS if the hotspot configuration is obtained; returns an error code defined in otherwise.
GetLinkedInfo()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetLinkedInfo ([WifiLinkedInfo]($api-api-LinkIoT-WifiLinkedInfo.md) * result)
Description:
Obtains information about the connected hotspot.
Parameters:
result | Indicates the information about the connected hotspot. |
Returns:
Returns WIFI_SUCCESS if the information about the connected hotspot is obtained; returns an error code defined in otherwise.
GetScanInfoList()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetScanInfoList ([WifiScanInfo]($api-api-LinkIoT-WifiScanInfo.md) * result, unsigned int * size )
Description:
Obtains an array of hotspots detected in a Wi-Fi scan.
The array of hotspots can be obtained only after the Wi-Fi scan is complete.
Parameters:
result | Indicates the array of hotspots detected in a Wi-Fi scan. The array is requested and released by the caller. The value must be greater than or equal to WIFI_SCAN_HOTSPOT_LIMIT. |
size | Indicates the size of the array. |
Returns:
Returns if the array of hotspots detected in the Wi-Fi scan is obtained; returns an error code defined in WifiErrorCode otherwise.
GetSignalLevel()
int GetSignalLevel (int rssi, int band )
Description:
Obtains the signal level indicated by a specified received signal strength indicator (RSSI) and frequency band.
Based on the signal level, you can display the signal strength represented by the number of signal bars.
Parameters:
rssi | Indicates the RSSI. |
band | Indicates the frequency band, either or HOTSPOT_BAND_TYPE_2G. |
Returns:
Returns the signal level if it is obtained; returns -1 otherwise.
GetStationList()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetStationList ([StationInfo]($api-api-LinkIoT-StationInfo.md) * result, unsigned int * size )
Description:
Obtains an array of stations connected to this hotspot.
The station information is defined in StationInfo.
Parameters:
result | Indicates the array of stations connected to this hotspot. The array is requested and released by the caller. The value must be greater than or equal to WIFI_MAX_STA_NUM. |
size | Indicates the size of the array. |
Returns:
Returns if the array of stations connected to this hotspot is obtained; returns an error code defined in WifiErrorCode otherwise.
IsHotspotActive()
int IsHotspotActive (void )
Description:
Checks whether the hotspot mode is enabled.
Returns:
Returns WIFI_HOTSPOT_ACTIVE if the hotspot mode is enabled; returns otherwise.
IsWifiActive()
int IsWifiActive (void )
Description:
Checks whether the station mode is enabled.
Returns:
Returns if the station mode is enabled; returns WIFI_STA_NOT_ACTIVE otherwise.
RegisterWifiEvent()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) RegisterWifiEvent ([WifiEvent]($api-api-LinkIoT-WifiEvent.md) * event)
Description:
Registers a callback for a specified Wi-Fi event.
The registered callback will be invoked when the Wi-Fi event defined in WifiEvent occurs.
Parameters:
event | Indicates the event for which the callback is to be registered. |
Returns:
Returns WIFI_SUCCESS if the callback is registered successfully; returns an error code defined in otherwise.
RemoveDevice()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) RemoveDevice (int networkId)
Description:
Removes a hotspot configuration matching a specified networkId.
Parameters:
networkId | Indicates the networkId matching the hotspot configuration to remove. |
Returns:
Returns WIFI_SUCCESS if the hotspot configuration is removed; returns an error code defined in otherwise.
Scan()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) Scan (void )
Description:
Starts a Wi-Fi scan.
Returns:
Returns if the Wi-Fi scan is started; returns an error code defined in WifiErrorCode otherwise.
SetBand()
Description:
Sets the frequency band for this hotspot.
Parameters:
band | Indicates the frequency band to set. |
Returns:
Returns if the frequency band is set; returns an error code defined in WifiErrorCode otherwise.
SetHotspotConfig()
Description:
Sets a specified hotspot configuration.
The hotspot configuration includes the SSID, security type, and key. The configuration set overwrites the existing configuration and takes effect after the hotspot mode is re-enabled. Before enabling the hotspot mode for the first time, you must call this function.
Parameters:
config | Indicates the hotspot configuration to set. |
Returns:
Returns if the hotspot configuration is set; returns an error code defined in WifiErrorCode otherwise.
UnRegisterWifiEvent()
Description:
Unregisters a callback previously registered for a specified Wi-Fi event.
Parameters:
event | Indicates the event for which the callback is to be unregistered. |
Returns:
Returns if the callback is unregistered successfully; returns an error code defined in WifiErrorCode otherwise.