AliOS-Things--linkkitapp (6)上报属性

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28877125/article/details/83004359

 在上报属性的时候遇到的很多坑,一直遇到:

[err] TSL Property Assemble Failed: RGBColor.Red
[err] TSL Property Assemble Failed: RGBColor.Green
[err] TSL Property Assemble Failed: RGBColor.Blue

最后,终于解决了这个问题了,于是记录一下。

上报属性

 全部的属性如下:总的来说分为两种

  • 第一种简单的(键:值):"WIFI_Tx_Rate":1
  • 第二种复杂嵌套的(键:{键:值}):"RGBColor":{ "Red":0, "Blue":0, "Green":0 }
{
	{
		"actionType":"upstream",
		"messageMethod":"thing.event.property.post",
		"messageID":"12174726",
		"messageParams":{
		
			"WIFI_Tx_Rate":1,
			"WIFI_AP_BSSID":"4:�:r:@:�:�",
			"WiFI_RSSI":-30,"Brightness":0,
			"HSVColor":{
			
				"Saturation":0,
				"Value":0,"Hue":0
			},
			"WIFI_Band":"2.4G",
			"RGBColor":{
			
				"Red":0,
				"Blue":0,
				"Green":0
			},
			"WIFI_Rx_Rate":1,
			"HSLColor":{
			
				"Lightness":0,
				"Saturation":0,
				"Hue":0
			},
			"LightSwitch":0,
			"Propertypoint":0,
			"NightLightSwitch":0,
			"ColorTemperature":0,
			"PropertyCharacter":"",
			"WiFI_SNR":30,
			"WIFI_Channel":1,
			"WorkMode":0
		},
			"topic":"/sysa1a6auLEDNxLTS20181008001thing/event/property/post",
			"uniMsgId":"1049558894138900480"
	},
	"messageResult":"200",
	"logTime":"1539069314"
}

1、简单的属性上报:LightSwitch

属性Json表达式:

	"LightSwitch":0,
    int lightswitch = 1;
    
    linkkit_set_value(linkkit_method_set_property_value, sample->thing,
    			"LightSwitch", &lightswitch, NULL);
    
    linkkit_post_property(sample->thing, "LightSwitch",post_property_cb);
     

2、复杂的属性上报:RGBColor

属性Json表达式:

	"RGBColor":{
		"Red":0,
		"Blue":0,
		"Green":0
	 }

错误的写法

    int red, green, blue;
    
    red = 255;
    
    green = 255;
    
    blue = 255;
    
    // RGB
    linkkit_set_value(linkkit_method_set_property_value, sample->thing,
    			"RGBColor.Red", &red, NULL);
    
    linkkit_post_property(sample->thing, "RGBColor.Red",post_property_cb);
    
    linkkit_set_value(linkkit_method_set_property_value, sample->thing,
    			"RGBColor.Green", &green, NULL);
    
    linkkit_post_property(sample->thing, "RGBColor.Green",post_property_cb);
    
    linkkit_set_value(linkkit_method_set_property_value, sample->thing,
    			"RGBColor.Blue", &blue, NULL);
    
    linkkit_post_property(sample->thing, "RGBColor.Blue",post_property_cb); 
    

正确的写法

    int red, green, blue;
    
    red = 255;
    
    green = 255;
    
    blue = 255;
    
    linkkit_set_value(linkkit_method_set_property_value, sample->thing,  
    			"RGBColor.Red", &red, NULL);
    
    linkkit_set_value(linkkit_method_set_property_value, sample->thing, 
    			"RGBColor.Green", &green, NULL);
    
    linkkit_set_value(linkkit_method_set_property_value, sample->thing, 
    			"RGBColor.Blue", &blue, NULL);
    
    linkkit_post_property(sample->thing,"RGBColor",post_property_cb);
    

而一般来说一个上报属性的函数是这样写的:

static int post_property_color(sample_context_t *sample_ctx)
{
    int ret = -1;
    unsigned int red, green, blue;
 
    if (is_active(sample_ctx))  {
		
	red = 1;
	green = 2;
	blue = 3;
	   
	linkkit_set_value(linkkit_method_set_property_value, sample_ctx->thing, 
				"RGBColor.Red", &red, NULL);
	linkkit_set_value(linkkit_method_set_property_value, sample_ctx->thing, 
				"RGBColor.Green", &green, NULL);
	linkkit_set_value(linkkit_method_set_property_value, sample_ctx->thing, 
				"RGBColor.Blue", &blue, NULL);

	linkkit_post_property(sample_ctx->thing,"RGBColor",post_property_cb);

        ret = 0;
    }
    return ret;
}

猜你喜欢

转载自blog.csdn.net/qq_28877125/article/details/83004359