Router Management

Last Updated on : 2024-06-24 10:12:31download

This topic describes router management with a mobile app, including Wi-Fi settings, guest Wi-Fi, parental controls, mesh networking, port mapping, and device management.

Pair the router

Choose the gateway, router, and pairing method on the mobile app, and then select the router’s Wi-Fi access point as instructed. Once the router is discovered, configure the internet connection type, which can be PPPoE, DHCP, or static IP. After the setup is complete, the router will connect to the internet and get activated.

  1. Register the WAN setting callback using tuya_router_reg_wan_setting_cb.

    OPERATE_RET user_router_srv_start(IN ty_cJSON *cfg)
    {
        ...
        UINT_T timeout= 20;
        tuya_router_wan_setting_report_net_stat(FALSE);
        TUYA_ROUTER_WAN_SETTING_CBS_S wan_setting_cbs = {
            .wan_conn_query_cb = wan_setting_query_cb,
            .wan_conn_set_cb   = wan_setting_set_cb
        };
        tuya_router_reg_wan_setting_cb(timeout, &wan_setting_cbs);
        ...
    }
    
  2. When the mobile app detects the router, it will query the supported WAN configuration types, triggering wan_conn_query_cb. Call tuya_router_wan_setting_query_resp to return the supported types. Here is an example:

    VOID wan_setting_query_cb(VOID)
    {
        CHAR_T *wan_type[3] = {
            "PPPOE",
            "DHCP",
            "STATIC_IP"
        };
        tuya_router_wan_setting_query_resp(0, &wan_type, 3);
    }
    
  3. Process WAN settings received from the mobile app in wan_conn_set_cb, as shown below:

    VOID wan_setting_set_cb(IN CONST WAN_CONN_SETTING_INFO *setting)
    {
        WAN_CONN_ERR_CODE_T error_code = WAN_CONN_ERR_CODE_OK;
        switch (setting->wan_conn_type) {
            case  WAN_CONN_TYPE_PPPOE:
                PR_DEBUG("<pppoe: account:%s, password: %s>", setting->pppoe_info.account, setting->pppoe_info.pwd);
                memcpy(&wan_setting, setting, sizeof(WAN_CONN_SETTING_INFO));
                break;
    
            case WAN_CONN_TYPE_DHCP:
                PR_DEBUG("dhcp:");
                memcpy(&wan_setting, setting, sizeof(WAN_CONN_SETTING_INFO));
                break;
    
            case WAN_CONN_TYPE_STATIC_IP:
                PR_DEBUG("static ip");
                PR_DEBUG("ip: %s", setting->static_ip_info.ip);
                PR_DEBUG("mask:%s", setting->static_ip_info.mask);
                PR_DEBUG("gw:%s", setting->static_ip_info.gw);
                PR_DEBUG("pr dns:%s", setting->static_ip_info.primary_dns);
                PR_DEBUG("sec dns:%s", setting->static_ip_info.secondary_dns);
                memcpy(&wan_setting, setting, sizeof(WAN_CONN_SETTING_INFO));
                break;
    
            default:
                PR_DEBUG("not support");
                break;
        }
        ...
        tuya_router_wan_setting_set_resp(wan_setting.wan_conn_type, 0);
        ...
    }
    

Manage devices connected to the router

