当前位置: 首页 > news >正文

苏州装修公司网站建设怎么去营销自己的产品

苏州装修公司网站建设,怎么去营销自己的产品,南宁做网店,如何找到网站的模板页面一、华为云IoTDA创建产品 创建如下服务,并添加对应的属性和命令。 二、小熊派接入 根据小熊派官方示例代码D6完成了小熊派接入华为云并实现属性上传命令下发。源码:小熊派开源社区/BearPi-HM_Nano 1. MQTT连接代码分析 这部分代码在oc_mqtt.c和oc_mq…

一、华为云IoTDA创建产品

创建如下服务,并添加对应的属性和命令。

二、小熊派接入

根据小熊派官方示例代码D6完成了小熊派接入华为云并实现属性上传命令下发。源码:小熊派开源社区/BearPi-HM_Nano

1. MQTT连接代码分析

这部分代码在oc_mqtt.c和oc_mqtt.h中

/*该结构体在oc_mqtt.h中*用来存储与MQTT设备相关的认证和标识信息。
*/
struct bp_oc_info
{char client_id[OC_CLIENT_ID_LEN];char username[OC_USERNAME_LEN];char password[OC_PASSWORD_LEN];char user_device_id_flg;
};
typedef struct bp_oc_info *bp_oc_info_t;/*该函数在oc_mqtt.c中*在调用mqtt连接前,通过该函数对连接参数进行赋值
*/
void device_info_init(char *client_id, char * username, char *password)
{oc_info.user_device_id_flg = 1;strncpy(oc_info.client_id,  client_id, strlen(client_id));strncpy(oc_info.username,     username, strlen(username));strncpy(oc_info.password,  password, strlen(password));
}/*该函数在oc_mqtt.c中*调用该函数可以完成mqtt的连接*其中oc_mqtt_entry函数将根据云端地址进行连接,然后连接mqtt
*/
int oc_mqtt_init(void)
{int result = 0;if (init_ok){//LOG_D("oc mqtt already init!");return 0;}if (oc_mqtt_entry() < 0){result = -2;goto __exit;}__exit:if (!result){//LOG_I("oc package(V%s) initialize success.", oc_SW_VERSION);init_ok = 1;//官网这里为0,根据逻辑这里应该为连接成功,连接成功后应该置1避免重复连接。}else{//LOG_E("oc package(V%s) initialize failed(%d).", oc_SW_VERSION, result);}return result;
}

2. 属性上报

华为云IoTDA中,属性上报格式如下:

{"services": [{"service_id": "xxxxx",//服务ID为产品创建后添加的服务"properties": {"temp": 23//属性和对应的值}}]
}

在小熊派源码中通过结构体封装了属性上报的函数,调用方便代码分析如下

typedef struct
{void *nxt;char *service_id;                         ///< the service id in the profile, which could not be NULLchar *event_time;                         ///< eventtime, which could be NULL means use the platform timeoc_mqtt_profile_kv_t *service_property;   ///< the property in the profile, which could not be NULL
}oc_mqtt_profile_service_t;

该结构体位于oc_mqtt.h中,用于表示接入云端的一个服务内容,具体分析如下:

  • void *nxt;是一个指向下一个oc_mqtt_profile_service_t结构体的指针,用于实现服务的链表结构。通过这个字段,可以将多个服务链接在一起。
  • char *service_id;:是一个指向字符的指针,表示服务的ID。在配置文件中,服务的ID是必需的,不能为空(NULL)。
  • char *event_time;:是一个指向字符的指针,表示事件的时间。这个字段可以是NULL,表示使用平台的时间。
  • oc_mqtt_profile_kv_t *service_property;:是一个指向oc_mqtt_profile_kv_t结构体的指针,表示服务的属性。需要上报的属性。
typedef struct
{void                 *nxt;   ///< ponit to the next keychar                 *key;en_oc_profile_data_t  type;void                 *value;
}oc_mqtt_profile_kv_t;typedef enum
{EN_OC_MQTT_PROFILE_VALUE_INT = 0,EN_OC_MQTT_PROFILE_VALUE_LONG,EN_OC_MQTT_PROFILE_VALUE_FLOAT,EN_OC_MQTT_PROFILE_VALUE_STRING,           ///< must be ended with '\0'EN_OC_MQTT_PROFILE_VALUE_LAST,
}en_oc_profile_data_t;

该结构体位于oc_mqtt.h中,用于存储服务的属性它包含以下字段:

  • void *nxt;:是一个指向下一个oc_mqtt_profile_kv_t结构体的指针,用于实现键值对的链表结构。通过这个字段,可以将多个键值对链接在一起。
  • char *key;:这是一个指向字符的指针,表示键的名称。
  • en_oc_profile_data_t type;:这是一个枚举类型,表示值的类型。枚举en_oc_profile_data_t定义了多种数据类型,用于指定与键相关联的值的类型。
  • void *value;:这是一个指向任意类型数据的指针,表示与键相关联的值。由于value的类型是void*,它可以是任何类型的数据,具体类型由type字段指定。

通过这两个结构体构建上报属性的消息更加方便,能够动态添加属性。属性上报代码如下:

/*该函数位于iot_cloud_oc_sample.c中,将需要上报的属性进行初始化*/
static void deal_report_msg(report_t *report)
{oc_mqtt_profile_service_t service;oc_mqtt_profile_kv_t fish_temp;oc_mqtt_profile_kv_t fish_light;oc_mqtt_profile_kv_t fish_pump;oc_mqtt_profile_kv_t fish_heat;service.event_time = NULL;service.service_id = "HomeBox";service.service_property = &fish_temp;service.nxt = NULL;fish_temp.key = "FishTemp";fish_temp.value = &report->temp;fish_temp.type = EN_OC_MQTT_PROFILE_VALUE_INT;fish_temp.nxt = &fish_light;fish_light.key = "FishLight";fish_light.value = g_app_cb.light? "ON" : "OFF";fish_light.type = EN_OC_MQTT_PROFILE_VALUE_STRING;fish_light.nxt = &fish_pump;fish_pump.key = "FishPump";fish_pump.value = g_app_cb.pump ? "ON" : "OFF";fish_pump.type = EN_OC_MQTT_PROFILE_VALUE_STRING;fish_pump.nxt = &fish_heat;fish_heat.key = "FishHeat";fish_heat.value = g_app_cb.heat ? "ON" : "OFF";fish_heat.type = EN_OC_MQTT_PROFILE_VALUE_STRING;fish_heat.nxt = NULL;oc_mqtt_profile_propertyreport(USERNAME, &service);return;
}

其中oc_mqtt_profile_propertyreport函数位于oc_mqtt.h中,该函数是一个用于构建和发布 MQTT 消息,上报设备服务属性。该函数中间接调用了oc_mqtt_profile_package.c文件中的oc_mqtt_profile_propertyrepormake_servicesmake_servicemake_kvsprofile_fmtvalue函数,这些函数协同工作,以 JSON 格式创建服务属性,并通过 MQTT 发布。

int oc_mqtt_profile_propertyreport(char *deviceid,oc_mqtt_profile_service_t *payload)
{int ret = (int)en_oc_mqtt_err_parafmt;char *topic;char *msg;if(NULL == deviceid){if(NULL == s_oc_mqtt_profile_cb.device_id){return ret;}else{deviceid = s_oc_mqtt_profile_cb.device_id;}}if((NULL== payload) || (NULL== payload->service_id) || (NULL == payload->service_property)){return ret;}topic = topic_make(CN_OC_MQTT_PROFILE_PROPERTYREPORT_TOPICFMT, deviceid,NULL);msg = oc_mqtt_profile_package_propertyreport(payload);printf("msg:%s \r\n",msg);if((NULL != topic) && (NULL != msg)){ret = oc_mqtt_publish(topic,(uint8_t *)msg,strlen(msg),(int)en_mqtt_al_qos_1);}else{ret = (int)en_oc_mqtt_err_sysmem;}free(topic);free(msg);return ret;
}

oc_mqtt_profile_propertyreport -->oc_mqtt_profile_package_propertyreport(创建上报信息的json对象)–>make_services(创建json对象数组)–>make_service(创建属性json对象)–>make_kvs(创建属性json数组)–>profile_fmtvalue(创建各个属性内容的json对象)

  • oc_mqtt_profile_propertyreport函数
    • 这个函数负责构建并发布一个 MQTT 消息,该消息包含设备的服务属性报告。
    • 它首先检查deviceidpayload是否为NULL。如果是,则根据全局回调函数中的设备 ID 或返回错误。
    • 使用 topic_make 函数构建 MQTT 主题。
    • 使用oc_mqtt_profile_package_propertyreport 函数打包服务属性报告为消息。
    • 使用oc_mqtt_publish函数(同样未在代码中定义)发布 MQTT 消息。
    • 最后,释放分配的内存并返回结果。
  • make_services函数
    • 这个函数创建一个 JSON 数组,该数组包含多个服务对象的 JSON 表示。
    • 它遍历传入的service_info链表,为每个服务调用make_service函数,并将结果添加到 JSON 数组中。
    • 如果在内存分配过程中发生错误,它会跳转到EXIT_MEM标签,释放已分配的资源,并返回NULL
  • make_service函数
    • 这个函数创建一个 JSON 对象,该对象表示单个服务。
    • 它添加service_id、properties(使用make_kvs函数生成)和可选的event_time到 JSON 对象中。
    • 如果在内存分配过程中发生错误,它会跳转到EXIT_MEM`标签,释放已分配的资源,并返回NULL。
  • make_kvs函数:
    • 这个函数创建一个 JSON 对象,该对象包含键值对的列表,这些键值对表示服务的属性。
    • 它遍历传入的kvlst链表,为每个键值对调用profile_fmtvalue函数,并将结果添加到 JSON 对象中。
    • 如果在内存分配过程中发生错误,它会跳转到EXIT_MEM标签,释放已分配的资源,并返回NULL。
  • profile_fmtvalue函数:
    • 这个函数根据键值对的类型(整数、长整数、浮点数或字符串)创建一个相应的 JSON 值。
    • 它返回创建的 JSON 值,该值可以是数字或字符串。

3. 消息接收

在mqtt连接后,oc_mqtt.c文件中oc_mqtt_entry函数中设置了mqtt的回调函数mq_client.defaultMessageHandler = mqtt_callback;,在函数mqtt_callback中将接收到的值存入结构体oc_mqtt.cmd_rsp_cb中后续进行处理。

/*主函数*/
oc_set_cmd_rsp_cb(oc_cmd_rsp_cb);void oc_cmd_rsp_cb(uint8_t *recv_data, size_t recv_size, uint8_t **resp_data, size_t *resp_size)
{app_msg_t *app_msg;int ret = 0;app_msg = malloc(sizeof(app_msg_t));app_msg->msg_type = en_msg_cmd;app_msg->msg.cmd.payload = (char *)recv_data;printf("recv data is %.*s\n", recv_size, recv_data);ret = osMessageQueuePut(mid_MsgQueue, &app_msg, 0U, 0U);if (ret != 0){free(recv_data);}*resp_data = NULL;*resp_size = 0;
}/*oc_mqtt.c*/
void oc_set_cmd_rsp_cb(void (*cmd_rsp_cb)(uint8_t *recv_data, uint32_t recv_size, uint8_t **resp_data, uint32_t *resp_size))
{oc_mqtt.cmd_rsp_cb = cmd_rsp_cb;
}
  • 函数 oc_set_cmd_rsp_cb</font>

这个函数用于设置命令响应的回调函数。它接收一个参数:

  • void (*cmd_rsp_cb)(uint8_t *recv_data, uint32_t recv_size, uint8_t **resp_data, uint32_t *resp_size):这是一个函数指针,指向命令响应的回调函数。

函数内部逻辑如下:
- 将传入的回调函数 cmd_rsp_cb赋值给 oc_mqtt.cmd_rsp_cboc_mqtt 是一个结构体,用于存储MQTT相关的配置和状态,其中 cmd_rsp_cb成员用于存储命令响应的回调函数。

  • 回调函数oc_cmd_rsp_cb
    这个函数是命令响应的回调函数,当接收到命令时,这个函数会被调用。它接收四个参数:
    • uint8_t *recv_data:指向接收到的数据的指针。
    • size_t recv_size:接收到的数据的大小。
    • uint8_t **resp_data:指向响应数据的指针的地址,用于返回响应数据。
    • size_t *resp_size>:指向响应数据大小的指针,用于返回响应数据的大小。

接收到的消息存入消息队列进行处理


文章转载自:
http://ploughshoe.wghp.cn
http://ouidah.wghp.cn
http://comparative.wghp.cn
http://epidermic.wghp.cn
http://photochemical.wghp.cn
http://nutritive.wghp.cn
http://silenus.wghp.cn
http://contuse.wghp.cn
http://keystroke.wghp.cn
http://catacomb.wghp.cn
http://abnormalcy.wghp.cn
http://savanna.wghp.cn
http://then.wghp.cn
http://termitary.wghp.cn
http://hinnie.wghp.cn
http://carnaby.wghp.cn
http://erna.wghp.cn
http://poddock.wghp.cn
http://uneventful.wghp.cn
http://strawhat.wghp.cn
http://incisively.wghp.cn
http://pietermaritzburg.wghp.cn
http://nonrecognition.wghp.cn
http://homepage.wghp.cn
http://farandole.wghp.cn
http://mara.wghp.cn
http://injectable.wghp.cn
http://methylal.wghp.cn
http://clade.wghp.cn
http://osteosclerosis.wghp.cn
http://locule.wghp.cn
http://hexaplar.wghp.cn
http://empirism.wghp.cn
http://abas.wghp.cn
http://subshrub.wghp.cn
http://unoccupied.wghp.cn
http://fletschhorn.wghp.cn
http://townish.wghp.cn
http://metasomatosis.wghp.cn
http://hetaerism.wghp.cn
http://hmas.wghp.cn
http://interfusion.wghp.cn
http://megranate.wghp.cn
http://sculpin.wghp.cn
http://tormina.wghp.cn
http://bebeeru.wghp.cn
http://pembrokeshire.wghp.cn
http://antithrombotic.wghp.cn
http://celebrator.wghp.cn
http://captivation.wghp.cn
http://firebug.wghp.cn
http://beamwidth.wghp.cn
http://undecorative.wghp.cn
http://precordium.wghp.cn
http://was.wghp.cn
http://trafficker.wghp.cn
http://cymous.wghp.cn
http://unsuspicious.wghp.cn
http://astrobotany.wghp.cn
http://amused.wghp.cn
http://nature.wghp.cn
http://inscribe.wghp.cn
http://summarise.wghp.cn
http://migronaut.wghp.cn
http://machism.wghp.cn
http://extort.wghp.cn
http://demonetarize.wghp.cn
http://demiworld.wghp.cn
http://surround.wghp.cn
http://nte.wghp.cn
http://hsaa.wghp.cn
http://influential.wghp.cn
http://farinose.wghp.cn
http://blowtorch.wghp.cn
http://mediatrix.wghp.cn
http://supertype.wghp.cn
http://armored.wghp.cn
http://parlor.wghp.cn
http://notungulate.wghp.cn
http://loaded.wghp.cn
http://salerno.wghp.cn
http://fruiter.wghp.cn
http://seceder.wghp.cn
http://mood.wghp.cn
http://spousal.wghp.cn
http://pugree.wghp.cn
http://downloading.wghp.cn
http://rightless.wghp.cn
http://cantus.wghp.cn
http://eyen.wghp.cn
http://lowestoft.wghp.cn
http://erythritol.wghp.cn
http://burgee.wghp.cn
http://histosol.wghp.cn
http://mailbox.wghp.cn
http://reshuffle.wghp.cn
http://missense.wghp.cn
http://inextricable.wghp.cn
http://millivolt.wghp.cn
http://aeonian.wghp.cn
http://www.hrbkazy.com/news/70613.html

相关文章:

  • 网站开发方案 ppt上海发布最新情况
  • 网站制作价格行情广州抖音seo
  • 做网站时怎么更改区域内的图片重庆seo公司排名
  • 江阴做网站的公司小璇seo优化网站
  • 网站营销seo哪个公司可靠电话营销销售系统
  • 做脚垫版型的网站厦门seo服务
  • 商务网站需求说明书万网域名
  • 郑州公共住宅建设投资有限公司网站app推广拉新渠道
  • 做软件挣钱的网站百度惠生活商家入驻
  • 做文献ppt模板下载网站搜索引擎优化的方法有哪些?
  • 代做网站公司有哪些刷外链
  • 中天建设集团有限公司广西分公司su搜索引擎优化
  • crm外贸管理软件天津外贸seo推广
  • 做网站运营很累吧seo薪资seo
  • 中国常用网站seo门户 site
  • 网站建设所用的工具外包接单平台
  • 搭建网站需要备案吗郑州网络推广报价
  • 建旅游网站多少钱广州百度
  • 如何设计大型电商网站建设网站seo优化方案
  • b站怎么做推广长尾关键词搜索网站
  • 关于网站及新媒体平台建设的规划网站优化
  • 企业网站开发与管理网上有免费的网站吗
  • 深圳网站建设价钱seo外贸网站制作
  • 秦皇岛市网站制作公司论坛推广技巧
  • 制作网站费怎么做会计科目seo系统推广
  • 分类目录网站平台seo经验是什么
  • 新网站应该怎么做seo武汉网站推广公司
  • 网站建设试手需要买服务器吗seo网络优化推广
  • 汽车网站开发百度地图网页版进入
  • 做婚纱网站的图片个人网站制作模板主页