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

File Name

Description

station_info.h

Defines the structure and macro of the station information contained in the event information.

wifi_device.h

Provides capabilities to enable and disable the station mode, connect to and disconnect from a station, query the station status, and listen for events.

wifi_device_config.h

Defines the Wi-Fi station configuration.

wifi_error_code.h

Defines error codes of the Wi-Fi service.

wifi_event.h

Defines callbacks and structure of Wi-Fi events.

wifi_hotspot.h

Provides capabilities to enable and disable the hotspot mode, connect to and disconnect from a hotspot, query the hotspot status, and listen for events.

wifi_hotspot_config.h

Defines the Wi-Fi hotspot configuration.

wifi_linked_info.h

Defines the data structure and macro of the Wi-Fi connection information.

wifi_scan_info.h

Defines the data structure and macro of the Wi-Fi scan result information.

Data Structures

Data Structure Name

Description

StationInfo

Represents the station information.

WifiDeviceConfig

Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.

WifiScanParams

Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.

WifiEvent

Represents the pointer to a Wi-Fi event callback for station and hotspot connection, disconnection, or scan.

HotspotConfig

Represents the hotspot configuration.

WifiLinkedInfo

Represents the Wi-Fi connection information.

WifiScanInfo

Represents the Wi-Fi scan result information.

Macros

Macro Name and Value

Description

WIFI_MAX_CONFIG_SIZE   10

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.

WIFI_MAX_SSID_LEN   33

Indicates the maximum length of a Wi-Fi SSID.

WIFI_MAX_KEY_LEN   65

Indicates the maximum length of a Wi-Fi key.

WIFI_MAC_LEN   6

Indicates the maximum length of a Wi-Fi MAC address or a Wi-Fi BSSID.

WIFI_PSK_LEN   32

Indicates the maximum length of a Wi-Fi PSK.

WIFI_STA_ACTIVE   1

Indicates that the Wi-Fi station mode is enabled.

WIFI_STA_NOT_ACTIVE   0

Indicates that the Wi-Fi station mode is disabled.

WIFI_HOTSPOT_ACTIVE   1

Indicates that the Wi-Fi hotspot mode is enabled.

WIFI_HOTSPOT_NOT_ACTIVE   0

Indicates that the Wi-Fi hotspot mode is disabled.

WIFI_MAX_EVENT_SIZE   10

Indicates the maximum number of event listeners that can be registered using RegisterWifiEvent.

HOTSPOT_DEFAULT_CHANNEL    6

Defines the default channel of the hotspot mode.

WIFI_MAX_STA_NUM    6

Defines the maximum number of stations connected to a hotspot.

WIFI_SCAN_HOTSPOT_LIMIT    64

Indicates the maximum number of hotspots that can be detected in a Wi-Fi scan.

Typedefs

Typedef Name

Description

WifiDeviceConfig

typedef struct WifiDeviceConfig 

Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.

Enumerations

Enumeration Name

Description

WifiSecurityType {   WIFI_SEC_TYPE_INVALID = -1, WIFI_SEC_TYPE_OPEN, WIFI_SEC_TYPE_WEP, WIFI_SEC_TYPE_PSK,   WIFI_SEC_TYPE_SAE }

Enumerates Wi-Fi security types.

WifiPskType { WIFI_PSK_TYPE_ASCII = 0, WIFI_PSK_TYPE_HEX }

Enumerates psk encryption types.

WifiScanType { WIFI_FREQ_SCAN, WIFI_SSID_SCAN, WIFI_BSSID_SCAN, WIFI_BAND_SCAN }

Enumerates Wi-Fi scan types.

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 }

Enumerates Wi-Fi error codes.

WifiEventState { WIFI_STATE_NOT_AVALIABLE = 0, WIFI_STATE_AVALIABLE }

Enumerates states in Wi-Fi events.

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.

WifiConnState { WIFI_DISCONNECTED, WIFI_CONNECTED }

Enumerates Wi-Fi connection states.

Functions

Function Name

Description

EnableWifi (void)

WifiErrorCode 

Enables the station mode.

DisableWifi (void)

WifiErrorCode 

Disables the station mode.

IsWifiActive (void)

int 

Checks whether the station mode is enabled.

Scan (void)

WifiErrorCode 

Starts a Wi-Fi scan.

GetScanInfoList (WifiScanInfo result, unsigned int size)

WifiErrorCode 

Obtains an array of hotspots detected in a Wi-Fi scan.

AddDeviceConfig (const WifiDeviceConfig config, int result)

WifiErrorCode 