Manage and control devices connected to the router, including device list display, network details, and upload and download speeds.

  1. Register callbacks using tuya_router_svc_init. Example:

    OPERATE_RET user_router_srv_start(IN ty_cJSON *cfg)
    {
        TUYA_ROUTER_CBS_S router_cbs = {
            .cmd_handle_cb       =   ty_router_cmd_handle_cb,
            .get_source_cb       =   ty_router_get_source_cb,
            .set_source_cb       =   ty_router_set_source_cb,
            .get_hotspot_cb      =   ty_router_get_hotspot_cb,
            .set_hotspot_cb      =   ty_router_set_hotspot_cb,
            .router_query_pwd_cb =   ty_router_query_pwd_cb,
            .router_set_pwd_cb   =   ty_router_set_pwd_cb,
        };
    
        TUYA_ROUTER_STA_CBS_S sta_cbs = {
            .sta_cmd_cb =       ty_router_sta_cmd_cb
        };
        op_ret = tuya_router_svc_init(&router_cbs, &sta_cbs);
        if (op_ret != OPRT_OK) {
            PR_ERR("tuya_router_svc_init faild, [%d]", op_ret);
        }
        ...
    }
    
  2. The mobile app uses cmd_handle_cb to query the router for the supported Wi-Fi access points and the list of online devices connected to the router. Example:

    VOID ty_router_cmd_handle_cb(IN CONST TY_ROUTER_CMD_E cmd)
    {
        TUYA_ROUTER_WIFI_LIST_S wifi_list[3] = {0x0};
        TUYA_ROUTER_DEV_LIST_S dev_list[256] = {0x0};
        int i = 0;
    
        switch (cmd) {
            case TY_ROUTER_CMD_GET_WIFI_LIST:
                strcpy(wifi_list[0].ssid, "netcore");
                wifi_list[0].b_encrypted = TRUE;
                wifi_list[0].signal_strength = TY_WIFI_SIG_HIGH;
                strcpy(wifi_list[1].ssid, "HUA-SAN");
                wifi_list[1].b_encrypted = TRUE;
                wifi_list[1].signal_strength = TY_WIFI_SIG_LOW;
                strcpy(wifi_list[2].ssid, "HUA-WEI");
                tuya_router_rept_wifi_list(2, wifi_list);
                break;
    
            case TY_ROUTER_CMD_GET_ONLINE_LIST:
                for (i = 0; i < 250; i++) {
                    char buf[100] = {0};
                    snprintf(buf, sizeof(buf),"Myphone-%d", i);
                    strcpy(dev_list[i].dev_name, buf);
                    memset(buf, 0, sizeof(buf));
                    snprintf(buf, sizeof(buf),"77:22:33:44:55:%02x", i);
                    strcpy(dev_list[i].mac, buf);
                    memset(buf, 0, sizeof(buf));
                    snprintf(buf, sizeof(buf),"192.168.10.%d", i);
                    strcpy(dev_list[i].ip_addr, buf);
    
                    memset(dev_list[i].upper_router_name, 0, sizeof(dev_list[i].upper_router_name));
                    strcpy(dev_list[i].upper_router_name, "Main");
                    dev_list[i].wifi_types = TY_WIFI_TYPE_5G;
                }
                tuya_router_rept_online_list(250, dev_list);
                break;
            default:
                break;
        }
    }
    
  3. Configure the upload and download speeds using sta_cmd_cb. Example:

    OPERATE_RET ty_router_sta_cmd_cb(IN CONST TY_ROUTER_STA_CMD_E cmd, IN CONST CHAR_T *mac,
            IN CONST TUYA_ROUTER_STA_CONF_S *cfg_value)
    {
        OPERATE_RET ret = OPRT_OK;
        PR_DEBUG("cmd:%d mac:%s\n", cmd, mac);
        switch (cmd) {
            case TY_STA_CMD_ALLOW_NET:
                config.allow = cfg_value->allow;
                PR_DEBUG("allow_network: %d", config.allow);
                tuya_router_rept_sta_allow_net(mac, config.allow, STA_DPID);
                break;
    
            case TY_STA_CMD_SPEED_LIMIT:
                config.limit = cfg_value->limit;
                PR_DEBUG("network speed limit: %d", config.limit);
                tuya_router_rept_sta_limit(mac, config.limit, STA_DPID);
                break;
    
            case TY_STA_CMD_UP_LIMIT:
                config.up_limit = cfg_value->up_limit;
                strcpy(config.rate_unit, cfg_value->rate_unit);
                PR_DEBUG("max upload speed: %d", config.up_limit);
                tuya_router_rept_sta_up_limit(mac, config.up_limit, STA_DPID);
                break;
    
            case TY_STA_CMD_DOWN_LIMIT:
                config.down_limit = cfg_value->down_limit;
                strcpy(config.rate_unit, cfg_value->rate_unit);
                PR_DEBUG("max down speed: %d", config.down_limit);
                tuya_router_rept_sta_down_limit(mac, config.down_limit, STA_DPID);
                break;
    
            case TY_STA_CMD_RATE_UNIT:
                strcpy(config.rate_unit, cfg_value->rate_unit);
                PR_DEBUG("rate unit: %s", config.rate_unit);
                tuya_router_rept_sta_rate_unit(mac, config.rate_unit, STA_DPID);
                break;
                ...
            default:
                break;
        }
    }
    

Parental controls

Add specific devices to a group, set the allowlist and denylist of target URLs, and specify a time period for internet access.

Set parental controls

  1. tuya_router_family_ctrl_report_dev_list reports the list of devices, which will be displayed on the mobile app for setting up parental controls. Example:

    VOID router_family_ctrl_report_dev_list(VOID)
    {
        FAMILY_CTRL_DEV_LIST_T list[3] = {
            {"11:22:33:44:55:68", "hello_world9"},
            {"66:55:44:33:22:19", "hello_world10"},
            {"66:55:44:33:22:1a", "hello_world11"},
        };
        tuya_router_family_ctrl_report_dev_list(list, 3);
    }
    
  2. Register the parental controls handler using tuya_router_reg_family_ctrl_cb. Example:

    OPERATE_RET user_router_srv_start(IN ty_cJSON *cfg)
    {
        ...
        TUYA_ROUTER_FAMILY_CTRL_CBS_S family_ctrl_cbs = {
            .cfg_cb = family_ctrl_cfg_cb,
            .del_cb = family_ctrl_del_cb
        };
        tuya_router_reg_family_ctrl_cb(&family_ctrl_cbs);
        ...
    }
    
  3. In cfg_cb, the router receives the parental control settings from the mobile app.

    VOID family_ctrl_cfg_cb(IN UINT_T id, IN CONST CHAR_T **mac_list, INT_T mac_num, IN FACTORY_CTRL_URL_T *ctrl_url, IN FACTORY_CTRL_LIMIT_TIME_T *ctrl_time)
    {
        UINT_T i = 0;
        PR_DEBUG("%s, group id:%d, list type:%d", __func__, id, ctrl_url->url_list_type);
        for (i = 0; i < mac_num; i++)
            PR_DEBUG("mac num:%d, mac: %s", mac_num, mac_list[i]);
        if (ctrl_url != NULL) {
            PR_DEBUG("web filter enable:%d", ctrl_url->web_filter_enable);
            if (ctrl_url->url_list_type == URL_WHITE_LIST)
                PR_DEBUG("white list");
            else
                PR_DEBUG("black list");
            for (i = 0; i < ctrl_url->url_num; i++)
                PR_DEBUG("URL: %s, %d", ctrl_url->url_list[i], ctrl_url->url_num);
        }
        if (ctrl_time != NULL) {
            PR_DEBUG("time: %s", ctrl_time->limit_time);
        }
    }
    

    ctrl_time is a JSON string, representing a control rule for a specific time period, as shown below.

    [{
        "enable": 1,
        "start_time": "21:30",
        "stop_time": "07:00",
        "weekdays": "0100000"
    }]
    
    • enable: 1 for enabling the rule. 0 for disabling the rule.

    • start_time: In the format HH:MM, 24-hour clock.

    • stop_time: In the format HH:MM, 24-hour clock.

    • weekdays: The first bit represents Sunday, the second bit represents Monday, and so forth.

Delete parental controls

del_cb deletes a set of parental controls.

VOID family_ctrl_del_cb(UINT_T id)
{
    PR_DEBUG("group id:%d will be deleted", id);
    /* TODO: */
}

Mesh networking

The mobile app can send a networking request to establish a mesh network among routers. When the router receives the networking request, it returns the list of nearby routers to the mobile app. Users can select the routers to create a mesh network and wait for the networking process to finish.

OPERATE_RET user_router_srv_start(IN ty_cJSON *cfg)
{
    OPERATE_RET op_ret = OPRT_OK;
    ...
    /* wifi mesh */
    TUYA_ROUTER_WIFI_MESH_CBS_S mesh_cbs = {
        .enable_cb = mesh_enable_cb,
        .confirm_slave_routers_cb = confirm_mesh_salve_routers_cb,
        .query_cb = mesh_query_cb,
        .chg_router_name_cb = mesh_chg_name
    };
    tuya_router_reg_wifi_mesh_cb(&mesh_cbs);
    ...
}

