
#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);
}



