Wi-Fi Development Guide

Introduction

Quectel FCM242D and FGM842D series modules support QuecOpen® solution. QuecOpen® is an embedded development platform based on RTOS system. It is intended to simplify the design and development of IoT applications. For more information on QuecOpen®, see Quick_Start_Guide.

This document is applicable to QuecOpen® solution based on SDK build environment. It introduces Wi-Fi API and related examples provided in the SDK of FCM242D and FGM842D series modules, as well as contents about Wi-Fi provisioning via web.

Wi-Fi API

Header File

ql_wlan.h, the header file of Wi-Fi API, is in the ql_components/api directory. Unless otherwise specified, all header files mentioned in this document are in this directory.

API Overview

Function Description
ql_wlan_get_mac() Obtains the MAC address for Wi-Fi communication.
ql_wlan_set_mac() Sets the MAC address for Wi-Fi communication.
ql_wlan_start() Starts STA or AP mode.
ql_wlan_start_sta_adv() Enables STA to connect AP quickly.
ql_wlan_stop() Stops STA or AP mode.
ql_wlan_start_scan() Enables AP scan.
ql_wlan_scan_ap_reg_cb() Registers the callback function which will be called after the scan is finished.
ql_wlan_sta_scan_result() Gets the network scan results in STA mode.
ql_wlan_start_assign_scan() Scans the specified AP.
ql_wlan_status_register_cb() Registers the callback function for the Wi-Fi status register.
ql_wlan_start_monitor() Enables monitoring mode.
ql_wlan_stop_monitor() Disables monitoring mode.
ql_wlan_register_monitor_cb() Registers the callback function for monitoring mode.
ql_wlan_ap_para_info_get() Gets the current AP information.
ql_wlan_get_ip_status() Gets the current Wi-Fi network status.
ql_wlan_get_link_status() Obtains the connection status between the module and the AP when the module is operating as a STA.
ql_wlan_get_channel() Obtains the channel being monitored.
ql_wlan_set_channel() Sets the channel to be monitored.
ql_wlan_set_channel_sync() Sets the channel to be monitored without restarting the monitoring mode.
ql_sta_chiper_type() Obtains the encryption method of connected AP.
ql_wlan_ota_download() Upgrades the module firmware.
ql_ap_ip_is_start() Obtains the status of AP.
ql_sta_ip_is_start() Queries whether the module is connected to an AP when it is operating as a STA.
ql_airkiss_start() Starts AirKiss provisioning.
ql_airkiss_is_at_its_context() Checks whether AirKiss provisioning is currently in progress.
ql_wifi_stainfo_read() Reads Wi-Fi information from flash.
ql_wifi_stainfo_write() Writes Wi-Fi information to flash.
ql_wifi_stainfo_remove() Deletes Wi-Fi information from flash.
ql_uart_baudrate_write() Writes baud rate to flash.
ql_uart_baudrate_read() Reads baud rate from flash.
ql_uart_baudrate_remove() Deletes baud rate from flash.

API Description

ql_wlan_get_mac

This function obtains the MAC address for Wi-Fi communication.

Prototype:

int ql_wlan_get_mac(char *mac)

Parameters:

mac: [Out] The obtained MAC address.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wifi_errcode_e

The enumeration of function execution result codes:

typedef enum
{
    QL_WIFI_SUCCESS = 0,
    QL_WIFI_EXECUTE_ERR,
    QL_WIFI_INVALID_PARAM_ERR,
} ql_wifi_errcode_e

Members:

Member Description
QL_WIFI_SUCCESS Successful execution
QL_WIFI_EXECUTE_ERR Failed execution
QL_WIFI_INVALID_PARAM_ERR Invalid parameter

ql_wlan_set_mac

This function sets the MAC address for Wi-Fi communication.

Prototype:

int ql_wlan_set_mac(char *mac)

Parameters:

mac: [In] The MAC address to be set.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wlan_start

This function starts STA or AP mode. The upper application starts the Wi-Fi network connection after obtaining the SSID and password.

Prototype:

int ql_wlan_start(ql_network_init_s *inNetworkInitPara)

Parameters:

inNetworkInitPara: [In] Wi-Fi network connection configuration information. See ql_network_init_s for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_network_init_s

The structure of Wi-Fi network connection configuration information:

