Real-time Transmission (Legacy)

Last Updated on : 2025-02-11 02:04:01download

Based on tuyaos_robot_sweeper_sdk, this topic describes the process and APIs for transmitting real-time maps and routes of laser robot vacuums.

Overview

The real-time map and route transmission feature supports two file actions:

  • Map transmission
  • Cancel map transmission

The map for laser robot vacuums is available in two standard types:

  • Full map
  • Cleaning route

The map for laser robot vacuums also supports custom files, such as ai.bin.stream for AI-powered recognition.

Custom files are typically used in custom panels, and their naming conventions should match those on the panel.

How it works

General process

ApplicationTuyaOS SDKSTUN ServerTuya-Enabled AppCheck if the numberof sessions reachesthe limit. If it does,close a session.Send authentication information.If authenticationfails, the session willbe closed.Query the map files supported by the device.Return the result.Send a transmission event.Acknowledge the receipt of the command.The transmission eventcallback.Invoke data transmission.Send the map and route file.Cancel transmitting the map file.The transmission cancellationevent callback.Return file transmissiontermination.Return the transmission cancellation result.ApplicationTuyaOS SDKSTUN ServerTuya-Enabled App

Transmit real-time map and route

Tuya-Enabled AppTuyaOS SDKApplicationSend a file transmission event.Acknowledge the receipt ofthe command.Asynchronously senddata to differentapps in sequencebased on differentsession IDs in thecallback.Pass the transmission event andsession ID throughtuya_sweeper_event_cb callbackGet the local map file and sendit asynchronously throughtuya_sweeper_send_map_data_w-ith_buff.Send data.Get the local route file and sendit asynchronously throughtuya_sweeper_send_cleanpath_d-ata_with_buff.Send data.Get the local custom file andsend it asynchronously throughtuya_sweeper_send_customize_d-ata_with_buff.Send data.The device can asynchronouslylooptuya_sweeper_p2p_alone_stream-_close to proactively disconnectfrom apps.Notify apps to disconnect.Tuya-Enabled AppTuyaOS SDKApplication
  • The real-time map and route transmission interfaces are reported in blocking mode. After receiving the tuya_sweeper_event_cb transmission event and connection session ID callback, the app needs to handle the event asynchronously.
  • The app saves the session ID, handles the event asynchronously, and transmits data in a loop based on different session IDs.
  • If multiple transmission events are received, the data transmission interface can be invoked periodically and sequentially to transmit data.
  • You can use the tuya_sweeper_p2p_alone_stream_close interface to disconnect the connection session with the app proactively. This is usually used when the device or app network error occurs and data transmission fails for a long time. This interface can clear the local cache and parameters, and thus quickly establish a connection with the app after the network is restored.
  • If an exception occurs in sending data on multiple channels, you can call the tuya_sweeper_p2p_alone_stream_close interface in sequence to proactively disconnect from the app.

When you initialize the streaming media service, you can set the maximum number of simultaneous sessions. Three to five sessions are recommended, and the default value is five sessions. If the limit is reached, the new connection request will be forcibly closed.

Cancel the transmission of real-time map and route

Tuya-Enabled AppTuyaOS SDKApplicationSend a file transmissioncancellation event.Pass the transmissioncancellation event and sessionID throughtuya_sweeper_event_cb callbackBased on the different sessionIDs in the callback,asynchronously calltuya_sweeper_stop_send_data_t-o_app in a loop to informdifferent apps of file transfertermination.Send messages to apps.Acknowledge the receipt ofthe command to apps.Tuya-Enabled AppTuyaOS SDKApplication
  • After receiving the tuya_sweeper_event_cb transmission cancellation event and connection session ID callback, the app needs to handle the event asynchronously. If multiple transmission cancellation events are received, call tuya_sweeper_stop_send_data_to_app sequentially to inform different apps of file transfer termination.

APIs

tuya_media_server_customize_init

Initialize streaming media service.