enable_cb specifies whether to enable mesh networking.

VOID mesh_enable_cb(IN BOOL_T enable)
{
    PR_DEBUG("wifi mesh enable:%d", enable);
}

The router responds with the enablement result through tuya_router_wifi_mesh_cmd_enable_resp and begins scanning for nearby routers. Report the list of nearby routers to the mobile app through the tuya_router_wifi_mesh_report_scanned_routers_list.

After users select the routers on the mobile app to form a mesh network, confirm_slave_routers_cb will be invoked. Example:

VOID confirm_mesh_salve_routers_cb(IN UINT_T *id_list, IN UINT_T num)
{
    UINT_T i = 0;
    router_id_list.router_id_num = num;
    for (i = 0; i < num; i++) {
        router_id_list.list[i] = id_list[i];
    }
}

To minimize data transmission, ensure that the response ID for the router matches the reported router ID.

When users change the device name of the main or secondary router on the mobile app, mesh_chg_name will be invoked.

VOID mesh_chg_name(CHAR_T *mac, CHAR_T *router_name)
{
    PR_DEBUG("mac: %s, router name:%s", mac, router_name);
}

Update main and secondary routers via OTA

Update the main and secondary routers in the mesh network using the mobile app.

OTA updates

  1. Register the OTA update callback for the main and secondary routers.

    OPERATE_RET user_router_srv_start(IN ty_cJSON *cfg)
    {
        OPERATE_RET op_ret = OPRT_OK;
        ...
        /* master router & slave routers ota info*/
        TUYA_ROUTER_OTA_CBS_S ota_cbs = {
            .query_cb = routers_ota_query_cb,
            .notify_ota_cb = routers_notify_cb
        };
        tuya_router_reg_ota_cb(&ota_cbs);
        ...
    }
    
  2. When users check the version of the main and secondary routers on the mobile app, query_cb will be invoked. The main router collects the version information and reports it using tuya_router_report_ota_info.

    VOID routers_mesh_ver_info_report(int st)
    {
        strcpy(master_ota_info.dev_name, "master");
        master_ota_info.ota_info[0].tp = 0;
        master_ota_info.ota_info[0].upg_status = st;
        strcpy(master_ota_info.ota_info[0].fw_ver, "1.2.0");
    
        slave_ota_info_list[0].dev_id = 1;
        strcpy(slave_ota_info_list[0].pid, "xxxx");
        strcpy(slave_ota_info_list[0].uuid, "uuidd39baaba17575011");
        strcpy(slave_ota_info_list[0].dev_name, "slave-1");
        slave_ota_info_list[0].ota_info[0].tp = 0;
        slave_ota_info_list[0].ota_info[0].upg_status = st;
        strcpy(slave_ota_info_list[0].ota_info[0].fw_ver, "1.2.0");
        strcpy(slave_ota_info_list[0].ota_info[0].fw_key, "yyyyyyyy");
    
        strcpy(slave_ota_info_list[1].pid, "xxxx");
        strcpy(slave_ota_info_list[1].uuid, "uuidda80b094a42cd083");
        strcpy(slave_ota_info_list[1].dev_name, "slave-2");
        slave_ota_info_list[1].dev_id = 2;
        slave_ota_info_list[1].ota_info[0].tp = 0;
        slave_ota_info_list[1].ota_info[0].upg_status = st;
        strcpy(slave_ota_info_list[1].ota_info[0].fw_ver, "1.2.0");
        strcpy(slave_ota_info_list[1].ota_info[0].fw_key, "yyyyyyyy");
    
        tuya_router_report_ota_info(0, &master_ota_info, &slave_ota_info_list, 2);
    }
    

    You need to upload the firmware for the main and secondary routers to the Tuya Developer Platform.

  3. When an update is available, the mobile app will send a notification to the router, triggering notify_ota_cb.

    VOID routers_notify_cb(IN ROUTERS_OTA_INFO_T *master_ota_info, IN ROUTERS_OTA_INFO_T *slave_ota_info_list, IN UINT_T slave_ota_info_num)
    {
        PR_DEBUG("master router ota info:");
        PR_DEBUG("pid: %s", master_ota_info->pid);
        PR_DEBUG("uuid: %s", master_ota_info->uuid);
        PR_DEBUG("fw_key: %s", master_ota_info->ota_info[0].fw_key);
        PR_DEBUG("sw_ver: %s", master_ota_info->ota_info[0].fw_ver);
        PR_DEBUG("fw_url: %s", master_ota_info->ota_info[0].fw_url);
        PR_DEBUG("fw_hmac: %s", master_ota_info->ota_info[0].fw_hmac);
        PR_DEBUG("file size: %d", master_ota_info->ota_info[0].file_size);
    
        PR_DEBUG("slave router ota info:");
        int i = 0;
        for (i = 0; i < slave_ota_info_num; i++) {
            PR_DEBUG("#%d", i);
            PR_DEBUG("pid: %s", slave_ota_info_list[i].pid);
            PR_DEBUG("uuid: %s", slave_ota_info_list[i].uuid);
            PR_DEBUG("dev_id: %d", slave_ota_info_list[i].dev_id);
            PR_DEBUG("fw_key: %s", slave_ota_info_list[i].ota_info[0].fw_key);
            PR_DEBUG("sw_ver: %s", slave_ota_info_list[i].ota_info[0].fw_ver);
            PR_DEBUG("fw_url: %s", slave_ota_info_list[i].ota_info[0].fw_url);
            PR_DEBUG("fw_hmac: %s", slave_ota_info_list[i].ota_info[0].fw_hmac);
            PR_DEBUG("file size: %d", slave_ota_info_list[i].ota_info[0].file_size);
        }
    }
    

    In this callback, the main router receives update information for the main and secondary routers, which includes the URL, version number, file size, and HMAC. The main router distributes this information to the secondary routers. The secondary router downloads the update from a specific URL, verifies the file size and HMAC, and then installs it. During the app waiting time, the main router reports the update results of both the main and secondary routers through tuya_router_report_ota_info.

