Commit 72bd42c0 authored by whmaizmy's avatar whmaizmy

【修改内容】1,增加comom下面的hal目录;2,增加kk_topic_mng.c,通过product type跟product code订阅

【提交人】陈伟灿
parent a3d22f20
......@@ -15,6 +15,6 @@ LDFLAGS += -lapi_com
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -static -lnanomsg
LDFLAGS += -L$(TOP_DIR)/common/ev -static -lev
LDFLAGS += -L$(TOP_DIR)/output/release/lib -static -lapi_com
LDFLAGS += -liot_cjson -liot_mqtt -lsqlite -ldl -lm -lanl
LDFLAGS += -liot_cjson -liot_mqtt -lsqlite -ldl -lm -lanl -lkk_hal
......@@ -13,5 +13,8 @@
#define PASSWORD "2ca1442865ff4cb99870f60f2c646190"
#define AUTO_CONN 1
#define CONNECT_TIMEOUT 3
#endif
......@@ -21,10 +21,9 @@
#include "MQTTAsync.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "kk_product.h"
#define THREAD_NUM 10
static int mqtt_start(void)
{
int count = 0;
......@@ -66,8 +65,9 @@ int main(int argc, char* argv[])
//KK_Data_Hdl_Init();
/*set the callback to get the device date to cloud*/
HAL_SetProduct_Type(PRODUCT_TPYE);
HAL_SetProduct_Code(PRODUCT_CODE);
kk_ipc_init(IPC_APP2MID,KK_Sendto_CloudData);
rc = mqtt_start();
return rc;
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kk_product.h"
const char KK_URI_SYS_PREFIX[] = "/sys/%s/%s/#";
int _kk_client_subscribe(char productType[PRODUCT_TYPE_LEN], char productCode[PRODUCT_CODE_LEN])
{
int res = 0, index = 0, fail_count = 0;
int url_len = 0;
printf("[%s][%d] \n",__FUNCTION__,__LINE__);
url_len = strlen(KK_URI_SYS_PREFIX) + strlen(productType) + strlen(productCode) + 1;
char *url = malloc(url_len);
if (url == NULL) {
return -1;
}
memset(url, 0, url_len);
snprintf(url, url_len, KK_URI_SYS_PREFIX, productType, productCode);
printf("[%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url);
res = KK_MQTT_SubTopic(url);
free(url);
return 0;
}
int KK_Client_Gateway_Subscribe(void)
{
char prpductType[PRODUCT_TYPE_LEN];
char prpductCode[PRODUCT_CODE_LEN];
HAL_GetProduct_Type(prpductType);
HAL_GetProduct_Code(prpductCode);
return _kk_client_subscribe(prpductType,prpductCode);
}
......@@ -124,7 +124,7 @@ static void onConnectBuild(void *context, char *cause)
{
int rc = 0;
INFO_PRINT("onConnectBuild:%s \n",cause);
rc = KK_MQTT_SubTopic(TOPIC);
rc = KK_Client_Gateway_Subscribe();
if(rc != 0)
{
ERROR_PRINT("KK_MQTT_SubTopic ERROR rc = %d\n",rc);
......
This diff is collapsed.
LIBA_TARGET := libkk_hal.a
\ No newline at end of file
#ifndef __KK_PRODUCT_H__
#define __KK_PRODUCT_H__
#include <stdio.h>
#ifndef _IN_
#define _IN_
#endif
#ifndef _OU_
#define _OU_
#endif
#define PRODUCT_TYPE_LEN (32+1)
#define PRODUCT_CODE_LEN (32+1)
#define DEVICE_CODE_LEN (64+1)
#define MAC_ADDR_LEN_MAX (10)
#define PID_STRLEN_MAX (64)
#define MID_STRLEN_MAX (64)
#define IOTX_URI_MAX_LEN (135) /* IoTx CoAP/HTTP uri & MQTT topic maximal length */
#define PID_STR_MAXLEN (64)
#define MID_STR_MAXLEN (64)
#define PRODUCT_SECRET_MAXLEN (64 + 1)
#define FIRMWARE_VERSION_MAXLEN (32 + 1)
#define HAL_CID_LEN (64 + 1)
#define PRODUCT_TPYE "a1OYuSBt23u"
#define PRODUCT_CODE "aIqEbWno8yDdsjCX15iq"
int HAL_SetProduct_Type(_IN_ char *product_type);
int HAL_SetProduct_Code(_IN_ char *product_code);
int HAL_SetDevice_Code(_IN_ char *device_code);
int HAL_GetProduct_Type(_OU_ char *product_type);
int HAL_GetProduct_Code(_OU_ char *product_code);
int HAL_GetDevice_Code(_OU_ char *device_code);
#endif
......@@ -18,6 +18,7 @@ SUBDIRS += common/api
SUBDIRS += common/nanomsg
SUBDIRS += common/ev
SUBDIRS += common/sqlite
SUBDIRS += common/hal
#SUBDIRS += platform/zigbee
$(call Append_Conditional, SUBDIRS)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment