成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

OpenHarmony繼續上云之騰訊云平臺

系統
說實話,騰訊云物聯網平臺一直是我比較喜歡的物聯網云太平,除了有騰訊大廠作為品質背書之外,提供的sdk也是相當好用,更有騰訊連連小程序可以幫助做界面,調試功能.

[[442860]]

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com

一.前面的話

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

二.首先下載sdk

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

#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區

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

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

把sdk下載之后,熟練的放進thirdparty文件夾,

#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區

不得不提一下,2.x版本的OpenHarmony比1.x版本的代碼結構清晰多了.

1.實現幾個重要接口

這個時候依然要看文檔,因為有些函數需要自己實現,具體是哪些呢,在這里:

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

這篇文檔寫了,我們要實現里面的這些接口,此處列舉一二:

#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區
#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區

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

#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區

寫出來這些后就可以準備編譯了嗎?

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

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

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

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

#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區

自己寫好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. #     http://www.apache.org/licenses/LICENSE-2.0 
  6. # Unless required by applicable law or agreed to in writing, software 
  7. # distributed under the License is distributed on an "AS IS" BASIS, 
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  9. # See the License for the specific language governing permissions and 
  10. # limitations under the License. 
  11.  
  12. static_library("qcloud_demo") { 
  13.     sources = [ 
  14.         # "iot_thread.c"
  15.         "light.c"
  16.         "light_data_template_sample.c" 
  17.         
  18.     ] 
  19.      
  20.     cflags = [ "-Wno-unused-variable" ] 
  21.     cflags += [ "-Wno-unused-but-set-variable" ] 
  22.      
  23.     include_dirs = [ 
  24.         "."
  25.         "//foundation/communication/softbus_lite/os_adapter/include"
  26.         "//utils/native/lite/include"
  27.         "//kernel/liteos_m/components/cmsis/2.0"
  28.         "//base/iot_hardware/peripheral/interfaces/kits"
  29.         "//third_party" 
  30.  
  31.     ] 
  32.  
  33.     deps = [  
  34.         "//third_party/qcloud-iot-explorer-sdk-embedded-c-3.2.0:qcloud_sdk_static"
  35.         # "//third_party/qcloud-iot-explorer-sdk-embedded-c-3.2.0/external_libs/mbedtls:mbedtls_static"
  36.     ] 
  37.  
  38.  

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

#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區

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

三.在云平臺上創建設備

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

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

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

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

搞定了物模型,創建一個設備,記錄下設備的產品id,設備id和連接秘鑰

這點跟華為云平臺不太一樣,騰訊云的產品秘鑰是平臺生成的,而華為云平臺是你自己定義好設備的秘鑰,在創建設備的時候傳上去

四.編譯,運行

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

不過在運行的時候出現一個情況,就是mutex不夠用了

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

[[442861]]

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

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

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

#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區

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

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

改完之后是這樣:

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

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

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

五.云平臺控制展示

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

#星光計劃2.0#  OpenHarmony繼續上云之騰訊云平臺-鴻蒙HarmonyOS技術社區

六.總結

其實對接騰訊云還是蠻簡單的,最新版的sdk在打印上也比以前好多了.OpenHarmony的2.x版本優化了不少東西,記得去年這時候用1.x版本對接的時候還是很費勁的,給OpenHarmony團隊點贊,也給騰訊云團隊點贊

大家趕緊玩起來吧

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com

 

責任編輯:jianghua 來源: 鴻蒙社區
相關推薦

2023-09-28 08:01:41

2013-07-18 10:10:31

2021-12-28 16:06:15

鴻蒙HarmonyOS應用

2012-06-13 11:10:59

2016-07-05 10:53:56

2015-05-05 11:20:09

騰訊云

2021-06-08 09:54:18

云計算混合云Region架構

2019-05-14 13:02:26

私有云公有云企業

2016-12-27 16:13:06

亞馬遜云阿里云騰訊云

2016-07-14 16:48:59

云計算

2022-10-26 11:59:05

騰訊云IaaSPaaS

2012-07-06 15:48:59

華為服務器

2020-11-29 15:09:15

騰訊云云開發代碼

2017-08-23 10:50:26

騰訊云政企轉型

2024-07-25 10:28:51

2018-12-10 23:01:44

2016-04-28 14:03:39

騰訊云計算CDN

2012-12-28 14:38:15

阿里云百度云騰訊云

2015-09-01 15:47:00

騰訊云安全云
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人av免费| 国产精品久久久久久久久久久久久久 | 日韩综合一区 | 又爽又黄axxx片免费观看 | 成人欧美一区二区三区色青冈 | av黄色免费| 久久婷婷av | 伊人久久一区二区 | 99re66在线观看精品热 | 一区二区三区中文字幕 | 中文一级片 | 国产精品久久久久久久一区探花 | 中文字幕一区二区三区四区五区 | 亚洲区一区二区 | 亚洲天堂日韩精品 | 福利久久 | 免费黄色片在线观看 | 久久草在线视频 | 国产小视频在线 | 九九热在线视频观看这里只有精品 | 四虎影院在线免费观看 | 精品国产一区二区三区久久影院 | 美女爽到呻吟久久久久 | 日本黄视频在线观看 | 亚洲成色777777在线观看影院 | 中文精品视频 | 亚洲一区二区免费 | 一级爱爱片 | 日批免费看 | 97精品超碰一区二区三区 | 亚洲视频一区二区三区四区 | 国产精品免费一区二区三区 | h视频在线观看免费 | 国产一级在线观看 | 日韩在线一区二区 | 永久免费av | 国产精品二区三区 | 亚洲福利一区 | www.伊人.com | 欧美精品久久久 | 国产馆|