Verify firmware HMAC

The main and secondary routers download the firmware update from a specific URL.

  1. Verify if file_size is acceptable.
  2. Compute the SHA-256 hash of the downloaded file and convert it to uppercase.
  3. Use the device UUID as the key to compute the HMAC SHA-256 value, and then compare it with the HMAC to authenticate the validity of the firmware.

Example script for computing HMAC:

#!/bin/sh

[ ! $# -eq 2 ] && {
    echo "$0 [file] [uuid]"
    exit -1
}

sum=$(sha256sum $1 | cut -d ' ' -f 1 | tr [:lower:] [:upper:])
echo -n "$sum" | openssl dgst -sha256 -hmac "$2" | cut -d ' ' -f 2

Port mapping

Users can set port mapping for their router on the mobile app.

  1. Register the callback for the port forwarding handler using tuya_router_reg_port_forwards_cb. Example:

    OPERATE_RET user_router_srv_start(IN ty_cJSON *cfg)
    {
        OPERATE_RET op_ret = OPRT_OK;
        ...
        /* port forward */
        TUYA_ROUTER_PORT_FORWARDS_CBS_S port_forwards_cbs = {
            .cmd_add_cb = port_forwards_add_cb,
            .cmd_del_cb = port_forwards_del_cb,
            .cmd_query_cb = port_forwards_query_cb,
            .cmd_change_cb = port_forwards_change_cb
        };
        tuya_router_reg_port_forwards_cb(&port_forwards_cbs);
        ...
    }
    
  2. Adding a port mapping will trigger cmd_add_cb.

    VOID port_forwards_add_cb(CONST PORT_FORWARDS_RULE_T *rule_list)
    {
        PR_DEBUG("ruld_id:%d", rule_list->rule_id);
        PR_DEBUG("dev_name:%s", rule_list->dev_name);
        PR_DEBUG("ip_addr:%s", rule_list->ip_addr);
        PR_DEBUG("rule_name:%s", rule_list->rule_name);
        PR_DEBUG("dst_port:%d", rule_list->dst_port);
        PR_DEBUG("src_port:%d", rule_list->src_port);
        PR_DEBUG("proto:%s", rule_list->proto);
    
        UINT_T num = get_rule_num();
        port_forward_rule_node_t *new_node = (port_forward_rule_node_t *)malloc(sizeof(port_forward_rule_node_t));
        memset(new_node, 0, sizeof(port_forward_rule_node_t));
        memcpy(&new_node->rule, rule_list, sizeof(PORT_FORWARDS_RULE_T));
        new_node->rule.rule_id = num;
        tuya_list_add_tail(&new_node->node, &port_forward_rule_list);
        PR_DEBUG("this is new, rule_id:%d!!!!", new_node->rule.rule_id);
    }
    
  3. (Optional) Deleting a port mapping will trigger cmd_del_cb.

    VOID port_forwards_del_cb(CONST UINT_T id)
    {
        port_forward_rule_node_t *one_rule_node = NULL;
        struct tuya_list_head *p = NULL;
        struct tuya_list_head *n = NULL;
        tuya_list_for_each_safe(p, n, &port_forward_rule_list) {
            one_rule_node = tuya_list_entry(p, port_forward_rule_node_t, node);
            if (one_rule_node->rule.rule_id == id) {
                PR_DEBUG("deleted %d", id);
                tuya_list_del(&one_rule_node->node);
                free(one_rule_node);
                port_forward_del = TRUE;
                return;
            }
        }
        PR_DEBUG("not found %d", id);
    }
    
  4. (Optional) Modifying a port mapping will trigger cmd_chg_cb.

    VOID port_forwards_change_cb(CONST PORT_FORWARDS_RULE_T *rule_list)
    {
        PR_DEBUG("ruld_id:%d", rule_list->rule_id);
        PR_DEBUG("dev_name:%s", rule_list->dev_name);
        PR_DEBUG("ip_addr:%s", rule_list->ip_addr);
        PR_DEBUG("rule_name:%s", rule_list->rule_name);
        PR_DEBUG("dst_port:%d", rule_list->dst_port);
        PR_DEBUG("src_port:%d", rule_list->src_port);
        PR_DEBUG("proto:%s", rule_list->proto);
    
        port_forward_change = TRUE;
        port_forward_rule_node_t *one_rule_node = NULL;
        struct tuya_list_head *p = NULL;
        struct tuya_list_head *n = NULL;
        tuya_list_for_each_safe(p, n, &port_forward_rule_list) {
            one_rule_node = tuya_list_entry(p, port_forward_rule_node_t, node);
            if (one_rule_node->rule.rule_id == rule_list->rule_id) {
                memcpy(&one_rule_node->rule, rule_list, sizeof(PORT_FORWARDS_RULE_T));
                strcpy(one_rule_node->rule.proto, rule_list->proto);
                strcpy(one_rule_node->rule.rule_name, rule_list->rule_name);
                PR_DEBUG("this is  changed!, %d", one_rule_node->rule.rule_id);
                return;
            }
        }
    }
    

    The router should store the port mappings.

