当前位置:网站首页>14. Tencent cloud IOT device side learning - data template application development
14. Tencent cloud IOT device side learning - data template application development
2022-06-24 02:54:00 【fancyxu】
The main purpose of this series is to record the learning notes of Tencent cloud Internet of things device , And on the device side SDK Make a supplementary explanation .
brief introduction
Data template related concepts , Please see the Data template
Data template function implementation , Please see the Data template function and implementation
The following describes how to develop applications based on data templates , It mainly includes Data template coding 、 Downlink data processing 、 Uplink data reporting .
Please refer to the source code :
https://github.com/xyfancy/iot-hub-device-c-sdk/tree/master/app/data_template
Data template coding
The core idea : Convert the data template definition to the corresponding C Code data type , such as Integer type ->int, Provide general interface according to Indexes visit ( The implementation is in beta edition , Subsequently, the script is used for automatic generation ).
Source code :data_template_config.c and data_template_config.h
Take the lamp switch attribute as an example :
1. initialization
Properties include :
- type: Corresponding data template type
- key: For the keyword corresponding to the attribute
- value: Value storage space
- need_report: Whether it is necessary to report , When the value changes , The escalation platform is required for synchronization ( Specially : If it is only a downstream attribute , And the platform is not used to save the status , There is no need to report )
struct DataTemplateProperty {
DataTemplatePropertyType type;
const char* key;
DataTemplatePropertyValue value;
int need_report;
};According to the definition of data template on the console , Initialize switch properties :
- type : Boolean type
- keyword :power_switch
- value : You can use C In language int Storage , Where the value uses Joint type , Users need to select members according to the data template type .
- Report or not : Because the switch can be modified manually when it is offline , Therefore, it is necessary to report during initialization )
sg_usr_data_template_property[USR_PROPERTY_INDEX_POWER_SWITCH].value.value_bool = 0; sg_usr_data_template_property[USR_PROPERTY_INDEX_POWER_SWITCH].key = "power_switch"; sg_usr_data_template_property[USR_PROPERTY_INDEX_POWER_SWITCH].type = DATA_TEMPLATE_TYPE_BOOL; sg_usr_data_template_property[USR_PROPERTY_INDEX_POWER_SWITCH].need_report = 1;
2. Interface call
By indexing data templates , Access the corresponding data template through the index
typedef enum {
USR_PROPERTY_INDEX_POWER_SWITCH = 0, // Switch index
USR_PROPERTY_INDEX_COLOR,
USR_PROPERTY_INDEX_BRIGHTNESS,
USR_PROPERTY_INDEX_NAME,
USR_PROPERTY_INDEX_POSITION,
USR_PROPERTY_INDEX_POWER,
} UsrPropertyIndex;// initialization
void usr_data_template_init(void);
// Get the data template value of non structure type
DataTemplatePropertyValue usr_data_template_property_value_get(UsrPropertyIndex index);
// Set the data template value of non structure type
void usr_data_template_property_value_set(UsrPropertyIndex index, DataTemplatePropertyValue value);
// Get the data template value of the structure type
DataTemplatePropertyValue usr_data_template_property_struct_value_get(UsrPropertyIndex struct_index,
int property_index);
// Set the data template value of the structure type
void usr_data_template_property_struct_value_set(UsrPropertyIndex struct_index, int property_index,
DataTemplatePropertyValue value);
// Get the data template value of the input parameter in the behavior
DataTemplatePropertyValue usr_data_template_action_input_value_get(UsrActionIndex index, int property_index);// Through analysis control perhaps get_status in control In the news params Set the corresponding properties
void usr_data_template_property_parse(UtilsJsonValue params);
// Report all the attributes that need to be reported ,need_report by 1
int usr_data_template_property_report(void* client, char* buf, int buf_len);
// Report the incident , Here, the user can construct json, More flexibility
void usr_data_template_event_post(void* client, char* buf, int buf_len, UsrEventIndex id, const char* params);
// Through analysis action The input parameters in the message set the corresponding properties
int usr_data_template_action_parse(UtilsJsonValue action_id, UtilsJsonValue params, UsrActionIndex* index);
// Response to action
int usr_data_template_action_reply(void* client, char* buf, int buf_len, UsrActionIndex index,
UtilsJsonValue client_token, int code, const char* response);Downlink data processing
Source code :data_template_app.c
Downlink data mainly includes :
- control news : Set the property value in the callback , Then read the attribute value for processing
- method_control_callback->usr_data_template_property_parse->usr_data_template_property_value_get
- action news : Set the input parameter attribute value in the callback , Then read the attribute value for processing
- method_action_callback->usr_data_template_action_parse->usr_data_template_action_input_value_get
- get_status news : Set... In callback control The attribute value of the message , Then read the attribute value for processing
- method_get_status_reply_callback->usr_data_template_property_parse->usr_data_template_property_value_get
- Reply to various messages :
- If you need to implement QOS1 quality , Please establish a queue implementation in the application layer ( It depends on the business , Different business requirements have different requirements for retransmission and timeout time , Typical examples are summarized based on business experience ).
- If it is QOS0 quality , All replies can be ignored directly ( Most data collection messages can be handled this way ).
Uplink data reporting
Source code :data_template_app.c
The online data mainly includes :
- report news : Setting property values (need_reoprt Set as 1), Then call the interface to report all need_report by 1 Properties of
- usr_data_template_property_value_set->usr_data_template_property_report
- control_reply news : Call the interface in the callback to reply directly , It's OK not to reply , It depends on the business
- method_control_callback->IOT_DataTemplate_PropertyControlReply
- action_reply news : Reply according to the result in the call , Because of the clouds API There is a timeout limit , So the reply must be immediate , If you can't complete the action , Please reply by attribute reporting .
- method_action_callback->usr_data_template_action_reply
- event Report : Call interface , To remodel oneself json Report ,sdk Examples are provided in . This is more flexible and simple
- usr_data_template_event_post
matters needing attention
The method provided in this paper is designed to summarize the previous business , There are the following restrictions , Please modify according to the business :
- By default, all attributes are passed usr_data_template_property_value_set It will be set after setting need_report by 1, And in the call usr_data_template_property_report I'll report it later . If you do not need to report the attribute , You can filter by attribute index .
- usr_data_template_property_parse Can parse json And set all the properties , If multiple attributes are required to take effect together , Please integrate these attributes into the structure or string type , Or modify the implementation of the interface , Judge against the index .
- All replies will not be processed , For some special scenes ( Weak net ), The application layer implements QOS1, At present, there are few project demands .
边栏推荐
- Iranian gas station paralyzed by cyber attack, babuk blackmail software source code leaked | global network security hotspot
- Vscode common shortcut keys, updating
- Which is a good human voice synthesis platform? What are the human voice synthesis application scenarios
- Afnetworking usage and cache processing
- [Tencent cloud double 12.12] from 56 yuan! New users of Tencent cloud buy for the first time, which is more cost-effective!
- Where is the domain name filed? What materials are required for domain name filing?
- Using the database middleware MYCAT to realize read-write separation (dual master and dual slave)
- What is the meaning of scdo? Is it comparable to bGH
- The 2021 Tencent digital ecology conference is coming
- Production line motor monitoring and maintenance - application case of 5g edge calculation for paperboard line motor maintenance
猜你喜欢