typedef struct
{
    char wifi_mode;
    char wifi_ssid[33];
    char wifi_key[108];
    char local_ip_addr[16];
    char net_mask[16];
    char gateway_ip_addr[16];
    char dns_server_ip_addr[16];
    char dhcp_mode;
    char wifi_bssid[6];
    char reserved[26];
    int wifi_retry_interval;
    bool hidden_ssid;
} ql_network_init_s

Parameters:

Type Parameter Description
char wifi_mode Wi-Fi working mode. See ql_wifi_mode_e for details.
char wifi_ssid SSID of the AP to be connected or created.
char wifi_key Password for the AP to be connected or created.
char local_ip_addr Static IP address, which is valid when DHCP is disabled.
char net_mask Static subnet mask, which is valid when DHCP is disabled.
char gateway_ip_addr Static gateway address, which is valid when DHCP is disabled.
char dns_server_ip_addr Static DNS address, which is valid when DHCP is disabled.
char dhcp_mode DHCP mode: 0 = DHCP_DISABLE (DHCP is disabled), 1 = DHCP_CLIENT (DHCP client), 2 = DHCP_SERVER (DHCP server, only supported in AP mode)
char wifi_bssid BSSID of AP (Reserved, not supported currently).
char reserved Reserved.
int wifi_retry_interval Reconnection interval. Unit: millisecond (Reserved, not supported currently).
bool hidden_ssid Whether to hide the SSID (Currently not supported).
ql_wifi_mode_e

The enumeration of Wi-Fi working modes:

typedef enum
{
    QL_SOFT_AP,
    QL_STATION,
    QL_P2P,
} ql_wifi_mode_e

Members:

Member Description
QL_SOFT_AP AP mode
QL_STATION STA mode
QL_P2P P2P mode (Currently not supported)

ql_wlan_start_sta_adv

This function enables STA to connect AP quickly.

Prototype:

int ql_wlan_start_sta_adv(ql_network_InitTypeDef_adv_s *inNetworkInitParaAdv)

Parameters:

inNetworkInitParaAdv: [In] Quick connection configuration information. See ql_network_InitTypeDef_adv_s for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_network_InitTypeDef_adv_s

The structure of quick connection configuration information:

typedef struct ql_network_InitTypeDef_adv_st
{
    ql_apinfo_adv_s ap_info;
    char key[64];
    int key_len;
    char local_ip_addr[16];
    char net_mask[16];
    char gateway_ip_addr[16];
    char dns_server_ip_addr[16];
    char dhcp_mode;
    char reserved[32];
    int wifi_retry_interval;
} ql_network_InitTypeDef_adv_s

Parameters:

Type Parameter Description
ql_apinfo_adv_s ap_info Information of the AP to be quickly connected. See ql_apinfo_adv_s for details.
char key Password for the AP to be quickly connected.
int key_len Length of password. Unit: Byte.
char local_ip_addr Static IP address, which is valid when DHCP is disabled.
char net_mask Static subnet mask, which is valid when DHCP is disabled.
char gateway_ip_addr Static gateway address, which is valid when DHCP is disabled.
char dns_server_ip_addr Static DNS address, which is valid when DHCP is disabled.
char dhcp_mode DHCP mode: 0 = DHCP_DISABLE (DHCP is disabled), 1 = DHCP_CLIENT (DHCP client), 2 = DHCP_SERVER (DHCP server, only supported in AP mode)
char reserved Reserved.
int wifi_retry_interval Reconnection time. Unit: millisecond (Reserved).
ql_apinfo_adv_s

The structure of the information of AP to be quickly connected:

typedef struct
{
    char ssid[32];
    char bssid[6];
    uint8_t channel;
    uint8_t security;
} ql_apinfo_adv_s

Parameters:

Type Parameter Description
char ssid SSID of the AP to be quickly connected.
char bssid BSSID of the AP to be quickly connected.
uint8_t channel Channel of the AP to be quickly connected.
uint8_t security Encryption method of the AP to be quickly connected. See ql_wlan_sec_type_e for details.
ql_wlan_sec_type_e

The enumeration of encryption methods:

typedef enum
{
    QL_SECURITY_TYPE_NONE,
    QL_SECURITY_TYPE_WEP,
    QL_SECURITY_TYPE_WPA_TKIP,
    QL_SECURITY_TYPE_WPA_AES,
    QL_SECURITY_TYPE_WPA_MIXED,
    QL_SECURITY_TYPE_WPA2_TKIP,
    QL_SECURITY_TYPE_WPA2_AES,
    QL_SECURITY_TYPE_WPA2_MIXED,
    QL_SECURITY_TYPE_WPA3_SAE,
    QL_SECURITY_TYPE_WPA3_WPA2_MIXED,
    QL_SECURITY_TYPE_EAP,
    QL_SECURITY_TYPE_OWE,
    QL_SECURITY_TYPE_AUTO,
} ql_wlan_sec_type_e

Members:

Member Description
QL_SECURITY_TYPE_NONE No encryption.
QL_SECURITY_TYPE_WEP WEP encryption.
QL_SECURITY_TYPE_WPA_TKIP WPA_TKIP encryption.
QL_SECURITY_TYPE_WPA_AES WPA_AES encryption.
QL_SECURITY_TYPE_WPA_MIXED WPA hybrid encryption.
QL_SECURITY_TYPE_WPA2_TKIP WPA2_TKIP encryption.
QL_SECURITY_TYPE_WPA2_AES WPA2_AES encryption.
QL_SECURITY_TYPE_WPA2_MIXED WPA2 hybrid encryption.
QL_SECURITY_TYPE_WPA3_SAE WPA3_SAE encryption.
QL_SECURITY_TYPE_WPA3_WPA2_MIXED WPA2/WPA3 hybrid encryption.
QL_SECURITY_TYPE_EAP Extensible authentication protocol.
QL_SECURITY_TYPE_OWE Opportunistic wireless encryption.
QL_SECURITY_TYPE_AUTO Automatic security type selection.

ql_wlan_stop

This function stops the STA or AP mode.

Prototype:

int ql_wlan_stop(ql_wifi_mode_e mode)

Parameters:

mode: [In] Wi-Fi working mode to be disabled. See ql_wifi_mode_e for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wlan_start_scan

This function enables AP scan.

Prototype:

int ql_wlan_start_scan(void)

Parameters:

None

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wlan_scan_ap_reg_cb

This function registers the callback function which will be called after the scan is finished.

Prototype:

int ql_wlan_scan_ap_reg_cb(ql_func_scan_callback ind_cb)

Parameters:

ind_cb: [In] The callback function which will be called after the scan is finished. See ql_func_scan_callback for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_func_scan_callback

This function is the callback function which will be called after the scan is finished.

Prototype:

typedef void (*ql_func_scan_callback)(void *arg, unsigned char vif_idx)

Parameters:

arg: [In] Reserved.

vif_idx: [In] Reserved.

ql_wlan_sta_scan_result

This function gets the network scan results in STA mode. It can be called after the scan is finished.

Prototype:

int ql_wlan_sta_scan_result(ql_scan_result_s *results)

Parameters:

results: [In] Scan result. See ql_scan_result_s for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_scan_result_s

The structure of scan result:

typedef struct ql_ScanResult_adv
{
    char ApNum;
    ql_apliststruct *ql_aplist_s;
} ql_scan_result_s

Parameters:

Type Parameter Description
char ApNum Number of scanned APs.
ql_apliststruct* ql_aplist_s Information of scanned AP. See ql_apliststruct for details.
ql_apliststruct

The structure of the information of scanned AP:

typedef struct
{
    char ssid[33];
    char ApPower;
    uint8_t bssid[6];
    char channel;
    uint8_t security;
} ql_apliststruct

Parameters:

Type Parameter Description
char ssid SSID of the AP that has been scanned.
char ApPower Signal strength of the AP that has been scanned. Range: -100 to 0.
uint8_t bssid BSSID of the AP that has been scanned.
char channel Channel of the AP that has been scanned.
uint8_t security AP encryption method. See ql_wlan_sec_type_e for details.

ql_wlan_start_assign_scan

This function scans the specified AP.

Prototype:

int ql_wlan_start_assign_scan(UINT8 **ssid_ary, UINT8 ssid_num)

Parameters:

ssid_ary: [In] SSID of specified AP.

ssid_num: [In] Number of the specified APs. It can only be set to 1, which means only the specified AP can be scanned.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wlan_status_register_cb