Adds a specified hotspot configuration for connecting to a hotspot.

GetDeviceConfigs (WifiDeviceConfig result, unsigned int size)

WifiErrorCode 

Obtains all hotspot configurations.

RemoveDevice (int networkId)

WifiErrorCode 

Removes a hotspot configuration matching a specified networkId.

ConnectTo (int networkId)

WifiErrorCode 

Connects to a hotspot matching a specified networkId.

Disconnect (void)

WifiErrorCode 

Disconnects this Wi-Fi connection.

GetLinkedInfo (WifiLinkedInfo result)

WifiErrorCode 

Obtains information about the connected hotspot.

RegisterWifiEvent (WifiEvent event)

WifiErrorCode 

Registers a callback for a specified Wi-Fi event.

UnRegisterWifiEvent (const WifiEvent event)

WifiErrorCode 

Unregisters a callback previously registered for a specified Wi-Fi event.

GetDeviceMacAddress (unsigned char result)

WifiErrorCode 

Obtains the MAC address of this device.

AdvanceScan (WifiScanParams params)

WifiErrorCode 

Starts a Wi-Fi scan based on a specified parameter.

EnableHotspot (void)

WifiErrorCode 

Enables the hotspot mode.

DisableHotspot (void)

WifiErrorCode 

Disables the hotspot mode.

SetHotspotConfig (const HotspotConfig config)

WifiErrorCode 

Sets a specified hotspot configuration.

GetHotspotConfig (HotspotConfig result)

WifiErrorCode 

Obtains a specified hotspot configuration.

IsHotspotActive (void)

int 

Checks whether the hotspot mode is enabled.

GetStationList (StationInfo result, unsigned int size)

WifiErrorCode 

Obtains an array of stations connected to this hotspot.

GetSignalLevel (int rssi, int band)

int 

Obtains the signal level indicated by a specified received signal strength indicator (RSSI) and frequency band.

SetBand (int band)

WifiErrorCode 

Sets the frequency band for this hotspot.

GetBand (int result)

WifiErrorCode 

Obtains the frequency band of this hotspot.

Details

Macro Definition Documentation

WIFI_CONFIG_INVALID

  1. #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

  1. #define WIFI_HOTSPOT_ACTIVE 1

Description:

Indicates that the Wi-Fi hotspot mode is enabled.

WIFI_HOTSPOT_NOT_ACTIVE

  1. #define WIFI_HOTSPOT_NOT_ACTIVE 0

Description:

Indicates that the Wi-Fi hotspot mode is disabled.

WIFI_MAC_LEN

  1. #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

  1. #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

  1. #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

  1. #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

  1. #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

  1. #define WIFI_PSK_LEN 32

Description:

Indicates the maximum length of a Wi-Fi PSK.

WIFI_STA_ACTIVE

  1. #define WIFI_STA_ACTIVE 1

Description:

Indicates that the Wi-Fi station mode is enabled.

WIFI_STA_NOT_ACTIVE

  1. #define WIFI_STA_NOT_ACTIVE 0

Description:

Indicates that the Wi-Fi station mode is disabled.

Typedef Documentation

