当前位置:网站首页>12. Tencent cloud IOT device side learning -- NTP function and Implementation
12. Tencent cloud IOT device side learning -- NTP function and Implementation
2022-06-24 05:58: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
ntp The function is simple uplink and downlink topic Matching functions , The device side subscribes to the downlink topic , Send a message to the uplink topic , Trigger the server to send downlink messages , And process according to the downlink message .
As follows: NTP Function as an example , Introduce how to base on iot-hub-device-c-sdk Realize this function .
Module add
stay services/hub/system/ New modules , Need to achieve
- src: Module source code , Provide sdk External interface
- inc: The module uses header files internally , None in this function
- sample: Sample code , Examples of calling interfaces
- test: Unit test case writing
- CMakeLists.txt:cmake Script , Simply set the source code and header file path , Add examples and unit tests ( Later, it can be simplified without modifying the service )
NTP The function mainly implements two interfaces :
- IOT_Sys_GetTime: This interface is used to get the time from the server , Mainly do the following three things
- _system_mqtt_result_topic_check_and_sub: Detect downlink topic Subscription status , If you don't subscribe, subscribe
- _system_mqtt_get_resource_time_publish: Up topic Release the news , To get time
- _system_mqtt_result_wait: Timeout waiting for server reply
- IOT_Sys_SyncNTPTime: and IOT_Sys_GetTime similar , The difference is that it passes according to the time before and after receiving the message HAL_Timer_SetSystimeSec and HAL_Timer_SetSystimeMs Set system time .
The source code to achieve ( see system_mqtt.c), The following is a brief description of the development ideas of such services :
- Sync subscription : Most services need to ensure the success of the subscription , To ensure the success of the subscription , You can call IOT_MQTT_SubscribeSync
- Message processing : The old version of the service will be in mqtt client Add a new member to the structure , Obviously, this is not conducive to code maintenance and subsequent function development , So you can subscribe to the usr_data To pass in the context that needs to be processed by the service , At the same time, we need to usr_data Register the release function of , Because this part follows mqtt client Life cycle exists , When mqtt client Be destroyed when the , It needs to be released usr_data.
- Interface encapsulation : Different services require different logic perceived by users , Services identified for such agreements , Generally by SDK encapsulate , Only provide data that users need to be aware of , Such as time .
Add... To the external header file
stay include/services/common Add external header file in qcloud_iot_system.h, It mainly provides external interfaces
Compile add
stay config/settings/iot_hub_setting.cmake Add module compilation in , Simply add the corresponding directory to the compilation , It will automatically detect the CMakeLists.txt
add_subdirectory(${PROJECT_SOURCE_DIR}/services/common/system)边栏推荐
- How to use the domain name? What domain name should be selected to purchase
- The website cannot be opened after windows installs the dongle
- MySQL optimization
- How to solve the problem that easynvr calls the video download interface of the specified time period to display "being synthesized" and does not generate video?
- How do users in the insurance upgrade industry choose?
- Load balancing on Tencent cloud
- NoClassDefFoundError and classnotfoundexception exceptions
- Groovy script engine practice in complex and changeable scenarios
- Tencent Anxin platform was officially released, and the "Anxin agricultural product plan" was launched at the same time, supporting the growth of 100 landmark agricultural product brands in three year
- Brief introduction to the working principle of high frequency signal generator
猜你喜欢
随机推荐
Go concurrency - work pool mode
An indoor high-end router with an external cable bundle limiting mechanism
How do fixed assets intensive enterprises manage fixed assets effectively?
How to file a personal domain name? What are the benefits of domain name filing?
Tesseract-OCR helloworld
Why do the new generation of highly concurrent programming languages like go and rust hate shared memory?
Interpretation of PNG files (1): past and present lives of png/apng format
Why storage?
Material production tool manual
The development and construction of live broadcast app, and the source code of live broadcast app involves all aspects
Summary of basic notes of C language (III)
A rail grinder for rail transit
[performance test] 3 How to calculate the number of concurrent users
Script updates CLB type ingress Certificate in tke cluster
Royal treasure: physical storage medium
How do virtual hosts bind domain names? Can binding failure be used normally?
How to solve the enterprise network security problem in the mixed and multi cloud era?
Progress update | optimization and upgrading of shard nodes
The website cannot be opened after windows installs the dongle
Go's package management learning notes


