Wireless Connection

Last Updated on : 2024-11-20 08:51:48

This topic describes the APIs used to enable the gateway to be connected to the internet via a wireless connection.

Structs

NW_IP_S

typedef struct
{
    char ip[16];
    char mask[16];
    char gw[16];
} NW_IP_S;

Functional specification

The IP address information.

Member description

Member Description
ip The IP address of the network adapter.
mask The subnet mask of the network adapter.
gw The default gateway of the network adapter.

WF_AP_CFG_IF_S

typedef struct {
    uint8_t ssid[WIFI_SSID_LEN+1];
    uint8_t s_len;
    uint8_t passwd[WIFI_PASSWD_LEN+1];
    uint8_t p_len;
    uint8_t chan;
    WF_AP_AUTH_MODE_E md;
    uint8_t ssid_hidden;
    uint8_t max_conn;
    uint16_t ms_interval;
} WF_AP_CFG_IF_S;

Functional specification

The access point (AP) configuration.

Member description

Member Description
ssid The SSID of the wireless network.
s_len The length of the SSID.
passwd The password of the wireless network.
p_len The length of the password.
chan The channel of the wireless network.
md The encryption type of the wireless network.
ssid_hidden Specify whether to hide the SSID.
max_conn The maximum number of clients that can be connected to the network.
ms_interval The beacon interval.

API reference

tuya_adapter_wifi_get_ip

OPERATE_RET tuya_adapter_wifi_get_ip(IN CONST WF_IF_E wf,
                                     OUT NW_IP_S *ip)

Functional description

Gets the IP address of the wireless network adapter. After the gateway is connected to a wireless network, the SDK will request the IP address of the network adapter to achieve LAN communication.

Parameter description

Parameter name Description
wf The modes of the wireless network adapter:
  • WF_STATION: The station mode.
  • WF_AP: The AP mode.
ip The IP address information. For more information, see NW_IP_S.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_get_mac

OPERATE_RET tuya_adapter_wifi_get_mac(IN CONST WF_IF_E wf,
                                      OUT NW_MAC_S *mac)

Functional description

Gets the MAC address of the wireless network adapter.

Parameter description

Parameter name Description
wf The modes of the wireless network adapter:
  • WF_STATION: The station mode.
  • WF_AP: The AP mode.
mac An output parameter. Assign the MAC address to this variable.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_set_mac

OPERATE_RET tuya_adapter_wifi_set_mac(IN CONST WF_IF_E wf,
                                      IN CONST NW_MAC_S *mac)

Functional description

Sets the MAC address of the gateway. This is a reserved interface so implementation is not needed.

Parameter description

Parameter name Description
wf The modes of the wireless network adapter:
  • WF_STATION: The station mode.
  • WF_AP: The AP mode.
mac The MAC address to set.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_set_work_mode

OPERATE_RET tuya_adapter_wifi_set_work_mode(IN CONST WF_WK_MD_E mode)

Functional description

Sets the operation mode of the gateway. During the pairing process, the operation mode of the wireless network adapter is switched based on specific parameters.

Parameter description

Parameter name Description
mode The operation modes of the gateway:
  • WWM_LOWPOWER: The low power mode. This mode is not necessary for Linux.
  • WWM_SNIFFER: The sniffer mode.
  • WWM_STATION: The station mode.
  • WWM_SOFTAP: The AP mode.
  • WWM_STATIONAP: The station mode and AP mode coexist.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_get_work_mode

OPERATE_RET tuya_adapter_wifi_get_work_mode(OUT WF_WK_MD_E *mode)

Functional description

Gets the operation mode of the gateway.

Parameter description

Parameter name Description
mode The operation modes of the gateway:
  • WWM_LOWPOWER: The low power mode. This mode is not necessary for Linux.
  • WWM_SNIFFER: The sniffer mode.
  • WWM_STATION: The station mode.
  • WWM_SOFTAP: The AP mode.
  • WWM_STATIONAP: The station mode and AP mode coexist.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_station_connect

OPERATE_RET tuya_adapter_wifi_station_connect(IN CONST CHAR_T *ssid,
                                              IN CONST CHAR_T *passwd)

Functional description

Connects the gateway to the router. The SDK uses the obtained SSID and password to connect the gateway to a specific router.

Parameter description

Parameter name Description
ssid The SSID of the router.
password The password of the router.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_station_disconnect

OPERATE_RET tuya_adapter_wifi_station_disconnect(VOID)

Functional description