Guest network

To prevent the leakage of home Wi-Fi information, a separate network is created for guests.

Register the guest callback. Example:

OPERATE_RET user_router_srv_start(IN ty_cJSON *cfg)
{
    OPERATE_RET op_ret = OPRT_OK;
    ...
    /* guest network*/
    TUYA_ROUTER_GEUST_NETWORK_CBS_S guest_network_cbs = {
        .cfg_cb = guest_network_cfg_cb,
        .query_cb = guest_network_query_cb
    };
    op_ret = tuya_router_reg_guest_network_cb(&guest_network_cbs);
    ...
}

cfg_cb handles the guest network configuration received from the mobile app. It returns the guest network settings, as shown below.

VOID guest_network_cfg_cb(CONST GUEST_NETWORK_CFG_T *cfg)
{
    PR_DEBUG("enable: %d", cfg->enable);
    PR_DEBUG("ssid: %s", cfg->ssid);
    PR_DEBUG("password: %s", cfg->password);
    PR_DEBUG("period: %d", cfg->period_time);
}

query_cb is the callback for querying the guest network settings. After receiving this callback, the router reports the guest network information, as shown below:

VOID guest_network_cfg_report(VOID)
{
    GUEST_NETWORK_CFG_T guest_network_cfg = {
        .enable = 1, /* Enablement: 1 for enable. 0 for disable. */
        .ssid = "test_ssid",
        .password = "test_password",
        .period_time = 0 /* Unit: hour */
    };
    tuya_router_guest_network_query_resp(0, &guest_network_cfg);
}

