# RTOS equipment

In the light of RTOS Equipment, we launch a cloud-to-cloud solution, that is, a cloud-broker solution.

The cloud to the cloud program is mainly for the inability to run a complete VoIP SDK Through the background of the equipment manufacturer, the communication link between the low-power equipment and the WeChat VoIP server can be opened up. The low-power equipment is transmitted to the audio video data flow and the signaling.

Call Process:

SDK Download Addresshttps://git.weixin.qq.com /wxa_iot/cloudvoipsdk

# 1. Equipment requirements

  • HTTPS Communication capability
  • Storage capacity
  • sound(regard)Frequency capability

# 2. Device Side Development

Requires integration on low power devices Device end SDK, used to call the Mini Program in the mobile WeChat VoIP Call.

equipment SDK You need to use Mini programs first. Appid, modelid, device Id, the data file folder path call wx_init Function initialization.

If the device runs the device for the first time The SDK, you also need to call wx_device_register Function to the WeChat background to register the current device. You need an Mini Program when registering a device snticket .

If the registration is successful, then at this point you can call the wx_cloudvoip_client_call Function to initiate WeChat voip Call, need to pass the device to call the WeChat user's Openid And audio and video cloud background recognition voip Information Required Payload (the content is transmitted to the cloud server background at the discretion of the vendor and the cloud server background). If the call is successful, the device is allowed to make audio and video calls to the specified WeChat user, and the manufacturer can create the audio and video data flow to the manufacturer's cloud server and start the transmission. call Function is initiated before). In short, payload It is the identification of the channel provided to the manufacturer's equipment to its cloud server, so that the cloud server can find the audio and video stream transmitted by the device after receiving the WeChat background notification.

It is necessary to note that WeChat users must first authorize the permission of the specified device to initiate a call in the vendor's Mini Program, and do not close the authorization or delete the Mini Program (clean up all the data and authorization information of the Mini Program) in the Mini Program settings, otherwise the device will not have the right to initiate the call. call The function will return no permissions.

# 3. Interface Dxplaination

The specific interface is as follows, please refer to the use of sdk In the bag example Under the directory Demo Code.

/**
 * @brief to initialize voip
 *
 * Need to be called before calling other interfaces wx_init() to initialize
 *
 *
 * @param  stack (nonnull ) Developer Implementation TLS Connect, close, read, write interfaces.
 * @param  hal (nonnull ) Developer Implementation OS Related Interfaces
 * @param  config (nonnull ) Equipment Configuration Information
 * @return
 *  - WXERROR_RESOURCE_EXHAUSTED: Memory resource allocation failed
 *  - WXERROR_INVALID_DEVICEID: The device is registered, but the current sdk Used deviceid、modelid wrong
 */
wx_error_t wx_init(wxvoip_network_https_impl_t *stack, wxvoip_os_impl_t *hal, wx_cloudvoip_config_t *config)

/**
 * @brief Destroy voip
 * 
 * Perform resource release
 */
void wx_destory(void)

/**
 * @brief Registration device
 * 
 * This interface needs to be called once, returned immediately if the device is registered, and re-registered if the device is not registered or if the registration data is incorrect.
 *
 * @param  sn_ticket (nonnull ) Corresponding to the Mini Program Snticket, Ref:
 * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/hardware-device/getSnTicket.html
 * @return
 *  - WXERROR_RESOURCE_EXHAUSTED: Memory resource allocation failed
 *  - WXERROR_RESPONSE: Background return failure, usually a network problem
 *  - WXERROR_IO: IO Failure, usually write file interface return failure
 *  - Others:
 *       -10008: snticket  There's a problem
 */
wx_error_t wx_device_register(const char *sn_ticket)

/**
 * @brief Check if the device has been registered
 * Need to be in the wx_init This function cannot be called until the call is complete.
 *
 * @param  is_registered_out Output device registry.
 * @return Whether there is an error in the detection process, For example, data files are not read-write, or rpmb
 * The device cannot be accessed normally.
 *   - WXERROR_OK: Return properly, Can be used correctly is_registered_out To determine if the device is registered.
 *   - WXERROR_FAILED_PRECONDITION: wx_init Not called
 *   - WXERROR_INVALID_ARGUMENT: Parameter is empty
 *   - WXERROR_INVALID_DEVICEID: The device is registered, but the current sdk Used deviceid、modelid wrong
 *   - WXERROR_UNKNOWN: Registration information is destroyed, in this case, you can generally clean the device to re-register
 */
