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);
}
#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 )
{
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 )
{
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;
}