激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - 編程技術(shù) - OpenHarmony繼續(xù)上云之騰訊云平臺

OpenHarmony繼續(xù)上云之騰訊云平臺

2021-12-30 21:51鴻蒙社區(qū)cszzlsw 編程技術(shù)

說實(shí)話,騰訊云物聯(lián)網(wǎng)平臺一直是我比較喜歡的物聯(lián)網(wǎng)云太平,除了有騰訊大廠作為品質(zhì)背書之外,提供的sdk也是相當(dāng)好用,更有騰訊連連小程序可以幫助做界面,調(diào)試功能.

OpenHarmony繼續(xù)上云之騰訊云平臺

一.前面的話

說實(shí)話,騰訊云物聯(lián)網(wǎng)平臺一直是我比較喜歡的物聯(lián)網(wǎng)云太平,除了有騰訊大廠作為品質(zhì)背書之外,提供的sdk也是相當(dāng)好用,更有騰訊連連小程序可以幫助做界面,調(diào)試功能,后端的API有java,c++,Golang,js,python等等語言版本,非常方便,簡直是上云首選.

二.首先下載sdk

我們首先來找官方sdk,茫茫文檔中給我看到了那熟悉的身影:

OpenHarmony繼續(xù)上云之騰訊云平臺

文檔地址在這,拿走不謝:

https://cloud.tencent.com/document/product/1081/48356

把sdk下載之后,熟練的放進(jìn)thirdparty文件夾,

OpenHarmony繼續(xù)上云之騰訊云平臺

不得不提一下,2.x版本的OpenHarmony比1.x版本的代碼結(jié)構(gòu)清晰多了.

1.實(shí)現(xiàn)幾個重要接口

這個時候依然要看文檔,因?yàn)橛行┖瘮?shù)需要自己實(shí)現(xiàn),具體是哪些呢,在這里:

https://cloud.tencent.com/document/product/1081/48389

這篇文檔寫了,我們要實(shí)現(xiàn)里面的這些接口,此處列舉一二:

OpenHarmony繼續(xù)上云之騰訊云平臺
OpenHarmony繼續(xù)上云之騰訊云平臺

仔細(xì)一看,霍,好家伙還不少呢,但是不怕,都是打工人,誰怕誰啊,二話不說我就寫,結(jié)果就給我給寫出來了:

OpenHarmony繼續(xù)上云之騰訊云平臺

寫出來這些后就可以準(zhǔn)備編譯了嗎?