wx_error_t wx_device_is_registered(int* is_registered_out)

/**
 * @brief to call VoIP Call to the designated WeChat user
 *
 * Manufacturers need to implement the user's address book function.
 * The manufacturer needs to prompt the user to specify the device in its own Mini Program. (equipment ID) To grant authorization VoIP After the call permission,
 * Carry the equipment. ID To the user on the device of the VoIP Call.
 *
 * @param  room_type Call type, available in both audio and audio video
 * @param  caller This equipment. VoIP Role settings.
 * @param  callee To call the WeChat user's VoIP Role settings
 * @param  custom_query Mini Program page custom parameters, Can be passed NULL
 * @param  payload Third-party cloud SDK sign VoIP The identifier of the stream (such as json)
 * @return
 *   - WXERROR_FAILED_PRECONDITION: Cannot initiate a call request, such as getting Token Not equal.
 *   - WXERROR_RESOURCE_EXHAUSTED: Memory resource allocation failed
 *   - WXERROR_RESPONSE: Background return failure, usually a network problem
 *   - Negative number: When requesting a call, the backstage return the failure code to take negative, can refer tohttps://mp.weixin.qq.com/wxopen/plugindevdoc?appid=wxf830863afde621eb 
 *       1	roomid error
 *       2	equipment deviceId error
 *       3	voip_id error
 *       4	Campus Scene Pay Brush Face Mode, voipToken error
 *       5	generate voip Room error
 *       7	openId error
 *       8	openId Not authorized
 *       9	Campus Scene Pay Brush Face Mode: openId No userId The contact person forHardware device mode: openId Unbound device
 *       12	Mini Program audio and video ability audit is not completed, the official version can not be used temporarily
 *       13	WeChat mode, voipToken error
 *       14	Mobile WeChat dialing hardware device mode, voipToken error
 *       15	Audio and video charges
 *       17	VoipToken  Corresponding modelId error
 *       19	openId With Small Programs appId No match. Please note that the same user in different Mini Programs openId Is different.
 *       20	openId invalid
 *       10008 snticket  Be overdue
 */
wx_error_t
wx_cloudvoip_client_call(wx_cloudvoip_session_type_t room_type,
                         const wx_cloudvoip_member_t* caller,
                         const wx_cloudvoip_member_t* callee,
                         const char* custom_query,
                         const char* payload)

/**
 * @brief WeChat dialing device, device use roomid Join the call
 *
 * When the manufacturer needs to call the device from the Mini Program end roomid Transfer to the device.
 *
 * @param  roomid After launching the call, get the roomid of the call
 * @param  payload Third-party cloud SDK sign VoIP The identifier of the stream (such as json)
 * @return
 *   - WXERROR_FAILED_PRECONDITION: Cannot initiate a call request, such as getting Token Not equal.
 *   - WXERROR_RESOURCE_EXHAUSTED: Memory resource allocation failed
 *   - WXERROR_RESPONSE: Background return failure, usually a network problem
 *   - Negative number: When requesting a call, the backstage return the failure code to take negative, can refer tohttps://developers.weixin.qq.com/miniprogram/dev/framework/device/voip-plugin/api/errCode.html
 *       1	roomid error
 *       2	equipment deviceId error
 *       3	voip_id error
 *       4	Campus Scene Pay Brush Face Mode, voipToken error
 *       5	generate voip Room error
 *       7	openId error
 *       8	openId Not authorized
 *       9	Campus Scene Pay Brush Face Mode: openId No userId The contact person forHardware device mode: openId Unbound device
 *       12	Mini Program audio and video ability audit is not completed, the official version can not be used temporarily
 *       13	WeChat mode, voipToken error
 *       14	Mobile WeChat dialing hardware device mode, voipToken error
 *       15	Audio and video charges
 *       17	VoipToken  Corresponding modelId error
 *       19	openId With Small Programs appId No match. Please note that the same user in different Mini Programs openId Is different.
 *       20	openId invalid
 */
wx_error_t 
wx_cloudvoip_client_Join(const char* roomid,
                          const char* payload)