WifiDeviceConfig

  1. 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

  1. enum [HotspotBandType]($api-api-LinkIoT-Wifiservice.md#ga37e10532da87571ee89193beac42d246)

Description:

Enumerates frequency bands supported by the Wi-Fi hotspot mode.

Enumerator

Description

HOTSPOT_BAND_TYPE_2G 

2.4 GHz

HOTSPOT_BAND_TYPE_5G 

5 GHz

RssiLevel

  1. 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.

Enumerator

Description

RSSI_LEVEL_1 

Level 1. The RSSI value for a 2.4 GHz hotspot ranges from -88 (included) to -82 (excluded), and that for a 5 GHz hotspot ranges from -85 (included) to -79 (excluded).

RSSI_LEVEL_2 

Level 2. The RSSI value for a 2.4 GHz hotspot ranges from -82 (included) to -75 (excluded), and that for a 5 GHz hotspot ranges from -79 (included) to -72 (excluded).

RSSI_LEVEL_3 

Level 3. The RSSI value for a 2.4 GHz hotspot ranges from -75 (included) to -65 (excluded), and that for a 5 GHz hotspot ranges from -72 (included) to -65 (excluded).

RSSI_LEVEL_4 

Level 4. The RSSI value for a 2.4 GHz or 5 GHz hotspot is greater than or equal to -65.

WifiConnState

  1. enum [WifiConnState]($api-api-LinkIoT-Wifiservice.md#ga970b7d5373775b1c7f3b31074bae50e1)

Description:

Enumerates Wi-Fi connection states.

Enumerator

Description

WIFI_DISCONNECTED 

Disconnected

WIFI_CONNECTED 

Connected

WifiErrorCode

  1. enum [WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568)

Description:

Enumerates Wi-Fi error codes.

Enumerator

Description

WIFI_SUCCESS 

No errors.

ERROR_WIFI_INVALID_ARGS 

Invalid parameters

ERROR_WIFI_CHIP_INVALID 

Invalid chip

ERROR_WIFI_IFACE_INVALID 

Invalid Wi-Fi interface

ERROR_WIFI_RTT_CONTROLLER_INVALID 

Invalid RTT controller

ERROR_WIFI_NOT_SUPPORTED 

Wi-Fi not supported by the current version or device

ERROR_WIFI_NOT_AVAILABLE 

Wi-Fi unavailable

ERROR_WIFI_NOT_STARTED 

Wi-Fi not initialized or started

ERROR_WIFI_BUSY 

System busy

ERROR_WIFI_UNKNOWN 

Unknown error

WifiEventState

  1. enum [WifiEventState]($api-api-LinkIoT-Wifiservice.md#ga6be99f93ce0d2d222c1f5f0a8217354d)

Description:

Enumerates states in Wi-Fi events.

Enumerator

Description

WIFI_STATE_NOT_AVALIABLE 

Unavailable state

WIFI_STATE_AVALIABLE 

Available state

WifiPskType

  1. enum [WifiPskType]($api-api-LinkIoT-Wifiservice.md#gaa1a44d23b8478232f14d2adfc82cee77)

Description:

Enumerates psk encryption types.

Enumerator

Description

WIFI_PSK_TYPE_ASCII 

Indicates that the ascii type of psk encryption type

WIFI_PSK_TYPE_HEX 

Indicates that the hex type of psk encryption type

WifiScanType

  1. enum [WifiScanType]($api-api-LinkIoT-Wifiservice.md#ga007bf5e22727debc02cad860e41a60a3)

Description:

Enumerates Wi-Fi scan types.

Enumerator

Description

WIFI_FREQ_SCAN 

A scan based on a specified frequency.

WIFI_SSID_SCAN 

A scan based on a specified SSID.

WIFI_BSSID_SCAN 

A scan based on a specified BSSID.

WIFI_BAND_SCAN 

A scan based on a specified frequency band.

WifiSecurityType

  1. enum [WifiSecurityType]($api-api-LinkIoT-Wifiservice.md#ga97c133f7db7c1234babcde03c4ce1b05)

Description:

Enumerates Wi-Fi security types.

Enumerator

Description

WIFI_SEC_TYPE_INVALID 

Invalid security type

WIFI_SEC_TYPE_OPEN 

Open

WIFI_SEC_TYPE_WEP 

Wired Equivalent Privacy (WEP)

WIFI_SEC_TYPE_PSK 

Pre-shared key (PSK)

WIFI_SEC_TYPE_SAE 

Simultaneous Authentication of Equals (SAE)

Function Documentation

AddDeviceConfig()

  1. [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:

Name

Description

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()

  1. [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:

Name

Description

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()

  1. [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:

Name

Description

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()

  1. [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()

  1. [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()

  1. [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()

  1. [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()

  1. [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()

  1. [WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetBand (int * result)

Description:

Obtains the frequency band of this hotspot.

Parameters:

Name

Description

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()

  1. [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:

Name

Description

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()

  1. [WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetDeviceMacAddress (unsigned char * result)

Description:

Obtains the MAC address of this device.

Parameters:

Name

Description

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()

  1. [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:

Name

Description

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()

  1. [WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetLinkedInfo ([WifiLinkedInfo]($api-api-LinkIoT-WifiLinkedInfo.md) * result)

Description:

Obtains information about the connected hotspot.

Parameters:

Name

Description

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()

  1. [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:

Name

Description

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()

  1. 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:

Name

Description

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()

  1. [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:

Name

Description

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()

  1. 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()

  1. 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()

  1. [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:

Name

Description

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()

  1. [WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) RemoveDevice (int networkId)

Description:

Removes a hotspot configuration matching a specified networkId.

Parameters:

Name

Description

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()

  1. [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()

  1. [WifiErrorCode]($api-api-LinkIoT-Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) SetBand (int band)

Description:

Sets the frequency band for this hotspot.

Parameters:

Name

Description

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()

  1. [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:

Name

Description

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()

  1. [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:

Name

Description

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.