2022-2028 global indoor pressure monitor and environmental monitor industry research and trend analysis report
![[51nod] 3047 displacement operation](/img/cb/9380337adbc09c54a5b984cab7d3b8.jpg)
[51nod] 3047 displacement operation

The cost of on-site development of software talent outsourcing is higher than that of software project outsourcing. Why

UI automation based on Selenium

2022-2028 Global Industry Survey and trend analysis report on portable pressure monitors for wards

2022-2028 global cell-based seafood industry research and trend analysis report

2022-2028 global pilot night vision goggle industry research and trend analysis report
Cloudpods golang practice

2022-2028 global high tibial osteotomy plate industry research and trend analysis report

IOS development - multithreading - thread safety (3)
随机推荐
2022-2028 global medical modified polypropylene industry research and trend analysis report
Coding -- the leader of R & D tools in the cloud native Era
Gin framework: RPC error code design
LeetCode 205. Isomorphic Strings
Crawler series: using API
[tcapulusdb knowledge base] manually view the online operation of tcapulusdb
Is your database "cloud native"?
Building a web site -- whether to rent or host a server
Afnetworking server client
Create and mount large files
Grpc: based on cloud native environment, distinguish configuration files
What are the main functions of DNS? What are the benefits of IP address translation
Buddha's foot before examination: the first bullet of leetcode
LeetCode 1323. Maximum number of 6 and 9
What is the 4A server fortress machine? What is the price of the fortress machine
How to log in the remote server of Fortress machine working principle of Fortress machine
Permission maintenance topic: domain controller permission maintenance
How to apply for top-level domain names? What are the types of top-level domain names?
Live broadcast Reservation: a guide to using the "cloud call" capability of wechat cloud hosting
How to handle the occasional address request failure in easygbs live video playback?