当前位置:网站首页>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 .
边栏推荐
- Contour-v1.19.1 release
- Official spoilers! Figure 1 understand Tencent security @2021 Tencent digital ecology Conference
- UI automation based on Selenium
- Optimization of Clickhouse ConnectionPool link pool
- A variety of fixed assets inventory methods to deal with the year-end large inventory of fixed assets
- How to strengthen prison security measures? Technologies you can't imagine
- 2022-2028 global third-party data platform industry research and trend analysis report
- Tke single node risk avoidance
- Simple use of notification
- Interesting talk about decorator mode, so you will never forget it
猜你喜欢

2022-2028 global indoor pressure monitor and environmental monitor industry research and trend analysis report

2022-2028 global aircraft wireless intercom system industry research and trend analysis report

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

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

Permission maintenance topic: domain controller permission maintenance

2022-2028 global genome editing mutation detection kit industry survey and trend analysis report

2022-2028 global medical coating materials industry research and trend analysis report

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

2022-2028 global medical modified polypropylene industry research and trend analysis report

UI automation based on Selenium
随机推荐
Cloudpods golang practice
Afnetworking usage and cache processing
Vscode common shortcut keys, updating
Simple use of notification
2022-2028 global pilot night vision goggle industry research and trend analysis report
How to transfer files from the server connected to the fortress machine and how to access the server through the fortress machine
Is the server connected to the fortress machine a virtual machine? What if the fortress machine IP is not connected
VNC enters the password and goes around for a long time before entering the desktop. Use procmon to locate the reason
2022-2028 global aircraft wireless intercom system industry research and trend analysis report
[51nod] 3047 displacement operation
2022-2028 global aircraft front wheel steering system industry research and trend analysis report
File access methods on Fortress server how to log in to the server
How to build a speech synthesis server
What is the performance improvement after upgrading the 4800h to the 5800h?
Gin framework: RPC error code design
How to enable IPv6 network access for personal broadband
Code 128 barcode details
2022-2028 global anti counterfeiting label industry research and trend analysis report
How to log in the remote server of Fortress machine working principle of Fortress machine
Face recognition using cidetector