自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

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

[[442860]]

想了解更多內(nèi)容,請?jiān)L問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

一.前面的話

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

二.首先下載sdk

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

#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)

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

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

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

#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)

不得不提一下,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)里面的這些接口,此處列舉一二:

#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)
#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)

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

#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)

寫出來這些后就可以準(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. #     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里面的點(diǎn)燈demo拿過來,直接新建一個demo文件夾,把文件放進(jìn)去:

#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)

自己寫好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把這個文件夾開啟編譯:

#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)

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

三.在云平臺上創(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)過請教猴哥才搞明白:

[[442861]]

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

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

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

#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)

然后我就把我的mutex相關(guān)代碼改成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

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

五.云平臺控制展示

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

#星光計(jì)劃2.0#  OpenHarmony繼續(xù)上云之騰訊云平臺-鴻蒙HarmonyOS技術(shù)社區(qū)

六.總結(jié)

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

大家趕緊玩起來吧

想了解更多內(nèi)容,請?jiān)L問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

 

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2023-09-28 08:01:41

2012-06-13 11:10:59

2016-07-05 10:53:56

2013-07-18 10:10:31

2021-12-28 16:06:15

鴻蒙HarmonyOS應(yīng)用

2021-06-08 09:54:18

云計(jì)算混合云Region架構(gòu)

2019-05-14 13:02:26

私有云公有云企業(yè)

2016-07-14 16:48:59

云計(jì)算

2015-05-05 11:20:09

騰訊云

2012-07-06 15:48:59

華為服務(wù)器

2016-12-27 16:13:06

亞馬遜云阿里云騰訊云

2022-10-26 11:59:05

騰訊云IaaSPaaS

2024-07-25 10:28:51

2017-08-23 10:50:26

騰訊云政企轉(zhuǎn)型

2016-04-28 14:03:39

騰訊云計(jì)算CDN

2020-11-29 15:09:15

騰訊云云開發(fā)代碼

2017-11-14 14:21:15

甲骨文云大會SaaS

2023-01-10 16:22:41

2013-09-13 16:10:55

騰訊云開放平臺
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號