【已解决】【IPC 5.X】安凯平台使用涂鸦SDK IPC 5.X,使用AP模式配网,手机连上AP热点后一直无法配网

IPC/NVR/可视门铃等具备多媒体能力的设备,扫地机/AGV等机器人设备


User avatar
fallen-queen
Posts: 140

Re: 急需支持【IPC 5.X】安凯平台使用涂鸦SDK IPC 5.X,使用AP模式配网,手机连上AP热点后一直无法配网

可参考如下实现,通过hostapd启动AP模式(WIFI参数可自行根据需要调整),通过udhcpd实现dhcp服务:

Code: Select all

OPERATE_RET tuya_adapter_wifi_ap_start(IN CONST WF_AP_CFG_IF_S *cfg)
{
    if((cfg == NULL) || (NULL == cfg->ssid) || (NULL == cfg->passwd) || (0 == strlen(cfg->ssid)))
    {
        printf("ap cfg null or ssid null \n");
        return OPRT_INVALID_PARM;
    }
    printf("Start AP SSID:%s passwd:%s\r\n", cfg->ssid, cfg->passwd);

exec_cmd("killall -9 udhcpc; killall -9 wpa_supplicant");
sleep(2);

char FileName[128];
memset(FileName, 0, sizeof(FileName));
snprintf(FileName, sizeof(FileName), "%s/udhcpd.conf", IPC_APP_STORAGE_PATH);

printf("path:%s\n", FileName);

FILE *pFile = NULL;
pFile = fopen(FileName, "wb");
if (pFile != NULL) {
    fprintf(pFile, "start		192.168.176.20\n");
    fprintf(pFile, "end		192.168.176.254\n");
    fprintf(pFile, "interface	%s\n", WLAN_DEV);
    fprintf(pFile, "option	subnet	255.255.255.0\n");

    fprintf(pFile, "opt	router	192.168.176.1\n");
    fprintf(pFile, "option	lease	864000	\n");
    fclose(pFile);
}

memset(FileName, 0, sizeof(FileName));
snprintf(FileName, sizeof(FileName), "%s/hostapd.conf", IPC_APP_STORAGE_PATH);

printf("path:%s\n", FileName);
pFile = fopen(FileName, "wb");
if (pFile != NULL) {
    fprintf(pFile, "interface=%s\n", WLAN_DEV);
    fprintf(pFile, "ssid=%s\n", cfg->ssid);
    fprintf(pFile, "driver=nl80211\n");
    fprintf(pFile, "hw_mode=g\n");
    fprintf(pFile, "channel=3\n");
    fprintf(pFile, "auth_algs=1\n");
    fprintf(pFile, "ignore_broadcast_ssid=0\n");
    fprintf(pFile, "ieee80211n=1\n");
    fprintf(pFile, "logger_syslog=-1\n");
    fprintf(pFile, "logger_syslog_level=2\n");
    fprintf(pFile, "logger_stdout=-1\n");
    fprintf(pFile, "logger_stdout_level=2\n");
    fprintf(pFile, "ctrl_interface=/var/run/hostapd\n");
    fprintf(pFile, "ctrl_interface_group=0\n");
    fprintf(pFile, "country_code=CN\n");
    fprintf(pFile, "rts_threshold=2347\n");
    fprintf(pFile, "wmm_enabled=1\n");
    fprintf(pFile, "wmm_ac_bk_cwmin=4\n");
    fprintf(pFile, "wmm_ac_bk_cwmax=10\n");
    fprintf(pFile, "wmm_ac_bk_aifs=7\n");
    fprintf(pFile, "wmm_ac_bk_txop_limit=0\n");
    fprintf(pFile, "wmm_ac_bk_acm=0\n");
    fprintf(pFile, "wmm_ac_be_aifs=3\n");
    fprintf(pFile, "wmm_ac_be_cwmin=4\n");
    fprintf(pFile, "wmm_ac_be_cwmax=10\n");
    fprintf(pFile, "wmm_ac_be_txop_limit=0\n");
    fprintf(pFile, "wmm_ac_be_acm=0\n");
    fprintf(pFile, "wmm_ac_vi_aifs=2\n");
    fprintf(pFile, "wmm_ac_vi_cwmin=3\n");
    fprintf(pFile, "wmm_ac_vi_cwmax=4\n");
    fprintf(pFile, "wmm_ac_vi_txop_limit=94\n");
    fprintf(pFile, "wmm_ac_vi_acm=0\n");
    fprintf(pFile, "wmm_ac_vo_aifs=2\n");
    fprintf(pFile, "wmm_ac_vo_cwmin=2\n");
    fprintf(pFile, "wmm_ac_vo_cwmax=3\n");
    fprintf(pFile, "wmm_ac_vo_txop_limit=47\n");
    fprintf(pFile, "wmm_ac_vo_acm=0\n");
    fprintf(pFile, "eapol_key_index_workaround=0\n");
    fprintf(pFile, "own_ip_addr=127.0.0.1\n");

    if (0 == strlen(cfg->passwd)) {
        fprintf(pFile, "wpa=0\n");
    } else {
        fprintf(pFile, "wpa=2\n");
        fprintf(pFile, "wpa_passphrase=%s\n", cfg->passwd);
        fprintf(pFile, "wpa_key_mgmt=WPA-PSK\n");
        fprintf(pFile, "wpa_pairwise=CCMP\n");
        fprintf(pFile, "rsn_pairwise=CCMP\n");
    }
    fclose(pFile);
} else {
    printf("fopen file %s error : %s\n", FileName, strerror(errno));
    return OPRT_COM_ERROR;
}

char cmdName[128];
exec_cmd("mkdir -pv /var/run");
memset(cmdName, 0, sizeof(cmdName));
snprintf(cmdName, sizeof(cmdName), "hostapd %s/hostapd.conf &", IPC_APP_STORAGE_PATH);
exec_cmd(cmdName);
exec_cmd("mkdir -p /var/lib/misc");
exec_cmd("touch /var/lib/misc/udhcpd.leases");

memset(cmdName, 0, sizeof(cmdName));
snprintf(cmdName, sizeof(cmdName), "ifconfig %s 192.168.176.1 up", WLAN_DEV);
exec_cmd(cmdName);
memset(cmdName, 0, sizeof(cmdName));
snprintf(cmdName, sizeof(cmdName), "udhcpd %s/udhcpd.conf", IPC_APP_STORAGE_PATH);
exec_cmd(cmdName);

printf("End AP SSID:%s\n", cfg->ssid);

return OPRT_OK;
}
lingchaoming
Posts: 17

Re: 急需支持【IPC 5.X】安凯平台使用涂鸦SDK IPC 5.X,使用AP模式配网,手机连上AP热点后一直无法配网

fallen-queen 2023年 Feb 16日 09:44

不好意思哈,IP地址写错了,改成192.168.175.1网段哈。
捕获.PNG

把AP模式IP改为192.168.175.1就可以正常配网了,感谢支持~

Post Reply