nonono,我們還沒做BUILD.gn文件呢,話不多說,直接教你寫。

  1. # Copyright (c) 2020 Huawei Device Co., Ltd.
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13.  
  14. import("//build/lite/config/component/lite_component.gni")
  15. import("//build/lite/ndk/ndk.gni")
  16.  
  17. config("qcloud_sdk_config") {
  18.  
  19. include_dirs = [
  20. "sdk_src/internal_inc",
  21. "sdk_src/library",
  22. "include",
  23. "include/exports",
  24.  
  25. "//kernel/liteos_m/kernel/include",
  26.  
  27. # "//third_party/cmsis",
  28. "//third_party/mbedtls/include",
  29. "//third_party/mbedtls/include/mbedtls",
  30.  
  31. ]
  32.  
  33.  
  34. }
  35. cflags = [ "-Wno-unused-variable" ]
  36. cflags += [ "-Wno-unused-but-set-variable" ]
  37. cflags += [ "-Wno-unused-parameter" ]
  38. cflags += [ "-Wno-sign-compare" ]
  39. cflags += [ "-Wno-unused-function" ]
  40. cflags += [ "-Wno-return-type" ]
  41.  
  42. qcloud_sdk_sources = [
  43. "sdk_src/network/socket/network_socket.c",
  44. "sdk_src/network/tls/network_tls.c",
  45. "sdk_src/network/network_interface.c",
  46.  
  47. "sdk_src/utils/utils_list.c",
  48. "sdk_src/utils/utils_base64.c",
  49. "sdk_src/utils/qcloud_iot_ca.c",
  50. "sdk_src/utils/utils_aes.c",
  51. "sdk_src/utils/utils_getopt.c",
  52. "sdk_src/utils/utils_hmac.c",
  53. "sdk_src/utils/utils_md5.c",
  54. "sdk_src/utils/utils_sha1.c",
  55. "sdk_src/utils/json_parser.c",
  56. "sdk_src/utils/json_token.c",
  57. "sdk_src/utils/string_utils.c",
  58. "sdk_src/utils/utils_ringbuff.c",
  59. "sdk_src/utils/qcloud_iot_log.c",
  60. "sdk_src/utils/qcloud_iot_device.c",
  61. "sdk_src/utils/utils_timer.c",
  62.  
  63. "sdk_src/protocol/mqtt/mqtt_client_common.c",
  64. "sdk_src/protocol/mqtt/mqtt_client_connect.c",
  65. "sdk_src/protocol/mqtt/mqtt_client_net.c",
  66. "sdk_src/protocol/mqtt/mqtt_client_publish.c",
  67. "sdk_src/protocol/mqtt/mqtt_client_subscribe.c",
  68. "sdk_src/protocol/mqtt/mqtt_client_unsubscribe.c",
  69. "sdk_src/protocol/mqtt/mqtt_client_yield.c",
  70. "sdk_src/protocol/mqtt/mqtt_client.c",
  71.  
  72. "sdk_src/services/data_template/data_template_action.c",
  73. "sdk_src/services/data_template/data_template_client.c",
  74. "sdk_src/services/data_template/data_template_client_common.c",
  75. "sdk_src/services/data_template/data_template_client_json.c",
  76. "sdk_src/services/data_template/data_template_client_manager.c",
  77. "sdk_src/services/data_template/data_template_event.c",
  78.  
  79. "platform/os/liteos_m/HAL_Device_liteos_m.c",
  80. "platform/os/liteos_m/HAL_OS_liteos_m.c",
  81. "platform/os/liteos_m/HAL_TCP_liteos_m.c",
  82. "platform/os/liteos_m/HAL_Timer_liteos_m.c",
  83. # "./os/liteos_m/HAL_TLS_mbedtls_liteos_m.c",
  84. # "./tls/mbedtls/HAL_DTLS_mbedtls.c",
  85. "platform/tls/mbedtls/HAL_TLS_mbedtls.c",
  86.  
  87.  
  88. ]
  89.  
  90. lite_library("qcloud_sdk_static") {
  91. target_type = "static_library"
  92.  
  93. sources = qcloud_sdk_sources
  94. public_configs = [ ":qcloud_sdk_config" ]
  95. }
  96.  
  97. lite_library("qcloud_sdk_shared") {
  98. target_type = "shared_library"
  99. sources = qcloud_sdk_sources
  100. public_configs = [ ":qcloud_sdk_config" ]
  101. }
  102.  
  103. ndk_lib("qcloud_ndk") {
  104. if (board_name != "hi3861v100") {
  105. lib_extension = ".so"
  106. deps = [
  107. ":qcloud_sdk_shared"
  108. ]
  109. } else {
  110. deps = [
  111. ":qcloud_sdk_static"
  112. ]
  113. }
  114. head_files = [
  115. "//third_party/iot_link/network/mqtt/paho_mqtt/paho"
  116. ]
  117. }

整完之后就可以嘗試一下有沒有錯誤了.

2.在main里面寫邏輯,處理事情

我們把官方sdk里面的點(diǎn)燈demo拿過來,直接新建一個demo文件夾,把文件放進(jìn)去:

OpenHarmony繼續(xù)上云之騰訊云平臺

自己寫好BUILD.gn,跟之前華為云對接一個套路,大家這么聰明,不用我多說了:

  1. # Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13.  
  14. static_library("qcloud_demo") {
  15. sources = [
  16. # "iot_thread.c",
  17. "light.c",
  18. "light_data_template_sample.c"
  19.  
  20. ]
  21.  
  22. cflags = [ "-Wno-unused-variable" ]
  23. cflags += [ "-Wno-unused-but-set-variable" ]
  24.  
  25. include_dirs = [
  26. ".",
  27. "//foundation/communication/softbus_lite/os_adapter/include",
  28. "//utils/native/lite/include",
  29. "//kernel/liteos_m/components/cmsis/2.0",
  30. "//base/iot_hardware/peripheral/interfaces/kits",
  31. "//third_party"
  32.  
  33. ]
  34.  
  35. deps = [
  36. "//third_party/qcloud-iot-explorer-sdk-embedded-c-3.2.0:qcloud_sdk_static",
  37. # "//third_party/qcloud-iot-explorer-sdk-embedded-c-3.2.0/external_libs/mbedtls:mbedtls_static",
  38. ]
  39.  
  40.  
  41. }

