- Wifiservice
- Overview
- Summary
- Files
- Data Structures
- Macros
- Typedefs
- Enumerations
- Functions
- Details
- Macro Definition Documentation
- WIFI_CONFIG_INVALID
- WIFI_HOTSPOT_ACTIVE
- WIFI_HOTSPOT_NOT_ACTIVE
- WIFI_MAC_LEN
- WIFI_MAX_CONFIG_SIZE
- WIFI_MAX_EVENT_SIZE
- WIFI_MAX_KEY_LEN
- WIFI_MAX_SSID_LEN
- WIFI_PSK_LEN
- WIFI_STA_ACTIVE
- WIFI_STA_NOT_ACTIVE
- Typedef Documentation
- WifiDeviceConfig
- Enumeration Type Documentation
- HotspotBandType
- RssiLevel
- WifiConnState
- WifiErrorCode
- WifiEventState
- WifiPskType
- WifiScanType
- WifiSecurityType
- Function Documentation
- AddDeviceConfig()
- AdvanceScan()
- ConnectTo()
- DisableHotspot()
- DisableWifi()
- Disconnect()
- EnableHotspot()
- EnableWifi()
- GetBand()
- GetDeviceConfigs()
- GetDeviceMacAddress()
- GetHotspotConfig()
- GetLinkedInfo()
- GetScanInfoList()
- GetSignalLevel()
- GetStationList()
- IsHotspotActive()
- IsWifiActive()
- RegisterWifiEvent()
- RemoveDevice()
- Scan()
- SetBand()
- SetHotspotConfig()
- UnRegisterWifiEvent()
Wifiservice
Overview
Provides functions for the Wi-Fi station and hotspot modes.
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 AddDeviceConfig. |
|
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
WifiSecurityType { WIFI_SEC_TYPE_INVALID = -1, WIFI_SEC_TYPE_OPEN, WIFI_SEC_TYPE_WEP, WIFI_SEC_TYPE_PSK, WIFI_SEC_TYPE_SAE } |
|
WifiScanType { WIFI_FREQ_SCAN, WIFI_SSID_SCAN, WIFI_BSSID_SCAN, WIFI_BAND_SCAN } |
|
WifiErrorCode { WIFI_SUCCESS = 0, ERROR_WIFI_INVALID_ARGS = -1, ERROR_WIFI_CHIP_INVALID = -2, ERROR_WIFI_IFACE_INVALID = -3, ERROR_WIFI_RTT_CONTROLLER_INVALID = -4, ERROR_WIFI_NOT_SUPPORTED = -5, ERROR_WIFI_NOT_AVAILABLE = -6, ERROR_WIFI_NOT_STARTED = -7, ERROR_WIFI_BUSY = -8, ERROR_WIFI_UNKNOWN = -9 } |
|
WifiEventState { WIFI_STATE_NOT_AVALIABLE = 0, WIFI_STATE_AVALIABLE } |
|
RssiLevel { RSSI_LEVEL_1 = 1, RSSI_LEVEL_2 = 2, RSSI_LEVEL_3 = 3, RSSI_LEVEL_4 = 4 } |
Enumerates received signal strength indicator (RSSI) levels. |
HotspotBandType { HOTSPOT_BAND_TYPE_2G = 1, HOTSPOT_BAND_TYPE_5G = 2 } |
Enumerates frequency bands supported by the Wi-Fi hotspot mode. |
Functions
EnableWifi (void) |
|
DisableWifi (void) |
|
IsWifiActive (void) |
|
Scan (void) |
|
GetScanInfoList (WifiScanInfo result, unsigned int size) |
|
AddDeviceConfig (const WifiDeviceConfig config, int result) |
Adds a specified hotspot configuration for connecting to a hotspot. |
GetDeviceConfigs (WifiDeviceConfig result, unsigned int size) |
|
RemoveDevice (int networkId) |
Removes a hotspot configuration matching a specified networkId. |
ConnectTo (int networkId) |
|
Disconnect (void) |
|
GetLinkedInfo (WifiLinkedInfo result) |
|
RegisterWifiEvent (WifiEvent event) |
|
UnRegisterWifiEvent (const WifiEvent event) |
Unregisters a callback previously registered for a specified Wi-Fi event. |
GetDeviceMacAddress (unsigned char result) |
|
AdvanceScan (WifiScanParams params) |
|
EnableHotspot (void) |
|
DisableHotspot (void) |
|
SetHotspotConfig (const HotspotConfig config) |
|
GetHotspotConfig (HotspotConfig result) |
|
IsHotspotActive (void) |
|
GetStationList (StationInfo result, unsigned int size) |
|
GetSignalLevel (int rssi, int band) |
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
#define WIFI_CONFIG_INVALID (-1)
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
#define WIFI_HOTSPOT_ACTIVE 1
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 AddDeviceConfig.
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 RegisterWifiEvent.
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
#define WIFI_MAX_SSID_LEN 33
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.
WIFI_STA_ACTIVE
#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
enum [WifiConnState]($api-api-LinkIoT-Wifiservice.md#ga970b7d5373775b1c7f3b31074bae50e1)
Description:
Enumerates Wi-Fi connection states.
WIFI_DISCONNECTED | |
WIFI_CONNECTED |
WifiErrorCode
enum [WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568)
Description:
Enumerates Wi-Fi error codes.
WifiEventState
enum [WifiEventState]($api-api-LinkIoT-Wifiservice.md#ga6be99f93ce0d2d222c1f5f0a8217354d)
Description:
Enumerates states in Wi-Fi events.
WIFI_STATE_NOT_AVALIABLE | |
WIFI_STATE_AVALIABLE |
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 WifiErrorCode 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 WIFI_SUCCESS 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 WIFI_SUCCESS 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 WifiErrorCode otherwise.
DisableWifi()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) DisableWifi (void )
Description:
Disables the station mode.
Returns:
Returns WIFI_SUCCESS if the station mode is disabled; returns an error code defined in WifiErrorCode otherwise.
Disconnect()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) Disconnect (void )
Description:
Disconnects this Wi-Fi connection.
Returns:
Returns WIFI_SUCCESS 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 WIFI_SUCCESS 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 WifiErrorCode otherwise.
GetBand()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetBand (int * result)
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 WifiErrorCode otherwise.
GetDeviceConfigs()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetDeviceConfigs ([WifiDeviceConfig]($api-api-LinkIoT-WifiDeviceConfig.md) * result, unsigned int * size )
Description:
Obtains all hotspot configurations.
Hotspot configurations were added using AddDeviceConfig.
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 WIFI_MAX_CONFIG_SIZE. |
size | Indicates the size of the array. |
Returns:
Returns WIFI_SUCCESS if all hotspot configurations are obtained; returns an error code defined in WifiErrorCode 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 WifiErrorCode 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:
result | Indicates the obtained hotspot configuration. |
Returns:
Returns WIFI_SUCCESS if the hotspot configuration is obtained; returns an error code defined in WifiErrorCode 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 WifiErrorCode 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 WIFI_SUCCESS 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 HOTSPOT_BAND_TYPE_5G 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 WIFI_SUCCESS 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 WIFI_HOTSPOT_NOT_ACTIVE otherwise.
IsWifiActive()
int IsWifiActive (void )
Description:
Checks whether the station mode is enabled.
Returns:
Returns WIFI_STA_ACTIVE 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 WifiErrorCode 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 WifiErrorCode otherwise.
Scan()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) Scan (void )
Description:
Starts a Wi-Fi scan.
Returns:
Returns WIFI_SUCCESS if the Wi-Fi scan is started; returns an error code defined in WifiErrorCode otherwise.
SetBand()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) SetBand (int band)
Description:
Sets the frequency band for this hotspot.
Parameters:
band | Indicates the frequency band to set. |
Returns:
Returns WIFI_SUCCESS if the frequency band is set; returns an error code defined in WifiErrorCode otherwise.
SetHotspotConfig()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) SetHotspotConfig (const [HotspotConfig]($api-api-LinkIoT-HotspotConfig.md) * config)
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 WIFI_SUCCESS if the hotspot configuration is set; returns an error code defined in WifiErrorCode otherwise.
UnRegisterWifiEvent()
[WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) UnRegisterWifiEvent (const [WifiEvent]($api-api-LinkIoT-WifiEvent.md) * event)
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 WIFI_SUCCESS if the callback is unregistered successfully; returns an error code defined in WifiErrorCode otherwise.