This function registers the callback function for the Wi-Fi status register.

Prototype:

int ql_wlan_status_register_cb(ql_func_status_callback cb)

Parameters:

cb: [In] Callback function for the Wi-Fi status register. See ql_func_status_callback for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_func_status_callback

This function is the callback function for the Wi-Fi status register.

Prototype:

typedef void (*ql_func_status_callback)(ql_wlan_evt_type *ctxt)

Parameters:

ctxt: [Out] Reserved.

ql_wlan_start_monitor

This function enables monitoring mode.

Prototype:

int ql_wlan_start_monitor(void)

Parameters:

None

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wlan_stop_monitor

This function disables monitoring mode.

Prototype:

int ql_wlan_stop_monitor(void)

Parameters:

None

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wlan_register_monitor_cb

This function registers the callback function for monitoring mode.

Prototype:

int ql_wlan_register_monitor_cb(ql_monitor_cb_t fn)

Parameters:

fn: [In] The callback function for monitoring mode. See ql_monitor_cb_t for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_monitor_cb_t

This function is the callback function for monitoring mode.

Prototype:

typedef void (*ql_monitor_cb_t)(uint8_t *data, int len, ql_wifi_link_info_t *info)

Parameters:

data: [Out] Data returned during monitoring.

len: [Out] Length of data returned during monitoring. Unit: byte.

info: [Out] Information of the monitored packets. See ql_wifi_link_info_t for details.

The structure of monitored packet information:

typedef struct
{
    int8_t rssi;
} ql_wifi_link_info_t

Parameters:

Type Parameter Description
int8_t rssi The signal strength of the monitored packet.

ql_wlan_ap_para_info_get

This function gets the current AP information.

Prototype:

int ql_wlan_ap_para_info_get(ql_network_init_ap_s *ap_info)

Parameters:

ap_info: [Out] AP information. See ql_network_init_ap_s for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_network_init_ap_s

The structure of AP information:

typedef struct ql_network_init_ap_st
{
    char wifi_ssid[32];
    char wifi_key[64];
    uint8_t channel;
    uint8_t security;
    uint8_t ssid_hidden;
    uint8_t max_con;
    char local_ip_addr[16];
    char net_mask[16];
    char gateway_ip_addr[16];
    char dns_server_ip_addr[16];
    char dhcp_mode;
    char reserved[32];
    int wifi_retry_interval;
} ql_network_init_ap_s

Parameters:

Type Parameter Description
char wifi_ssid SSID of the AP to be connected or created.
char wifi_key Password for the AP to be connected or created.
uint8_t channel Channel of the AP.
uint8_t security AP encryption method (Reserved, not supported currently).
uint8_t ssid_hidden Enable the SSID hiding function (Reserved, not supported currently).
uint8_t max_con The maximum number of STAs that can connect to the current AP (Reserved, not supported currently).
char local_ip_addr Static IP address, which is valid when DHCP is disabled.
char net_mask Static subnet mask, which is valid when DHCP is disabled.
char gateway_ip_addr Static gateway address, which is valid when DHCP is disabled.
char dns_server_ip_addr Static DNS address, which is valid when DHCP is disabled.
char dhcp_mode DHCP mode: 0 = DHCP_DISABLE (DHCP is disabled), 1 = DHCP_CLIENT (DHCP client), 2 = DHCP_SERVER (DHCP server, only supported in AP mode)
char reserved Reserved.
int wifi_retry_interval Reconnection interval. Unit: millisecond (Reserved, not supported currently).

ql_wlan_get_ip_status

This function gets the current Wi-Fi network status.

Prototype:

int ql_wlan_get_ip_status(ql_ip_status_s *outNetpara, ql_wifi_mode_e inInterface)

Parameters:

outNetpara: [Out] Wi-Fi network status. See ql_ip_status_s for details.

inInterface: [In] Wi-Fi working mode. See ql_wifi_mode_e for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_ip_status_s

The structure of Wi-Fi network status:

typedef struct
{
    uint8_t dhcp;
    char ip[16];
    char gate[16];
    char mask[16];
    char dns[16];
    char mac[16];
    char broadcastip[16];
    char standby_dns[16];
} ql_ip_status_s

Parameters:

Type Parameter Description
uint8_t dhcp Acquired DHCP mode: 0 = DHCP_DISABLE (DHCP is disabled), 1 = DHCP_CLIENT (DHCP client), 2 = DHCP_SERVER (DHCP server, only supported in AP mode)
char ip Acquired IP address.
char gate Acquired gateway IP address.
char mask Acquired subnet mask.
char dns Acquired DNS service IP address.
char mac Acquired MAC address.
char broadcastip Acquired broadcast IP address (Reserved, not supported currently).
char standby_dns Secondary DNS server address.

This function obtains the connection status between the module and the AP when the module is operating as a STA.

Prototype:

int ql_wlan_get_link_status(ql_link_status_s *outStatus)

Parameters:

outStatus: [Out] Connection status. See ql_link_status_s for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

The structure of connection status:

typedef struct
{
    int conn_state;
    int wifi_strength;
    uint8_t ssid[33];
    uint8_t bssid[6];
    uint16_t aid;
    int channel;
    uint8_t security;
} ql_link_status_s

Parameters:

Type Parameter Description
int conn_state Current connection status.
int wifi_strength Current signal strength.
uint8_t ssid SSID of currently connected AP.
uint8_t bssid BSSID of AP.
uint16_t aid Unique identifier assigned by the AP.
int channel Channel of currently connected AP.
uint8_t security AP encryption method. See ql_wlan_sec_type_e for details.

ql_wlan_get_channel

This function obtains the channel being monitored.

Prototype:

int ql_wlan_get_channel(void)

Parameters:

None

Return Value:

The channel being monitored.

ql_wlan_set_channel

This function sets the channel to be monitored.

Prototype:

int ql_wlan_set_channel(int channel)

Parameters:

channel: [In] Channel.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wlan_set_channel_sync

This function sets the channel to be monitored without restarting the monitoring mode.

Prototype:

int ql_wlan_set_channel_sync(int channel)

Parameters:

channel: [In] Channel.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_sta_chiper_type

This function obtains the encryption method of connected AP.

Prototype:

int ql_sta_chiper_type(void)

Parameters:

None

Return Value:

AP encryption method. See ql_wlan_sec_type_e for details.

ql_wlan_ota_download

This function upgrades the module firmware.

Prototype:

int ql_wlan_ota_download(const char *uri)

Parameters:

uri: [In] Domain of the HTTP server that stores the upgrade package.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_ap_ip_is_start

This function obtains the status of AP.

Prototype:

uint32 ql_ap_ip_is_start(void)

Parameters:

None

Return Value:

0 = Disabled, 1 = Enabled

ql_sta_ip_is_start

This function queries whether the module is connected to an AP when it is operating as a STA.

Prototype:

uint32 ql_sta_ip_is_start(void)

Parameters:

None

Return Value:

0 = Disconnected, 1 = Connected

ql_airkiss_start

This function starts AirKiss provisioning.

Prototype:

int ql_airkiss_start(uint8_t start)

Parameters:

start: [In] Start or stop AirKiss provisioning. 0 = Stop, 1 = Start

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_airkiss_is_at_its_context

This function checks whether AirKiss provisioning is currently in progress.

Prototype:

uint32 ql_airkiss_is_at_its_context(void)

Parameters:

None

Return Value:

0 = AirKiss provisioning is not in progress, 1 = AirKiss provisioning is in progress

ql_wifi_stainfo_read

This function reads Wi-Fi information from flash.

Prototype:

int ql_wifi_stainfo_read(ql_wifi_nv_info_t *wifi_info)

Parameters:

wifi_info: [Out] Wi-Fi information. See ql_wifi_nv_info_t for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wifi_nv_info_t

The structure of Wi-Fi information:

typedef struct {
    uint8_t sync;
    char sta_ssid[33];
    char sta_pwd[64];
    uint8_t sta_bssid[6];
    uint8_t channel;
    uint8_t auto_conn;
} ql_wifi_nv_info_t

Parameters:

Type Parameter Description
uint8_t sync Number of scanned APs.
char sta_ssid SSID of AP.
char sta_pwd Password for connecting to the AP.
uint8_t sta_bssid BSSID of AP.
uint8_t channel Channel.
uint8_t auto_conn Whether to automatically reconnect. 0 = Do not automatically reconnect, 1 = Automatically reconnect.

ql_wifi_stainfo_write