然后在sample里面的sdk把這個文件夾開啟編譯:

OpenHarmony繼續(xù)上云之騰訊云平臺

這樣就完成了代碼的編寫了,很快樂有木有。

三.在云平臺上創(chuàng)建設(shè)備

其實(shí)創(chuàng)建設(shè)備的過程官方文檔也的確挺詳細(xì)的,幾乎不用再另外加工,這里給出官方的智能燈接入指南:

https://cloud.tencent.com/document/product/1081/41155

官方定義了許多的物模型,其實(shí)我們的產(chǎn)品可能是官方物模型沒有定義的,此時我們就需要自己定義產(chǎn)品的屬性,事件和動作等,這塊自己仔細(xì)閱讀官方文檔就能搞懂

https://cloud.tencent.com/document/product/1081/34916

搞定了物模型,創(chuàng)建一個設(shè)備,記錄下設(shè)備的產(chǎn)品id,設(shè)備id和連接秘鑰

這點(diǎn)跟華為云平臺不太一樣,騰訊云的產(chǎn)品秘鑰是平臺生成的,而華為云平臺是你自己定義好設(shè)備的秘鑰,在創(chuàng)建設(shè)備的時候傳上去

四.編譯,運(yùn)行

編譯的過程倒是很順利,這里就不過多廢話了.

不過在運(yùn)行的時候出現(xiàn)一個情況,就是mutex不夠用了

自己折騰了一晚上也沒找不解決辦法,后面經(jīng)過請教猴哥才搞明白:

OpenHarmony繼續(xù)上云之騰訊云平臺

阿不對,下面這個候哥才對,大家可以去他主頁關(guān)注一下:

https://harmonyos.51cto.com/user/posts/13519852

候哥真大神也,短短一兩句話就幫我搞定了,在此特別感謝侯哥的幫助:

OpenHarmony繼續(xù)上云之騰訊云平臺

然后我就把我的mutex相關(guān)代碼改成posix接口,這是修改之前的:

  1. void *HAL_MutexCreate(void)
  2. {
  3. osMutexAttr_t attr;
  4. osMutexId_t mutex;
  5. char mutexName[RT_NAME_MAX];
  6. static uint32_t mutex_v;
  7.  
  8. attr.name = mutexName;
  9. attr.cb_mem = &mutex_v;
  10. attr.cb_size = 4;
  11.  
  12. mutex = osMutexNew(&attr);
  13. if (NULL == mutex) {
  14. HAL_Printf("create mutex failed");
  15. }
  16.  
  17. return mutex;
  18. }
  19.  
  20. void HAL_MutexDestroy(_IN_ void *mutex)
  21. {
  22. int err_num;
  23.  
  24. err_num = osMutexDelete((osMutexId_t)mutex);
  25.  
  26. if (0 != err_num) {
  27. HAL_Printf("destroy mutex failed");
  28. }
  29. }
  30.  
  31. void HAL_MutexLock(_IN_ void *mutex)
  32. {
  33. int err_num;
  34.  
  35. err_num = osMutexAcquire((osMutexId_t)mutex, osWaitForever);
  36.  
  37. if (0 != err_num) {
  38. HAL_Printf("lock mutex failed");
  39. }
  40. }
  41.  
  42. void HAL_MutexUnlock(_IN_ void *mutex)
  43. {
  44. int err_num;
  45.  
  46. err_num = osMutexRelease((osMutexId_t)mutex);
  47.  
  48. if (0 != err_num) {
  49. HAL_Printf("unlock mutex failed");
  50. }
  51. }
  52.  
  53. int HAL_MutexTryLock(_IN_ void *mutex)
  54. {
  55. int err_num;
  56.  
  57. err_num = osMutexAcquire((osMutexId_t)mutex, osNoWait);
  58.  
  59. if (0 != err_num) {
  60. HAL_Printf("trylock mutex failed");
  61. }
  62. return err_num;
  63. }

改完之后是這樣:

  1. void *HAL_MutexCreate(void)
  2. {
  3. // osMutexAttr_t attr;
  4. // osMutexId_t mutex;
  5. char mutexName[RT_NAME_MAX];
  6. static uint32_t mutex_v;
  7.  
  8. pthread_mutex_t * mutex = HAL_Malloc(sizeof(pthread_mutex_t));
  9. pthread_mutexattr_t attr;
  10.  
  11. int ret = pthread_mutex_init(mutex, &attr); // osMutexNew(&attr);
  12. // if (NULL == mutex) {
  13. if (ret != 0) {
  14. HAL_Printf("create mutex failed ");
  15. }
  16.  
  17. return mutex;
  18. }
  19.  
  20. void HAL_MutexDestroy(_IN_ void *mutex)
  21. {
  22. int err_num;
  23.  
  24. err_num = pthread_mutex_destroy(mutex);
  25.  
  26. if (0 != err_num) {
  27. HAL_Printf("destroy mutex failed");
  28. }
  29. }
  30.  
  31. void HAL_MutexLock(_IN_ void *mutex)
  32. {
  33. int err_num;
  34.  
  35. err_num = pthread_mutex_lock(mutex);
  36.  
  37. if (0 != err_num) {
  38. HAL_Printf("lock mutex failed");
  39. }
  40. }
  41.  
  42. void HAL_MutexUnlock(_IN_ void *mutex)
  43. {
  44. int err_num;
  45.  
  46. err_num = pthread_mutex_unlock(mutex);
  47.  
  48. if (0 != err_num) {
  49. HAL_Printf("unlock mutex failed");
  50. }
  51. }
  52.  
  53. int HAL_MutexTryLock(_IN_ void *mutex)
  54. {
  55. int err_num;
  56. struct timespec absTimeout={0,0};
  57.  
  58. err_num = pthread_mutex_timedlock(mutex, &absTimeout);
  59.  
  60. if (0 != err_num) {
  61. HAL_Printf("trylock mutex failed");
  62. }
  63. return err_num;
  64. }

使用的時候記得加上頭文件: #include

處理完這個異常情況,接下來就很順利的登錄騰訊云平臺收發(fā)數(shù)據(jù)了

五.云平臺控制展示

直接查看動圖,控制還是很及時的:

OpenHarmony繼續(xù)上云之騰訊云平臺

六.總結(jié)

其實(shí)對接騰訊云還是蠻簡單的,最新版的sdk在打印上也比以前好多了.OpenHarmony的2.x版本優(yōu)化了不少東西,記得去年這時候用1.x版本對接的時候還是很費(fèi)勁的,給OpenHarmony團(tuán)隊點(diǎn)贊,也給騰訊云團(tuán)隊點(diǎn)贊

大家趕緊玩起來吧

原文鏈接:https://harmonyos.51cto.com

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产一级片91 | 精品国产91久久久久久久 | 精品成人免费一区二区三区 | 国产羞羞视频免费在线观看 | 嫩草影院在线观看网站成人 | 国产91精品一区二区麻豆亚洲 | 成人视屏免费看 | 欧美精品黄色 | 成人午夜在线观看视频 | 精品国产一区二区三区天美传媒 | 成人在线观看网 | 色播视频在线播放 | 欧美人xx | 欧美一级高潮片免费的 | 一区国产精品 | 国产98色在线 | 韩国草草影院 | 一区在线视频观看 | 久久污 | 成人一级黄色大片 | 亚洲一级簧片 | 免费色片| 国产妇女乱码一区二区三区 | 福利在线免费 | 午夜视频成人 | 欧美乱淫 | 一区二区三区欧美日韩 | 黄色网址电影 | 羞羞答答www网站进入 | 国产精品一区二区三区在线看 | 欧美性受xxx黑人xyx性爽 | 日本xxxx色视频在线观看免费, | 欧美一级成人 | 91视频网国产| 亚洲第一综合 | 97超视频在线观看 | 亚洲乱妇19p| 成人9禁啪啪无遮挡免费 | xfplay噜噜av| 亚洲国产小视频 | 国产日韩大片 |