如何设置ap模式

如何设置线程才可以让ap正常使用, .access_control = SF_WIFI_ACCESS_CONTROL_DISABLE 我在线程模块找不到enable按钮。请问我该如何设置才可以正常使用ap并且让其他的设备可以连接。

  • 你需要调用Wifi Framwork的接口函数provisioningSet来设置,目前我们没有这方面的例程,需要你自己看用户手册来编写.具体的参考手册是SSP的用户手册,手册的链接如下:
    china.renesasrulz.com/.../71
  • In reply to yihua:

    您好,还有一个问题就是,我把WiFi应用例程里控制台模块和代码全部删除,并且设置了密码 但是WiFi一直无法连接这是什么原因呢,向您请教。
  • In reply to yyk:

    只看你的描述,没法知道是哪里的原因,方便的话把你的代码传上来,我看一下
  • In reply to yihua:

    你好,感谢你的回复。

    我把例程改为了这样的话,可以搜到有一个WiFi热点,但是它无法连接。我很疑惑,是IP地址的问题吗?(线程模块于WiFi框架例程的是类似的只是从client变为了server)

    www2.renesas.cn/.../D6001068.html)

    #include "wifi_app_thread.h"
    #include "utility.h"
    /***********************************************************************************************************************
    * static functions
    **********************************************************************************************************************/

    static int wait_for_link(void); /* Check on NetX IP Link enable */
    static int wifi_module_provision(void); /* Provision the Wi-Fi module */
    static void start_dhcp_client (void); /* Start DHCP server and acquire the assigned IP address */

    #define SERVER_IP IP_ADDRESS(192, 168, 10, 1)
    #define SERVER_SUBNET_MASK IP_ADDRESS(255, 255, 255, 0)
    #define SERVER_INTERFACE_INDEX 0
    #define SERVER_START_IP_ADDRESS_LIST IP_ADDRESS(192, 168, 10, 2)
    #define SERVER_END_IP_ADDRESS_LIST IP_ADDRESS(192, 168, 10, 10)
    /***********************************************************************************************************************
    * @brief wait_for_link function
    *
    * This function check the network link status
    ***********************************************************************************************************************/

    static int wait_for_link(void)
    {
    UINT status = 0;
    ULONG ip_status;
    uint8_t retry_cnt = 0;
    UINT addresses_added;
    nx_dhcp_create_server_ip_address_list(&g_dhcp_server0,0,SERVER_START_IP_ADDRESS_LIST,SERVER_END_IP_ADDRESS_LIST,&addresses_added);
    /** Wait for initialization to finish. */
    do {
    status = nx_ip_interface_status_check(&g_ip0, 0, NX_IP_LINK_ENABLED, &ip_status, 100);

    }while((status != NX_SUCCESS) && (retry_cnt < MAX_RETRY_CNT));

    if(retry_cnt >= MAX_RETRY_CNT)
    {
    print_to_console ("\r\nNetX IP interface NX_IP_LINK_ENABLE check failed.\r\n");
    APP_ERR_TRAP(status);
    return 1;
    }
    else
    return 0;
    }
    /***********************************************************************************************************************
    * @brief wifi_module_provision function
    *
    * This function provisions the Wi-Fi module
    ***********************************************************************************************************************/

    static int wifi_module_provision(void)
    {
    sf_wifi_provisioning_t g_provision_info;
    uint8_t wifimsg_from_queue[UX_DEMO_BUFFER_SIZE];
    wifi_queue_payload_t *msg;
    ssp_err_t ssp_err = SSP_SUCCESS;

    /** Set other provisioning configuration */
    g_provision_info.mode = SF_WIFI_INTERFACE_MODE_AP;
    g_provision_info.security = SF_WIFI_SECURITY_TYPE_WPA2; /* change this setting to work with other Security types*/
    g_provision_info.encryption = SF_WIFI_ENCRYPTION_TYPE_AUTO;
    strcpy((char *)&g_provision_info.ssid, "YYk");
    strcpy((char *)&g_provision_info.key,"12345678");
    tx_queue_receive(&g_wifi_queue, &wifimsg_from_queue, TX_WAIT_FOREVER);
    msg = (wifi_queue_payload_t*)&wifimsg_from_queue;

    if(msg->ap_ssid != NULL && msg->ap_pwd != NULL)
    {

    }

    /*call the Wi-Fi module provision API*/
    ssp_err = g_sf_wifi0.p_api->provisioningSet(g_sf_wifi0.p_ctrl, &g_provision_info);
    nx_dhcp_set_interface_network_parameters(&g_dhcp_server0, SERVER_INTERFACE_INDEX, NX_DHCP_SUBNET_MASK, SERVER_IP, SERVER_IP);
    if(ssp_err)
    {
    print_to_console ("\r\n\r\nYour Wi-Fi module provision failed.");
    print_to_console ("\r\nPlease check your network connection, SSID and Password.\r\n");
    print_to_console ("\r\nYou will need to restart the MCU to provision the Wi-Fi module.\r\n");
    return 1;
    }
    else
    {
    print_to_console ("\r\n\r\nYour Wi-Fi module is provisioned.\r\n");
    return 0;
    }

    }
    /***********************************************************************************************************************
    * @brief start_dhcp_client function
    *
    * This function starts the dhcp client and obtaines the IP address
    ***********************************************************************************************************************/

    static void start_dhcp_client (void)
    {
    ULONG ip0_ip_address = 0;
    UINT ip_status;
    UINT ret;
    char str[64];
    ULONG ip0_mask = 0;
    uint8_t retry_cnt = 0;

    /* start DHCP client */
    ret = nx_dhcp_server_start (&g_dhcp_server0);
    if(ret != 0)
    {
    print_to_console ("\r\nStart DHCP client failed!");
    APP_ERR_TRAP(ret);
    }

    /* check for NX_IP_ADDRESS_RESOLVED */
    do {
    ret = nx_ip_status_check(&g_ip0, NX_IP_ADDRESS_RESOLVED, (ULONG *) &ip_status, 100);
    retry_cnt++;
    }while((ret != NX_SUCCESS) && (ip_status != NX_IP_ADDRESS_RESOLVED )&& (retry_cnt < MAX_RETRY_CNT));


    if(retry_cnt >= MAX_RETRY_CNT)
    {
    print_to_console ("\r\nWi-Fi module IP Address is not resolved!");
    APP_ERR_TRAP(ret);
    }

    /* retrieve the IP address */
    ret = nx_ip_interface_address_get(&g_ip0,0,&ip0_ip_address,&ip0_mask);

    if (ret != NX_SUCCESS)
    {
    print_to_console ("\r\nWi-Fi module IP Address is not received.\r\n");
    APP_ERR_TRAP(ret);
    }

    /* report IP address to user */
    if(ret == NX_SUCCESS)
    {
    print_to_console ("\r\nWi-Fi module IP Address is resolved.\r\n");
    }

    sprintf(str, "IP ADDRESS is: %d.%d.%d.%d \n\r", (int)(ip0_ip_address>>24), (int)(ip0_ip_address>>16)&0xFF, (int)(ip0_ip_address>>8)&0xFF, (int)(ip0_ip_address)&0xFF );

    print_to_console ("\r\n");
    print_to_console (str);
    print_to_console ("\r\n");
    print_to_console ("\r\nYou can ping this IP address to verify the network connection.\r\n");
    print_to_console ("\r\nPlease note you will need to restart the CPU to provision with another AP.\r\n");

    }
    /***********************************************************************************************************************
    * @brief wifi_app_thread_entry function
    *
    * This function establish the network link, provision the Wi-Fi module and start the dhcp client
    ***********************************************************************************************************************/
    void wifi_app_thread_entry(void)
    {

    int returnstatus = 0;
    returnstatus = wait_for_link(); /*wait for the network link to establish*/
    if (returnstatus == 0) /* network link is established */
    {
    returnstatus = wifi_module_provision(); /*provision the Wi-Fi module */
    if (returnstatus == 0) /* Wi-Fi module is provisioned */
    start_dhcp_client(); /*start the dhcp client and obtain the IP address*/
    }

    while(1)
    {
    tx_thread_sleep(200);
    }

    }

     

     

    还有就是如果我运行这样的例程,将没有任何反应,似乎是线程一直未被使用。如果能给我一些指导,我将感激不尽。

    #include "net_thread.h"

    #define SERVER_WIFI_CHANNEL 11
    #define SERVER_WIFI_SSID "SynergyAP"
    #define SERVER_WIFI_KEY "RenesasRulz11"

    #define CLIENT_WIFI_CHANNEL 11
    #define CLIENT_WIFI_SSID "3_1lab"
    #define CLIENT_WIFI_KEY "1234567890lab"

    #define SERVER_IP IP_ADDRESS(192, 168, 10, 1)
    #define SERVER_SUBNET_MASK IP_ADDRESS(255, 255, 255, 0)
    #define SERVER_INTERFACE_INDEX 0
    #define SERVER_START_IP_ADDRESS_LIST IP_ADDRESS(192, 168, 10, 2)
    #define SERVER_END_IP_ADDRESS_LIST IP_ADDRESS(192, 168, 10, 10)

    extern void initialise_monitor_handles();


    void net_wifi_init(NX_IP * p_ip);
    void net_wifi_callback(sf_wifi_callback_args_t * p_args);
    void net_wifi_provision(sf_wifi_interface_mode_t mode, uint8_t channel, char const * p_ssid, char const * p_key);
    void net_wifi_dhcp_client_start(NX_DHCP * p_client, NX_IP * p_ip, ULONG * p_ip_address, ULONG * p_network_mask);
    void net_wifi_dhcp_client_stop(NX_DHCP * p_client);
    void net_wifi_dhcp_server_start(NX_DHCP_SERVER * p_server);
    void net_wifi_dhcp_server_stop(NX_DHCP_SERVER * p_server);

    void net_wifi_init(NX_IP * p_ip)
    {
    UINT status;
    ULONG ip_status;

    do
    {
    status = nx_ip_status_check(p_ip, NX_IP_LINK_ENABLED, &ip_status, 100);
    } while (status != NX_SUCCESS);
    }

    void net_wifi_callback(sf_wifi_callback_args_t * p_args)
    {
    SSP_PARAMETER_NOT_USED(p_args);
    }


    void net_wifi_provision(sf_wifi_interface_mode_t mode, uint8_t channel, char const * p_ssid, char const * p_key)
    {
    sf_wifi_provisioning_t g_provision_info;
    ssp_err_t result;

    g_provision_info.channel = channel;
    g_provision_info.mode = mode;
    g_provision_info.security = SF_WIFI_SECURITY_TYPE_WPA2;
    g_provision_info.encryption = SF_WIFI_ENCRYPTION_TYPE_AUTO;
    g_provision_info.p_callback = net_wifi_callback;

    strcpy((char *) &g_provision_info.ssid, (char const *) p_ssid);
    strcpy((char *) &g_provision_info.key, (char const *) p_key);

    do
    {
    result = g_sf_wifi.p_api->provisioningSet(g_sf_wifi.p_ctrl, &g_provision_info);
    } while (result != SSP_SUCCESS);
    }

    void net_wifi_dhcp_client_start(NX_DHCP * p_client, NX_IP * p_ip, ULONG * p_ip_address, ULONG * p_network_mask)
    {
    UINT status;
    ULONG ip_status;

    net_wifi_provision(SF_WIFI_INTERFACE_MODE_CLIENT, CLIENT_WIFI_CHANNEL, CLIENT_WIFI_SSID, CLIENT_WIFI_KEY);
    dhcp_client_init();

    status = nx_dhcp_start(p_client);

    if (NX_SUCCESS != status)
    {
    __BKPT(0);
    }

    do
    {
    status = nx_ip_status_check(p_ip, NX_IP_ADDRESS_RESOLVED, &ip_status, 20);
    } while (status != NX_SUCCESS);

    status = nx_ip_address_get(p_ip, p_ip_address, p_network_mask);

    if (NX_SUCCESS != status)
    {
    __BKPT(0);
    }
    }

    void net_wifi_dhcp_client_stop(NX_DHCP * p_client)
    {
    nx_dhcp_delete(p_client);
    }

    void net_wifi_dhcp_server_start(NX_DHCP_SERVER * p_server)
    {
    UINT status;
    UINT addresses_added;

    dhcp_server_init();

    status = nx_ip_address_set(p_server->nx_dhcp_ip_ptr, SERVER_IP, SERVER_SUBNET_MASK);

    if (status != NX_SUCCESS)
    {
    __BKPT(0);
    }

    /* Assign IP addresses from the given range. */
    status = nx_dhcp_create_server_ip_address_list(p_server,
    SERVER_INTERFACE_INDEX,
    SERVER_START_IP_ADDRESS_LIST,
    SERVER_END_IP_ADDRESS_LIST,
    &addresses_added);
    if (status != NX_SUCCESS)
    {
    __BKPT(0);
    }

    /* Set network parameters returned by the DHCP server. */
    status = nx_dhcp_set_interface_network_parameters(p_server, SERVER_INTERFACE_INDEX, NX_DHCP_SUBNET_MASK, SERVER_IP, SERVER_IP);

    if (status != NX_SUCCESS)
    {
    __BKPT(0);
    }

    net_wifi_provision(SF_WIFI_INTERFACE_MODE_AP, SERVER_WIFI_CHANNEL, SERVER_WIFI_SSID, SERVER_WIFI_KEY);

    /* Start the DHCP Server. */
    status = nx_dhcp_server_start(p_server);

    if (status != NX_SUCCESS)
    {
    __BKPT(0);
    }
    }

    void net_wifi_dhcp_server_stop(NX_DHCP_SERVER * p_server)
    {
    nx_dhcp_server_delete(p_server);
    }

    /* Net Thread entry function */
    void net_thread_entry(void)
    {
    ULONG ip_address;
    ULONG network_mask;

    initialise_monitor_handles();

    net_wifi_init(&g_ip);

    net_wifi_dhcp_client_start(&g_dhcp_client, &g_ip, &ip_address, &network_mask);
    net_wifi_dhcp_client_stop(&g_dhcp_client);

    printf("%lx\n%lx\n", ip_address, network_mask);

    net_wifi_dhcp_server_start(&g_dhcp_server);

    while (1)
    {
    tx_thread_sleep (1);
    }

    //net_wifi_dhcp_server_stop(&g_dhcp_server);
    }

  • In reply to yyk:

    先说第一个例程,我看到你程序里有这句话tx_queue_receive(&g_wifi_queue, &wifimsg_from_queue, TX_WAIT_FOREVER);
    把这个注释掉后,然后把DHCP改成客户端看能否连接上,有可能程序在这里被阻塞了。
    第二个线程,不知道你的程序DHCP客户端是否正常工作了,如果工作了,把DHCP客户端的功能删除后,再试一下服务器程序
  • In reply to yihua:

    就是第一个例程,WiFi热点可以打开,并且可以搜到,但是连接不上。然后第二个例程是,客户端也没有打开,至少WiFi热点上并没有显示它的接入。
  • In reply to yihua:

    它一直运行在一个线程上

  • In reply to yyk:

    第一个例程,你使用的是nx_dhcp_server_start ,你应该使用nx_dhcp_start,然后要确认在配置器中设置使用的是DHCP client
  • In reply to yihua:

    也就是说DHCP客户端也可以设置为AP模式,作为一个热点?
  • In reply to yyk:

    不好意思我理解错了,我以为你是要使用WiFi连接到固定的路由器,
    做热点的功能是WiFi模块的功能,你只要设置WiFi模式的工作模式是AP,就可以作热点,但是需要DHCP服务器给从设备分配IP地址,你连接不上可能是DHCP服务器没有工作,但是我没有DHCP服务器的例程,你可以参考下面链接里的关于DHCP服务器的文档
    china.renesasrulz.com/.../72
  • In reply to yihua:

    非常感谢,我马上去看一下,如果有问题,还希望能给予我一些指点,在此谢过。
  • In reply to yyk:

    我做了一个热点的例程,可以用计算机连接,并且可以ping到
    热点的名字是:MYAP_WIFI_SSID,密码是:12345678,AP的ip是192.168.1.0(可以ping这个地址)
    主要的代码在 WiFi AP Thread,你参考一下。
    下面是链接
    china.renesasrulz.com/.../90
  • In reply to yihua:

    非常感谢你。向您致敬。
  • In reply to yihua:

    您好 宜华

      非常抱歉又打扰您了,首先我感谢您提供的ap例程,它确实可以连接上,而且没什么毛病,但是我却ping不到192.168.1.0,而且手机可以快速连接到热点,但是电脑连接却十分缓慢,我弄了一段时间,实在是找不到原因,还请您多指教。这是什么原因呢?

  • In reply to yyk:

    是不是跟你的计算机的网络设置有关,不要设置代理服务器信息,这是我的网络配置选项