/**
 * @brief  Initialize media streaming service
 * @param  [in] max_client_num   range: 0 to 5
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_media_server_customize_init(int max_client_num);

Parameter description

Parameter Description
max_client_num The number of clients. Currently, up to five clients are supported.

tuya_sweeper_send_map_data_with_buff

Send the real-time map data to the mobile app.

/**
 * \fn tuya_sweeper_send_map_data_with_buff
 * \brief send file to app by P2P
 * \param[in] client: client handle
 * \param[in] fileLen: file len
 * \param[in] fileBuff: file buff
 * \param[in] timeout_ms: timeout, in ms
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_sweeper_send_map_data_with_buff(IN INT_T client, IN INT_T fileLen, IN CHAR_T* fileBuff, IN INT_T timeout_ms);

Parameter description

Parameter Description
client The session handle for the data transmission channel, obtained from the callback during map transmission.
fileLen The length of the live map file.
fileBuff The content of the live map file.
timeout_ms The timeout for live map file transmission.

When you need to clear the map displayed on the app, call this interface to report an empty map in the following format:
Set fileLen to 10 bytes and fill fileBuff with 0.

tuya_sweeper_send_cleanpath_data_with_buff

Send the real-time route data to the mobile app.

/**
 * \fn tuya_sweeper_send_cleanpath_data_with_buff
 * \brief send file to app by P2P
 * \param[in] client: client handle
 * \param[in] fileLen: file len
 * \param[in] fileBuff: file buff
 * \param[in] timeout_ms: timeout, in ms
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_sweeper_send_cleanpath_data_with_buff(IN INT_T client, IN INT_T fileLen, IN CHAR_T* fileBuff, IN INT_T timeout_ms);

Parameter description

Parameter Description
client The session handle for the data transmission channel, obtained from the callback during map transmission.
fileLen The length of the live route file.
fileBuff The content of the live route file.
timeout_ms The timeout for live route file transmission.

When you need to clear the map displayed on the app, call this interface to report an empty map in the following format:
Set fileLen to 13 bytes. Fill the path type in fileBuff with 1 for standard mode and 0 for others.

tuya_sweeper_send_customize_data_with_buff

Send the custom file data to the mobile app.

/**
 * \fn tuya_sweeper_send_customize_data_with_buff
 * \brief send file to app by P2P
 * \param[in] client: client handle
 * \param[in] name: file name
 * \param[in] fileLen: file len
 * \param[in] fileBuff: file buff
 * \param[in] timeout_ms: timeout, in ms
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_sweeper_send_customize_data_with_buff(IN INT_T client, IN CHAR_T* name , IN INT_T fileLen, IN CHAR_T* fileBuff,IN INT_T timeout_ms);

Parameter description

Parameter Description
client The session handle for the data transmission channel, obtained from the callback during map transmission.
name The name of the custom file.
fileLen The length of the custom file.
fileBuff The content of the custom file.
timeout_ms The timeout for custom file transmission.

tuya_sweeper_set_customize_name

Send the custom file to the TuyaOS SDK, which must be called after TuyaOS SDK initialization. See the description of TUYA_SWEEPER_CUSTOMIZE_FILEINFO for the request parameters.

/**
 * \fn tuya_sweeper_set_customize_name
 * \brief send file to app by P2P
 * \param[in] name_info: file name
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_sweeper_set_customize_name(IN TUYA_SWEEPER_CUSTOMIZE_FILEINFO* name_info);

tuya_sweeper_stop_send_data_to_app

The device notifies the mobile app of the end of file transmission.

/**
 * \fn tuya_sweeper_stop_send_data_to_app
 * \brief send file to app by P2P
 * \param[in] client: client handle
 * \return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_sweeper_stop_send_data_to_app(IN INT_T client);

Parameter description

Parameter Description
client The session handle for the data transmission channel, obtained from the callback during map transmission.

tuya_sweeper_p2p_alone_stream_close

The device proactively disconnects the transmission channel.

/**
 * \fn tuya_sweeper_p2p_alone_stream_close
 * \brief One link is closed on the device
 * \param[in] client: client handle
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_sweeper_p2p_alone_stream_close(IN INT_T client);

Parameter description

Parameter Description
client The session handle for the data transmission channel, obtained from the callback during map downloading.