This function writes Wi-Fi information to flash.

Prototype:

int ql_wifi_stainfo_write(ql_wifi_nv_info_t *wifi_info)

Parameters:

wifi_info: [In] Wi-Fi information. See ql_wifi_nv_info_t for details.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_wifi_stainfo_remove

This function deletes Wi-Fi information from flash.

Prototype:

int ql_wifi_stainfo_remove(void)

Parameters:

None

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_uart_baudrate_write

This function writes baud rate to flash.

Prototype:

int ql_uart_baudrate_write(int *baud)

Parameters:

baud: [In] Baud rate. Unit: Bd.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_uart_baudrate_read

This function reads baud rate from flash.

Prototype:

int ql_uart_baudrate_read(int *baud)

Parameters:

baud: [Out] Baud rate. Unit: Bd.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

ql_uart_baudrate_remove

This function deletes baud rate from flash.

Prototype:

int ql_uart_baudrate_remove(void)

Parameters:

baud: [In] Baud rate. Unit: Bd.

Return Value:

Function execution result code. See ql_wifi_errcode_e for details.

Example Codes

ql_wlan_demo.c, the Wi-Fi API example code file, is in the ql_application/example/wlan_demo directory, where you can view the complete Wi-Fi API examples and implement Wi-Fi-related features. The example codes for some of the relevant features are shown below:

Enable STA to connect AP