Disconnects the gateway from the router.

Parameter description

Parameter name Description
VOID /

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_station_get_conn_ap_rssi

OPERATE_RET tuya_adapter_wifi_station_get_conn_ap_rssi(OUT SCHAR_T *rssi)

Functional description

Gets the signal strength of the wireless network received by the gateway. The SDK will report the obtained value to the cloud.

Parameter description

Parameter name Description
rssi The value of the received signal strength indicator (RSSI).

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_station_get_status

OPERATE_RET tuya_adapter_wifi_station_get_status(OUT WF_STATION_STAT_E *stat)

Functional description

Gets the wireless connection status of the gateway. With a wireless network connection, the SDK will regularly request the wireless connection status.

Parameter description

Parameter name Description
stat An output parameter. Assign the wireless connection status to this variable.
  • WSS_IDLE: The gateway is not connected to a wireless network.
  • WSS_CONNECTING: The gateway is being connected to a wireless network.
  • WSS_PASSWD_WRONG: Wrong password.
  • WSS_NO_AP_FOUND: No wireless AP is found.
  • WSS_CONN_FAIL: The gateway fails to be connected to a wireless network.
  • WSS_CONN_SUCCESS: The gateway is successfully connected to a wireless network.
  • WSS_GOT_IP: The gateway is successfully connected to a wireless network and assigned an IP address.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_set_country_code

OPERATE_RET tuya_adapter_wifi_set_country_code(CONST COUNTRY_CODE_E code)

Functional description

Sets the country code of the gateway.

Parameter description

Parameter name Description
code The country code.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_ap_start

OPERATE_RET tuya_adapter_wifi_ap_start(IN CONST WF_AP_CFG_IF_S *cfg)

Functional description

Turns on the wireless AP.

Parameter description

Parameter name Description
cfg The access point (AP) configuration. For more information, see WF_AP_CFG_IF_S.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_ap_stop

OPERATE_RET tuya_adapter_wifi_ap_stop(VOID)

Functional description

Turns off the wireless AP.

Parameter description

Parameter name Description
VOID /

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_all_ap_scan

OPERATE_RET tuya_adapter_wifi_all_ap_scan(OUT AP_IF_S **ap_ary,
                                          OUT UINT_T *num)

Functional description

Scans for the available wireless AP and returns a list to the SDK.

Parameter description

Parameter name Description
ap_ary Assign the list of available wireless AP to this variable.
num The length of the list.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_assign_ap_scan

OPERATE_RET tuya_adapter_wifi_assign_ap_scan(IN CONST CHAR_T *ssid,
                                             OUT AP_IF_S **ap)

Functional description

Gets the information about wireless AP with a specified SSID. This is a reserved interface so implementation is not needed.

Parameter description

Parameter name Description
ssid The SSID of a specified wireless AP.
ap The information about the wireless AP.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_release_ap

OPERATE_RET tuya_adapter_wifi_release_ap(IN AP_IF_S *ap)

Functional description

Frees the memory allocated by tuya_adapter_wifi_all_ap_scan.

Parameter description

Parameter name Description
ap The memory address used to store the list of available wireless APs.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_set_cur_channel

OPERATE_RET tuya_adapter_wifi_set_cur_channel(CONST UCHAR_T chan)

Functional description

Sets the channels of the wireless network. In the sniffer mode, the SDK switches between channels to capture wireless packets from each channel.

Parameter description

Parameter name Description
chan The channel to set.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_get_cur_channel

OPERATE_RET tuya_adapter_wifi_get_cur_channel(UCHAR_T *chan)

Functional description

Gets the current channel. When the SDK parses a valid wireless packet from a specific channel, it will stay in that channel until all the packets are received. You can use this API to get this specific channel.

Parameter description

Parameter name Description
chan Assign the obtained channel to this variable.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_adapter_wifi_sniffer_set

OPERATE_RET tuya_adapter_wifi_sniffer_set(CONST BOOL_T en, CONST SNIFFER_CALLBACK cb)

Functional description

Sets the sniffer mode for the gateway. With the sniffer mode turned on, you need to start a thread to capture wireless packets and send the captured packet to the SDK for parsing. After the sniffer mode is turned off, the thread will be destroyed.

Parameter description

Parameter name Description
en If en is TRUE, it indicates the sniffer mode is turned on.
If en is FALSE, it indicates the sniffer mode is turned off.
cb A callback to invoke when an IEEE 802.11 wireless packet is captured.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.