Router data points (DPs)

Create a router product on the Tuya Developer Platform, with some features implemented through DP.

DP ID Identifier Name Description
1 master_information Main router information -
2 upload_rate Upload speed Value type. DP reporting is required.
3 download_rate Download speed -
4 speed_test Speed test Enum type. DP reporting is required.
5 name_24g SSID (name) of the 2.4 GHz Wi-Fi String type. DP reporting is required after setup.
6 signal_strength_24g 2.4 GHz Wi-Fi signal strength Enum type ("low","medium","high"). DP reporting is required.
7 route_auth_24g 2.4 GHz Wi-Fi encryption Enum type (none","wpa2psk","wpa_wpa2psk","wpa3_sae"). DP reporting is required after setup.
8 switch_24g 2.4 GHz Wi-Fi toggle DP reporting is required after setup.
9 hide_24g Hide 2.4 GHz Wi-Fi toggle DP reporting is required after setup.
10 name_5G SSID (name) of the 5 GHz Wi-Fi DP reporting is required after setup.
11 signal_strength_5g 5 GHz Wi-Fi signal strength Enum type ("low","medium","high"). DP reporting is required after setup.
12 route_auth_5g 5 GHz Wi-Fi encryption Enum type (none","wpa2psk","wpa_wpa2psk","wpa3_sae"). DP reporting is required after setup.
13 switch_5g 5 GHz Wi-Fi toggle DP reporting is required after setup.
14 hide_5g Hide 5 GHz Wi-Fi toggle DP reporting is required after setup.
15 Station_data Station data Call tuya_router_sta_data_parse to parse the data. See the demo for details.
16 switch_speed_limit Speed limit toggle DP reporting is required after setup.
18 internet_disc_switch Internet disconnection toggle DP reporting is required after setup.
19 access_ctrl_switch Access toggle DP reporting is required after setup.
20 guest_ctrl_switch Guest network toggle DP reporting is required after setup.
23 reboot_data Reboot toggle JSON string. See the reboot description below for the data format. DP reporting is required after setup.
24 wps_switch WPS toggle DP reporting is required after setup.
25 qos_set QoS setting JSON string. See the QoS description below for the data format. DP reporting is required after setup.
26 fast_roaming_switch Fast roaming toggle DP reporting is required after setup.
27 port_forward_switch Port mapping toggle DP reporting is required after setup.
28 upnp_switch UPNP toggle DP reporting is required after setup.
29 dhcp_set DHCP setting JSON string. See the DHCP description below for the data format. DP reporting is required after setup.
30 dns_set DNS setting JSON string. See the DNS description below for the data format. DP reporting is required after setup.
31 indicator Status indicator DP reporting is required after setup.
47 dual_band Dual-band DP reporting is required after setup.
  • QoS setting, in string type. JSON parsing is required after the DP data is received. Format:

    {
       "enable": 1,
       "upload_speed": 112,
       "down_speed": 789,
       "rate_unit":"kb/s"
    }
    
  • DHCP setting, in JSON type. JSON parsing is required after the DP data is received. Format:

    {
       dhcpset: "10.0.11.3"
    }
    
  • DNS setting, in JSON type, as shown below.

    {
       "auto_mode": false,
       "primary_dns_server": "8.8.8.8",
       "secondary_dns_server": "4.4.4.4"
    }
    
  • Reboot setting. Users can schedule router reboots using the mobile app. The data is in raw type. JSON parsing is required after the DP data is received. Format:

    {
       "immediate_restart": false,
       "reboot_timers": [{
          "enable": 1,
          "weekdays": "0100000",
          "time": "18:27"
       }]
    }
    

    weekdays: The first bit represents Sunday, the second bit represents Monday, and so forth. immediate_restart: Specifies whether to reboot immediately.

    • true: Reboot immediately.
    • false: Scheduled reboot. The reboot_timers field applies.
    • Immediate reboot and scheduled reboot can coexist without conflict. When an immediate reboot is triggered, any scheduled reboots will still proceed as planned.