From f46398d941cb719bf94ff4be892d94d7666ba46d Mon Sep 17 00:00:00 2001 From: kyz Date: Tue, 15 Aug 2023 16:20:43 +0800 Subject: [PATCH] report firmware version --- app/src/iot.c | 6 +++++- app/src/iot_dp.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/iot.c b/app/src/iot.c index 9b9e132..c1f35d6 100644 --- a/app/src/iot.c +++ b/app/src/iot.c @@ -139,17 +139,21 @@ void* iot_task( void * unused ) for (;;) { msg = dp_event_pop(); if( msg ){ + //printf( "---------------xxx-msg----------------------------\n" ); if( msg[0] == 'E' ){ //Event tuyalink_thing_event_trigger(client, NULL, &msg[1] ); }else if( msg[0] == 'P' ){ //Property tuyalink_thing_property_report( client, NULL, &msg[1] ); }else if( msg[0] == 'A' ){ //Action tuyalink_thing_action_resp(client, NULL, &msg[1] ); + }else if( msg[0] == 'O' ){ //OTA Init + tuyalink_ota_firmware_report(client, deviceId, &msg[1] ); } free( msg ); }else{ - usleep(5*1000); + // usleep(5*1000); } + /* Loop to receive packets, and handles client keepalive */ tuya_mqtt_loop(client); } diff --git a/app/src/iot_dp.c b/app/src/iot_dp.c index 4a08349..1a5ba1d 100644 --- a/app/src/iot_dp.c +++ b/app/src/iot_dp.c @@ -60,6 +60,9 @@ char * gesture_event_name[] = { #define event_fmt_str "E{\"eventCode\":\"%s\",\"outputParams\":{\"%s\":\"%s\" } }" #define action_p1_fmt_str "A{\"actionCode\":\"%s\",\"outputParams\":{\"%s\":\"%s\" } }" #define action_p2_fmt_str "A{\"actionCode\":\"%s\",\"outputParams\":{\"%s\":\"%s\", \"%s\":\"%s\" } }" +#define ota_init_fmt_str "O{\"bizType\":\"INIT\",\"pid\":\"%s\",\"otaChannel\":[{\"channel\":0,\"version\":\"%s\"}]}" + +// tuyalink_ota_firmware_report(context,deviceId,"{\"bizType\":\"INIT\",\"pid\":\"al0fhe2uqyg6pzeb\",\"otaChannel\":[{\"channel\":0,\"version\":\"1.0.0\"},{\"channel\":9,\"version\":\"1.0.0\"}]}"); int32_t dp_report( char *payload ) { @@ -126,6 +129,19 @@ int32_t dp_property_report_bool( char *dp_name, int32_t dp_value ) return dp_report( msg_buf ); } +static void ota_init_report( void ) +{ + char msg_buf[100]; + char *pid= NULL; + iot_key_load( &pid, NULL, NULL ); + if( pid ){ + sprintf( msg_buf, ota_init_fmt_str, pid, SW_VERSION); + dp_report( msg_buf ); + } + return; + +} + //激活流程,通过dp_key上报KEY ID, 也通过dp_key接收 KEY Value int32_t dp_active_report( uint32_t active ) { @@ -174,6 +190,10 @@ int32_t dp_report_all( mg_dev_t *dev ) usleep(50*1000); dp_property_report_bool( "mg_tof_status", 0 ); + //ota firmware version +// tuyalink_ota_firmware_report(context,deviceId,"{\"bizType\":\"INIT\",\"pid\":\"al0fhe2uqyg6pzeb\",\"otaChannel\":[{\"channel\":0,\"version\":\"1.0.0\"},{\"channel\":9,\"version\":\"1.0.0\"}]}"); + ota_init_report(); + return 0; } -- 2.34.1