Commit 4660895f authored by chen.weican's avatar chen.weican

【修改内容】增加主机未连接云的标记文件

【提交人】陈伟灿
parent 19aa848a
......@@ -107,10 +107,12 @@ again:
if(rc == 0){
rc = mqtt_start();
if(rc < 0){
kk_write_disconnect_flag();
sleep(2);
goto again;
}
}else{
kk_write_disconnect_flag();
sleep(2);
goto again;
}
......
......@@ -21,6 +21,7 @@
#define BUFSIZE 1024
#define PRODUCTSECRET "123456"
int kk_execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len)
{
if(cmd == NULL || buf == NULL || buf_len == 0)
......@@ -347,7 +348,7 @@ int kk_start_ccu_register(void)
while(1){
h = select(sockfd +1, &t_set1, NULL, NULL, &tv);
//if (h == 0) continue;
if (h == -1) {
if (h < 0) {
close(sockfd);
return -1;
};
......@@ -355,7 +356,7 @@ int kk_start_ccu_register(void)
memset(buf, 0, 1024);
memset(buf2, 0, 1024);
i= read(sockfd, buf, 1024);
if (i==0){
if (i <= 0){
close(sockfd);
return -1;
}
......
......@@ -256,7 +256,7 @@ char* KK_Make_Topic(cJSON *info,cJSON *data)
if(device_code == NULL){
goto errorreturn;
}
if((!strcmp(product_code->valuestring,"15") || !strcmp(product_code->valuestring,"ccu_n12")) && \
if((!strcmp(product_code->valuestring,"15") || !strcmp(product_code->valuestring,KK_CCU_PRODUCTID)) && \
(strstr(type->valuestring,"thing/status/online") != NULL)){
KK_CCU_TOPIC_Subscribe();
}
......
......@@ -15,6 +15,17 @@ int KK_Send_CloudState(int state);
int kk_get_cloud_status(void){
return s_cloudStatus;
}
void kk_write_disconnect_flag(void)
{
if((access("/tmp/CLOUD_STATUS_FAIL",F_OK)) != 0){
system("touch /tmp/CLOUD_STATUS_FAIL");
}
}
void kk_remove_disconnect_flag(void){
if((access("/tmp/CLOUD_STATUS_FAIL",F_OK)) == 0){
system("rm /tmp/CLOUD_STATUS_FAIL");
}
}
/*Connect lost callback*/
static void connlost(void *context, char *cause)
{
......@@ -23,6 +34,7 @@ static void connlost(void *context, char *cause)
ERROR_PRINT("PARAM ERROR\n");
s_mqttStop = 1;
s_cloudStatus = DEVICE_OFFLINE;
kk_write_disconnect_flag();
KK_Send_CloudState(s_cloudStatus);
return;
}
......@@ -33,6 +45,7 @@ static void connlost(void *context, char *cause)
INFO_PRINT("\nConnection lost\n");
INFO_PRINT("cause: %s\n", cause);
s_cloudStatus = DEVICE_OFFLINE;
kk_write_disconnect_flag();
KK_Send_CloudState(s_cloudStatus);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
......@@ -106,6 +119,7 @@ void onConnect(void* context, MQTTAsync_successData* response)
{
INFO_PRINT("Successful connection\n");
s_cloudStatus = DEVICE_ONLINE;
kk_remove_disconnect_flag();
KK_Send_CloudState(s_cloudStatus);
}
......@@ -138,6 +152,7 @@ static void onConnectBuild(void *context, char *cause)
//ERROR_PRINT("KK_MQTT_SubTopic ERROR rc = %d\n",rc);
//}
s_cloudStatus = DEVICE_ONLINE;
kk_remove_disconnect_flag();
KK_Send_CloudState(s_cloudStatus);
}
static void onDisConnected(void *context, MQTTProperties* properties,enum MQTTReasonCodes reasonCode)
......
......@@ -786,16 +786,19 @@ void KK_Data_FromMid(void* str,int len)
}
if (strstr(msgtype->valuestring,SYNC_MSG_TYPE_REPLY) != NULL){
INFO_PRINT("syncinfo_reply handle!!!");
kk_parse_syncinfo(payload);
kk_create_syncinfo_to_sdk(payload,0);
kk_vp_syncinfo_handle(payload);
}else if (strstr(msgtype->valuestring,SYNCPUSH_MSG_TYPE_REPLY) != NULL){
INFO_PRINT("syncinfopush_reply handle!!!");
kk_parse_syncinfo(payload);
kk_create_syncinfo_to_sdk(payload,1);
kk_vp_syncinfo_handle(payload);
}
else if(strstr(msgtype->valuestring,"/thing/event/property/post")!= NULL){
INFO_PRINT("property post handle!!!");
if(is_ccu_msg(productCode,deviceCode)){
int type;
......@@ -806,25 +809,33 @@ void KK_Data_FromMid(void* str,int len)
kk_lan_property_post_deal(deviceCode->valuestring,payload);
}
}else if(strstr(msgtype->valuestring,"/thing/topo/delete")!= NULL){
INFO_PRINT("topo delete handle!!!");
kk_lan_device_delete_notify(payload);
}else if(strstr(msgtype->valuestring,"/thing/status/online")!= NULL){
INFO_PRINT("online handle!!!");
kk_device_onoffline_handle(payload,1);
}else if(strstr(msgtype->valuestring,"/thing/status/offline")!= NULL){
INFO_PRINT("offline handle!!!");
kk_device_onoffline_handle(payload,0);
}else if(strstr(msgtype->valuestring,"/thing/service/addDeviceToRoom_reply")!= NULL){
sleep(3);
INFO_PRINT("addDeviceToRoom_reply handle!!!");
device_add_sync(payload);
}else if(strstr(msgtype->valuestring,"/thing/event/alarmNotify")!= NULL){
INFO_PRINT("alarmNotify handle!!!");
cJSON * msgId = cJSON_GetObjectItem(payload, "msgId");
kk_device_alarm_handle(payload,productCode->valuestring,deviceCode->valuestring,msgId->valuestring);
}else if(strstr(msgtype->valuestring,"/thing/service/historyAlarm_reply")!= NULL){
printf("----------------->1\n");
INFO_PRINT("historyAlarm_reply handle!!!");
kk_device_historyalarm_handle(payload);
}else if(strstr(msgtype->valuestring,"/thing/service/delAlarm_reply")!= NULL){
INFO_PRINT("delAlarm_reply handle!!!");
kk_del_historyalarm_handle(payload);
}else if(strstr(msgtype->valuestring,"/thing/event/addSceneNotification/post")!= NULL){
INFO_PRINT("addSceneNotification handle!!!");
kk_lan_scene_handle(payload,1);
}else if(strstr(msgtype->valuestring,"/thing/event/deleteSceneNotification/post")!= NULL){
INFO_PRINT("deleteSceneNotification handle!!!");
kk_lan_scene_handle(payload,0);
}
......
......@@ -352,10 +352,10 @@ int kk_is_tcp_channel(char devCode[DEVICE_CODE_LEN]){
if (devCode == NULL || strlen(devCode) == 0){
return -1;
}
INFO_PRINT("[%s] devCode=%s \n", __FUNCTION__,devCode);
//INFO_PRINT("[%s] devCode=%s \n", __FUNCTION__,devCode);
for(;i < MAX_LISTEN_NUM; i++){
if(strcmp(devCode, g_tcp_ctrl[i].deviceCode) == 0){
INFO_PRINT("[%s] idx=%d ip=%s sock=%d\n", __FUNCTION__,i, g_tcp_ctrl[i].ip, g_tcp_ctrl[i].sock);
//INFO_PRINT("[%s] idx=%d ip=%s sock=%d\n", __FUNCTION__,i, g_tcp_ctrl[i].ip, g_tcp_ctrl[i].sock);
return g_tcp_ctrl[i].sock;
}
}
......
......@@ -293,12 +293,7 @@ int HAL_GetProduct_Code(_OU_ char *product_code)
return strlen(KK_CCU_PRODUCTID);
}
int HAL_GetDevice_Code(_OU_ char *dev_code)
{
strncpy(dev_code, KK_CCU_ID, strlen(KK_CCU_ID));
dev_code[strlen(KK_CCU_ID)] = '\0';
return strlen(KK_CCU_ID);
}
/*
* This need to be same with app version as in uOTA module (ota_version.h)
......
......@@ -23,7 +23,7 @@ SUBDIRS += common/nanomsg
SUBDIRS += common/ev
SUBDIRS += common/sqlite
SUBDIRS += common/hal
SUBDIRS += factory_test_src/src
#SUBDIRS += factory_test_src/src
#SUBDIRS += common/zlog
#SUBDIRS += platform/zigbee
......
......@@ -247,7 +247,6 @@ static cJSON *kk_get_gw_properties_info(cJSON *data)
propertyStr = (char*)sqlite3_column_text(stmt, DB_IDENTIFITER);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(valueType == KK_TSL_DATA_TYPE_TEXT){
cJSON_AddStringToObject(property, propertyStr, valueStr);
}else if(valueType == KK_TSL_DATA_TYPE_INT||
......@@ -1024,7 +1023,6 @@ static int kk_get_scenes_info(cJSON *data)
cJSON_AddNumberToObject(sceneArrayItem, KK_SYNC_SCENE_ENABLE_STR, 1);
}else{
cJSON_AddNumberToObject(sceneArrayItem, KK_SYNC_SCENE_ENABLE_STR, 0);
}
type = sqlite3_column_int(stmt, DB_SCENEINFO_SCENETYPE);
cJSON_AddNumberToObject(sceneArrayItem, KK_SYNC_SCENE_SCENETYPE_STR, type);
......@@ -1102,12 +1100,10 @@ char *kk_sync_get_info()
char version[32] = {0};
char cloudstatus_str[16] = {0};
cJSON *data = cJSON_CreateObject();
kk_get_rooms_info(data);
kk_get_devices_info(data);
kk_get_scenes_info(data);
//HAL_GetDevice_Code(ccu_deviceCode);
HAL_Get_ccuid(ccu_deviceCode);
HAL_GetProduct_Code(ccu_productCode);
HAL_GetVersion(version);
......
......@@ -187,9 +187,9 @@ void kk_sendData2gw(void* data, int len, char* chalMark){
}else{
kk_ipc_send_ex(IPC_MID2PLAT, data, newLen + 1, chalMark);
}
INFO_PRINT("start to send data to gw srart\n");
//INFO_PRINT("start to send data to gw srart\n");
kk_print_long_data(data,newLen);
INFO_PRINT("start to send data to gw end\n");
//INFO_PRINT("start to send data to gw end\n");
}
void split(char *src,const char *separator,char **dest,int *num) {
char *pNext;
......@@ -1142,7 +1142,7 @@ void *udp_dispatch_yield(void *args){
kk_property_db_get_rawdata("IPAddress",4, ipList, sizeof(ipList));
for(; idx < 10; idx++){
DEBUG_PRINT("ipList[%d][%s][%s] \n", idx, ipList[idx].deviceCode, ipList[idx].raw);
//DEBUG_PRINT("ipList[%d][%s][%s] \n", idx, ipList[idx].deviceCode, ipList[idx].raw);
if (strlen(ipList[idx].deviceCode)>0 && strlen(ipList[idx].raw)>0){
kk_set_tcp_channel_by_idx(idx, ipList[idx].deviceCode, ipList[idx].raw);
}
......
#!/bin/sh
#filepath="/home/kk"
filepath="/app/ccuApps"
/etc/init.d/S90dcron stop
if [ ! -f "/sbin/jq" ]
then
cp $filepath/jq /sbin
......@@ -39,9 +40,15 @@ if [ ! -d "$run_Dir" ]; then
mkdir ${run_Dir}
fi
#if [ ! -d "$tsl_Dir" ]; then
cp -rf $filepath/tsl ${run_Dir}/
#fi
if [ ! -d "$tsl_Dir" ]; then
cp -rf $filepath/tsl ${run_Dir}/
else
defaultVer=`cat ${filepath}/tsl/version`
curVer=`cat ${run_Dir}/tsl/version`
if [ $defaultVer != $curVer ]; then
cp -rf $filepath/tsl ${run_Dir}/
fi
fi
#if [ ! -d "$map_Dir" ]; then
cp -rf $filepath/map ${run_Dir}/
#fi
......@@ -68,11 +75,10 @@ sleep 2
$filepath/bin/kk_cloud &
sleep 5
$filepath/bin/smarthome_z3gw_nx5 -r0 -l3 --device-def=$filepath/kk_device_def.json --db=/data/kk/kk_z3gw.db --uart=/dev/ttyS1&
sleep 2
$filepath/bin/kk_lan --uart=/dev/ttyS3&
sleep 1
if [ ! -f /etc/cron.d/ccu ]; then
echo "*/1 * * * * /app/ccuApps/process_check.sh" > /etc/cron.d/ccu || { echo "ERROR:add ccu crontab rule failed."; exit 1;}
fi
/etc/init.d/S90dcron restart
ntpd -n -q -d -p stdtime.gov.hk &
exit 0
\ No newline at end of file
......@@ -2,7 +2,7 @@
"schema": "https://iot-ap.ikonke.com/model/gateway_2.json",
"productType":"gw",
"profile":{
"heartbeat": "3000",
"heartbeat": "300",
"productCode": "2",
"productName": "网关"
},
......
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