Event Alert

Last Updated on : 2024-06-25 03:48:41download

The camera sends alerts of events including motion, human shape, pet, and doorbell call to the cloud to get reflected in the message center on the mobile app. Event alerts support image or video message and incoming call prompt.

Development guide

Components

svc_api_ipc

API description

Solution 1

Report alerts using DP 212. If the event type is included in the NOTIFICATION_NAME_E enum (in the file: tuya_ipc_notify.h), use the following API to report the alert.

/**
 * @brief send an editable alarm to tuya cloud and APP
 *
 * @param[in] snap_buffer: address of current snapshot
 * @param[in] snap_size: size fo snapshot, in Byte
 * @param[in] name: editable event type, NOTIFICATION_NAME_E
 * @param[in] is_notify: send to message center if TRUE
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_ipc_notify_alarm(IN CONST CHAR_T *snap_buffer, IN CONST UINT_T snap_size, IN CONST NOTIFICATION_NAME_E name, IN BOOL_T is_notify);

Solution 2

If the event type is not included in the NOTIFICATION_NAME_E enum, check if it is included in the TUYA_ALARM_TYPE_E enum (in the file: tuya_ipc_event.h). If yes, you can use the following API to report the alert.

/**
 * @brief notify an alarm not base on event
 *
 * @param alarm: TUYA_ALARM_T
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_ipc_trigger_alarm_without_event(IN TUYA_ALARM_T *alarm);

Data structure

The data struct for alert details:

typedef struct {
    INT_T type;                         ///< alarm type
    TUYA_ALARM_BITMAP_T wait_for;       ///< depends on other alarms
    INT_T is_notify;                    ///< notify to cloud
    TIME_T trigger_time;
    TIME_T upload_time;                 ///< 0 means immediately and -1 means wait until event ends
    BOOL_T valid;                       ///< 1 means needs to handle and 0 means had handled. You should set it to 1
    BOOL_T force;                       ///< force upload or not, independent with event like E_ALARM_COVER
    INT_T resource_type;                ///< refer to macro RESOURCE_XXX
    CHAR_T *extra_data;                 ///< extra data append to upload info, json format: "aaa":3. NULL if not need
    CHAR_T *pic_buf;
    INT_T pic_size;
    TUYA_ALARM_TEXT_T *context;        ///< text alarm info, can be NULL
    INT_T context_cnt;                  ///< TUYA_ALARM_TEXT_T count, can be 0
    NOTIFICATION_UNIT_T *media;         ///< media info, can be NULL
    INT_T media_cnt;                    ///< NOTIFICATION_UNIT_T count, can be 0
    CHAR_T dev_id[DEV_ID_LEN+1];        ///< device id
    INT_T dev_chan_index;              ///< device channel
} TUYA_ALARM_T;

The following sample code shows the initial values for reporting an image alert.

TUYA_ALARM_T alarm_info = {0};
alarm_info.type = ; // The event type.
alarm_info.is_notify = ; // Message center on/off state.
alarm_info.trigger_time = tal_time_get_posix(); // The current time.
alarm_info.upload_time = 0;
alarm_info.valid = 1;
alarm_info.force = 1;
alarm_info.resource_type = RESOURCE_PIC;
alarm_info.pic_buf = ; // The address of the image buffer.
alarm_info.pic_size = ; // The size of the image buffer.
alarm_info.extra_data = NULL;
alarm_info.context = NULL;
alarm_info.context_cnt = 0;
alarm_info.media = NULL;
alarm_info.media_cnt = 0;

FAQs

Is there a limit on the frequency of alert reporting?

  • It is recommended to report an alert for every motion event.
  • Take the debounce time into consideration based on motion detection.

How do I deal with the API if motion detection is turned off on the mobile app?

What event types do you support?

  • Events included in NOTIFICATION_NAME_E.
  • Events included in TUYA_ALARM_TYPE_E.
  • To add an event type, submit a service ticket.

How do you secure image transfer?

  • Images are encrypted and transmitted in an encrypted channel.
  • Messages are transmitted in an encrypted channel.

What image file format is supported?

JPEG format.

What is the image size limit?

An image must be less than 307,120 bytes.

How do I know if an alert is reported successfully?

  • In the log, check https for the result of delivering the image and DP 212 message.
  • Go to the Tuya Developer Platform. Choose Product > Device Management, and enter the device ID to check if DP 212 is reported successfully.

Why doesn’t the message center display a successfully reported event?

Submit a service ticket to request a check for the configuration of the respective event type in DP 212.