report firmware version
authorkyz <kongyuzhong@gmail.com>
Tue, 15 Aug 2023 08:20:43 +0000 (16:20 +0800)
committerkyz <kongyuzhong@gmail.com>
Tue, 15 Aug 2023 08:20:43 +0000 (16:20 +0800)
app/src/iot.c
app/src/iot_dp.c

index 9b9e132d75bf6c49753c0e749c4fa739946864ca..c1f35d6cf3f1d39bf7803c6782b2e9523bef242b 100644 (file)
@@ -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);
        }
index 4a083498a66e2c2ec88b5054502963abfa6a21f5..1a5ba1d99d02b22cdbde5e55547abfca17f79f9c 100644 (file)
@@ -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;
 }