End Product Testing – LAN

Last Updated on : 2024-01-19 05:54:29download

During the manufacturing process, conducting a comprehensive inspection and testing of the end product helps ensure compliance with specified standards and requirements, thereby enhancing quality control.

This topic describes Tuya host-based LAN testing and the corresponding APIs. The implementation code is not provided. The test items may vary depending on the product features, so implement the code according to your needs.

Procedure

  1. Set up the testing router with the SSID tuya_mdev_test4, password 12345678, and channel 6.

  2. Turn on the Tuya host software for end product testing.

    Not all host software supports LAN testing. Check if the host software for your product category supports this feature before development. For more information, see Manufacturing – End Product. To get the testing protocol, submit a service ticket.

  3. Power on the device and scan for and connect to the testing router. After a successful connection, the device, host software, and router create a LAN.

  4. The host software sends testing commands to the device over the LAN.

  5. The device executes the received command and returns the result.

  6. After the test is completed, the host software will record and display the test results for future reference.

Shut down testing mode

The device will not enter the testing process, scan for the specified beacon, or connect to the specified router in any of the following scenarios.

  • The device works continuously for 15 minutes after being activated.

  • The pairing mode is set to GWCM_OLD, which does not support the two testing features mentioned above. For more information, see Definition of Pairing Mode.

  • If the pairing mode is set to power-on pairing and the device has already obtained the Wi-Fi credentials, the available modes are:

    • GWCM_OLD_PROD
    • GWCM_LOW_POWER_AUTOCFG
    • GWCM_SPCL_AUTOCFG
  • If the pairing mode is set to non-power-on pairing and the device is in pairing mode, the available modes are:

    • GWCM_SPCL_MODE
    • GWCM_LOW_POWER

How it works

DeviceWireless RouterHostEnd product testing mode is openSet the wireless router as follows:SSID: tuya_mdev_test4Password: 12345678 Channel: 6 DHCP lease: three minutes or lessOn the same LAN.Find and connect to the beacon.Advertise its presence.Respond to the device on receiving the advertising packet.Enter the testing mode.Enter the testing process.Send testing commands.Return the execution result.DeviceWireless RouterHost

Development guide

Open tuya_iot_config.h and check if the following macro is defined.

#define ENABLE_PRODUCT_AUTOTEST  1

Reference the header

  • prod_test.h

How to use

  1. Register the information about end product testing.
  2. Call the beacon scanning API.

API description

Register required information

Register pairing mode, beacon list, testing commands, and result callbacks.

/**
 * @brief  Host-based LAN testing. The application command callback.
 *
 * @param[in] cmd: Test command
 * @param[in] data: Test data
 * @param[in] len: Test data len
 * @param[out] ret_data: Test return data
 * @param[out] ret_len: Test return data len
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
typedef OPERATE_RET(*MF_USER_PRODUCT_TEST_CB)(USHORT_T cmd, UCHAR_T *data, \
                                              UINT_T len, OUT UCHAR_T **ret_data, \
                                              OUT USHORT_T *ret_len);

typedef struct {
    GW_WF_CFG_MTHD_SEL              gwcm_mode;  // Pairing mode
    uint8_t                         ssid_count; // Beacon scanning testing. The number of custom testing beacons.
    const char                    **ssid_list;  // Beacon scanning testing. The list of custom testing beacons.
    prodtest_app_cb_t               app_cb;     // Beacon scanning testing. The information returned when a specified beacon is found.
    MF_USER_PRODUCT_TEST_CB         product_cb; // Host-based LAN testing. The application command callback.
    char                           *file_name;  // Host-based LAN testing. The firmware identifier, which is APP_BIN_NAME.
    char                           *file_ver;   // Host-based LAN testing. The firmware version, which is USER_SW_VER.
} prodtest_app_cfg_t;

/**
 * @brief  The configuration required to register the end product testing feature.
 *
 * @param[in] app_cfg: The application pairing mode.
 *
 * @return OPERATE_RET
 *
 */
int prodtest_app_register(const prodtest_app_cfg_t *app_cfg);

Scan for testing beacon

/**
 * @brief Scan for the testing beacon and connect to tuya_mdev_test4.
 *         The device will first check if the testing mode is open before scanning for the testing beacon. It will proceed with the testing process only if all prerequisites are met. 
 *        For more information about the prerequisites, see Shut Down Testing Mode in this topic.
 *
 * @param[in] timeout: The scanning timeout, in milliseconds.
 *                     If no testing signal is detected within the timeout period, the device will not undergo a test. 
 *                     If you set this parameter to 0, the default value of 500 ms will be applied. 
 *
 * @return TRUE: Enter the testing mode. FALSE: Not enter the testing mode.
 *
 */
bool prodtest_ssid_scan(uint32_t timeout);

Example

After downloading the Networked Product Development Framework, you can find the example code for all features in the tuyaos_demo_examples folder under the apps directory. See the code in service_product_test. For the usage of the example code, see TuyaOS Example Collection.