void ql_demo_sta_app_init(char *oob_ssid, char *connect_key)
{
    /* Define a structure for passing in parameters */
    ql_network_init_s wNetConfig;
    int ssid_len, key_len;

    os_memset(&wNetConfig, 0x0, sizeof(ql_network_init_s));

    /* Check the length of SSID, which cannot exceed 32 bytes */
    ssid_len = os_strlen(oob_ssid);
    if(SSID_MAX_LEN < ssid_len || ssid_len < 1)
    {
        ql_wlan_log("ssid length error\n");
        return;
    }

    key_len = os_strlen(connect_key);
    if (STA_KEY_MAX_LEN < key_len || key_len < 8)
    {
        bk_printf("key length error\n");
        return;
    }

    /* Pass SSID and password into the structure */
    os_strcpy((char *)wNetConfig.wifi_ssid, oob_ssid);
    os_strcpy((char *)wNetConfig.wifi_key, connect_key);

    /* STATION mode */
    wNetConfig.wifi_mode = QL_STATION;

    /* Obtain the IP address dynamically from the router by using DHCP CLIENT */
    wNetConfig.dhcp_mode = DHCP_CLIENT;
    wNetConfig.wifi_retry_interval = 100;

    ql_wlan_log("ssid:%s key:%s\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key);

    /* Start STATION */
    ql_wlan_start(&wNetConfig);
}

Start AP

void ql_demo_softap_app_init(char *ap_ssid, char *ap_key)
{
    /* Define a structure for passing in parameters */
    ql_network_init_s wNetConfig;
    int len;

    /* Clear the structure */
    os_memset(&wNetConfig, 0x0, sizeof(ql_network_init_s));

    len = os_strlen(ap_ssid);
    if(SSID_MAX_LEN < len || len < 1)
    {
        ql_wlan_log("ssid length error\n");
        return;
    }

    len = os_strlen(ap_key);
    if(63 < len || len < 8)
    {
        bk_printf("key length error\n");
        return;
    }

    /* Pass in the ap ssid and ap key to connect */
    os_strcpy((char *)wNetConfig.wifi_ssid, ap_ssid);
    os_strcpy((char *)wNetConfig.wifi_key, ap_key);

    /* AP mode */
    wNetConfig.wifi_mode = QL_SOFT_AP;

    /* With DHCP SERVER mode, static addresses need to be assigned as local addresses */
    wNetConfig.dhcp_mode = DHCP_SERVER;
    wNetConfig.wifi_retry_interval = 100;

    os_strcpy((char *)wNetConfig.local_ip_addr, QL_WLAN_DEFAULT_IP);
    os_strcpy((char *)wNetConfig.net_mask, QL_WLAN_DEFAULT_MASK);
    os_strcpy((char *)wNetConfig.gateway_ip_addr, QL_WLAN_DEFAULT_GW);
    os_strcpy((char *)wNetConfig.dns_server_ip_addr, QL_WLAN_DEFAULT_GW);

    ql_wlan_log("ssid:%s key:%s\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key);

    /* Start ap */
    ql_wlan_start(&wNetConfig);
}

Start Wi-Fi scan and analyze the scan results

/* Callback function, used to parse scan results after scan */
static void scan_cb(void *ctxt, uint8_t param)
{
    int ret = 0;
    ql_scan_result_s info;
    char *auth_str[] = {"open", "wep", "wpa", "wpa", "wpa2", "wpa2", "wpa/wpa2", "wpa3", "wpa2/wpa3"};

    ret = ql_wlan_sta_scan_result(&info);
    if (ret == 0) {
        ql_wlan_log("Got ap count: %d\n", info.ApNum);
        for (int i = 0; i < info.ApNum; i++){
            debug_log("\"%s\", %02x%02x%02x%02x%02x%02x, %d, %s, %d\n",
                info.ql_aplist_s[i].ssid, MAC2STR(info.ql_aplist_s[i].bssid),
                info.ql_aplist_s[i].ApPower, auth_str[info.ql_aplist_s[i].security],
                info.ql_aplist_s[i].channel);
        }
        os_free(info.ql_aplist_s);
    }
    else
    {
        ql_wlan_log("not found bss.\n");
    }
}

void ql_demo_scan_app_init(void)
{
    /* Register scan callback function */
    ql_wlan_scan_ap_reg_cb(scan_cb);

    /* start scan */
    ql_wlan_start_scan();
}

Wi-Fi Provisioning via Web

Environment Preparation

Hardware Environment:

Hardware Quantity
Quectel FCM242D-TE-B 1
Micro USB cable 2
PC 1

FCM242D-TE-B

Wi-Fi Provisioning Steps

Compiling and Downloading Codes

Set the macro CFG_ENABLE_QUECTEL_AP_NET in ql_app_mian.c to 1. As shown in the figure below:

Enable Wi-Fi Provisioning

Please see Quick_Start_Guide for the code compilation steps. The .bin file generated after the compilation is stored in the out/ directory. Flash the .bin file into the development board. After the flashing process is completed, the module will automatically reset, and the Wi-Fi provisioning example program in the SDK will run automatically.

Wi-Fi Provisioning Process

  1. Run the Wi-Fi provisioning example program in SDK to enable the hotspot whose name is "FCM242D" (The hotspot name is fixed as "FCM242D" when a FCM242D or FGM842D series module is used) and password is "12345678".

    Wi-Fi Provisioning Example Program

  2. Connect to the "FCM242D" hotspot and input "192.168.19.1" in the browser on the PC, then Wi-Fi provisioning interface is displayed.

    Wi-Fi Provisioning Interface

  3. Enter the SSID and password in the input boxes of "SSID" and "Password", then click Save to connect Wi-Fi.

    Input Information

  4. View the log of the module to check whether the module is connected to the specified AP hotspot. If the information in the red box in the following figure is displayed, the AP hotspot is connected.

    Connect to AP Hotspot Successfully

Web Example Codes

ql_wlan_config_network_demo.c, the code example file of Wi-Fi provisioning via web, is in the ql_application/example/wlan_config_network_demo directory, where you can view the complete examples and implement related features of Wi-Fi provisioning via web.

Appendix References

Related Documents:

Document Name
Quectel_FCM242D&FGM842D_Series_QuecOpen(SDK)_Quick_Start_Guide

Terms and Abbreviations

Terms and Abbreviations:

Abbreviation Description
AES Advanced Encryption Standard
AP Access Point
API Application Programming Interface
BSSID Basic Service Set Identifier
DHCP Dynamic Host Configuration Protocol
DNS Domain Name Server
EAP Extensible Authentication Protocol
HTTP Hypertext Transfer Protocol
IoT Internet of Things
IP Internet Protocol
MAC Medium Access Control
OWE Opportunistic Wireless Encryption
P2P Peer-to-peer
PC Personal Computer
RTOS Real-Time Operation
SAE Simultaneous Authentication of Equals
SDK Software Development Kit
SSID Service Set Identifier
STA Station
TKIP Temporal Key Integrity Protocol
USB Universal Serial Bus
WEP Wired Equivalent Privacy
WPA Wi-Fi Protected Access