Report device status on demand from the device

更新时间:
复制 MD 格式

Frequent status reporting from devices can cause the server to store large amounts of unnecessary data and increase costs. To solve this problem, you can use an app to control the reporting frequency. This enables on-demand status reporting.

Solution

下载 (3).svg

1708999498532-be7723f8-5b22-40b1-98e2-f34d4e093167.png

How to Get Started

  1. Add the getProperties service to the Thing Specification Language model during product registration, as shown below:

  2. Use version 1.6.6-20 of the Feiyan device SDK.

  3. This feature is disabled by default. To enable it, refer to the smart_outlet application at Products/example/smart_outlet.

    1. In the smart_outlet.mk file, enable the GLOBAL_CFLAGS += -DREPORP_ON_DEMAND macro.

    2. To control event reporting in the Thing Specification Language model, enable the GLOBAL_CFLAGS += -DDISABLE_EVENT_REPORT macro in smart_outlet.mk. Otherwise, leave it disabled.

    3. Based on the product's Thing Specification Language model definition, complete the user_post_all_property(void) function in the smart_outlet_main.c file. This function is called when the device status reporting window opens to report the complete device status once.

    4. In the user_connected_event_handler(void) function in the smart_outlet_main.c file, disable the reporting switch after the connection is established and the status is reported once.

    @@ -234,6 +234,9 @@ static int user_connected_event_handler(void)
         }
     #endif
     
    +#ifdef REPORP_ON_DEMAND
    +    set_report_state(0);
    +#endif
         return 0;
     }
    
  4. The reporting window duration is defined in the report_on_demand.c file. The default duration is 30 s. You can modify it as needed:

    #define REPORT_TIMEOUT_MS (1 * 30 * 1000)

  5. Add the report_on_demand.c file to smart_outlet.mk.

    @@ -36,7 +36,8 @@ $(NAME)_SOURCES := app_entry.c \
                        device_state_manger.c \
                        factory.c \
                        property_report.c \
    -                   msg_process_center.c
    +                   msg_process_center.c \
    +                   report_on_demand.c

Patch file

Note

To enable on-demand status reporting from the device, apply this diff.zip file to the latest SDK.