梅科尔工作室-BearPi-HM_Nano 设备联网上云 原创
一、 华为云IOT平台产品介绍
华为云物联网平台即华为设备接入服务(loT Device Access)提供海量设备连接上云、设备和云端双向消息通信、批量设备管理、远程控制和监控、OTA升级、设备联动规则等能力,并可将设备数据灵活流转到华为云其他服务,帮助物联网行业用户快速完成设备联网及行业应用集成。
华为IoT平台地址: https://www.huaweicloud.com/product/iothub.html
二、华为IOT平台产品创建
产品模型用于描述设备具备的能力和特性。开发者通过定义产品模型,在物联网平台构建一款设备的抽象模型,使平台理解该款设备支持的服务、属性、命令等信息,如颜色、开关等。
三、设备对接华为云IOT平台
3.1打开“D6_iot_cloud_oc”工程的
iot_cloud_oc_sample.c文件,查看实现MQTT协议对接华为loT平台的代码。
3.2 代码:
代码1:
static int task_main_entry(void)
{
app_msg_t *app_msg;
uint32_t ret = WifiConnect(“Hold”, “0987654321”);
device_info_init(CLIENT_ID, USERNAME, PASSWORD);
oc_mqtt_init();
oc_set_cmd_rsp_cb(oc_cmd_rsp_cb);
while (1)
{
app_msg = NULL;
(void)osMessageQueueGet(mid_MsgQueue, (void **)&app_msg_, NULL, 0U);
if (NULL != app_msg)
{
switch (app_msg->msg_type)
{
case en_msg_cmd:
deal_cmd_msg(&app_msg->msg.cmd);
break;
case en_msg_report:
deal_report_msg(&app_msg->msg.report);
break;
default:
break;
}
free(app_msg);
)
}
return 0;
}
代码2:
#Copyright © 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the “License”);
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#http://www.apache.org/licenses/LICENSE-2.0
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an “AS IS” BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
import(“//build/lite/config/component/lite_component.gni”)
lite_component(“app”) {
features = [
#“A1_kernal_thread:thread_example”,
#“A2_kernel_timer:timer_example”,
#“A3_kernel_event:event_example”,
#“A4_kernel_mutex:mutex_example”,
#“A5_kernel_semaphore:semaphore_example”,
#“A6_kernel_message:message_example”,
#"B1_basic_led_blink:led_example",
"B2_basic_button:button_example",
#"B3_basic_pwm_led:pwm_example",
#"B4_basic_adc:adc_example",
#"B5_basic_i2c_nfc:i2c_example",
#"B6_basic_uart:uart_example",
#"C1_e53_sf1_mq2:e53_sf1_example",
#"C2_e53_ia1_temp_humi_pls:e53_ia1_example",
#"C3_e53_sc1_pls:e53_sc1_example",
#"C4_e53_sc2_axis:e53_sc2_example",
#"C5_e53_is1_infrared:e53_is1_example",
"D1_iot_wifi_ap:wifi_ap",
#"D2_iot_wifi_sta_connect:wifi_sta_connect",
#"D3_iot_udp_client:udp_client",
#"D4_iot_tcp_server:tcp_server",
#"D5_iot_mqtt:iot_mqtt",
"D6_iot_cloud_oc:oc_mqtt",
#"D7_iot_cloud_onenet:onenet_mqtt",
#"D8_iot_cloud_oc_smoke:cloud_oc_smoke",
#"D9_iot_cloud_oc_light:cloud_oc_light",
#"D10_iot_cloud_oc_manhole_cover:cloud_oc_manhole_cover",
#"D11_iot_cloud_oc_infrared:cloud_oc_infrared",
#"D12_iot_cloud_oc_agriculture:cloud_oc_agriculture",
#"D13_iot_cloud_oc_gps:cloud_oc_gps",
]
}
3.3生成设备对接信息网址: https://iot—tool.obs-website.cn— north-4.myhuaweicloud.com/
3.4案例将演示如何在 BearPi-HM_Na n o
开发板上使用 MQTT 协议连接华为工 oT 平台,
需要将 E53_IA1 智慧农业扩展板
与 BearPi-HM_Nano 开发板安装在一起。
3.4 E53_IA1 智慧农业扩展板购买地址:https://item.taobao.com/item.htm?id=607878490044