diff --git a/src/webcfg_mqtt.c b/src/webcfg_mqtt.c index e25ed0fd..fb841383 100755 --- a/src/webcfg_mqtt.c +++ b/src/webcfg_mqtt.c @@ -457,6 +457,7 @@ int createMqttHeader(char **header_list) char *deviceId_header = NULL, *doc_header = NULL; char *contenttype_header = NULL, *contentlen_header = NULL; char *DeviceWanMac = NULL, *DeviceWanMac_header = NULL; + char *deviceMac = NULL; struct timespec cTime; char currentTime[32]; char *currentTime_header=NULL; @@ -470,10 +471,14 @@ int createMqttHeader(char **header_list) WebcfgInfo("Start of createMqttHeader\n"); - if( get_deviceMAC() != NULL && strlen(get_deviceMAC()) !=0 ) + if( strlen(g_deviceId) ==0 ) { - strncpy(g_deviceId, get_deviceMAC(), sizeof(g_deviceId)-1); - WebcfgInfo("g_deviceId fetched is %s\n", g_deviceId); + deviceMac = get_deviceMAC(); + if(deviceMac != NULL) + { + strncpy(g_deviceId, get_deviceMAC(), sizeof(g_deviceId)-1); + WebcfgInfo("g_deviceId fetched is %s\n", g_deviceId); + } } if(strlen(g_deviceId)) @@ -968,20 +973,21 @@ int createMqttHeader(char **header_list) if(!get_global_supplementarySync()) { WebcfgInfo("Framing primary sync header\n"); - snprintf(*header_list, 1024, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\r\n\r\n", (deviceId_header!=NULL)?deviceId_header:"",(doc_header!=NULL)?doc_header:"", (version_header!=NULL)?version_header:"", (accept_header!=NULL)?accept_header:"", (schema_header!=NULL)?schema_header:"", (supportedVersion_header!=NULL)?supportedVersion_header:"", (supportedDocs_header!=NULL)?supportedDocs_header:"", (bootTime_header!=NULL)?bootTime_header:"", (FwVersion_header!=NULL)?FwVersion_header:"", (status_header!=NULL)?status_header:"", (currentTime_header!=NULL)?currentTime_header:"", (systemReadyTime_header!=NULL)?systemReadyTime_header:"", (uuid_header!=NULL)?uuid_header:"", (productClass_header!=NULL)?productClass_header:"", (ModelName_header!=NULL)?ModelName_header:"", (contenttype_header!=NULL)?contenttype_header:"", (contentlen_header!=NULL)?contentlen_header:"",(PartnerID_header!=NULL)?PartnerID_header:"", (DeviceWanMac_header!=NULL)?DeviceWanMac_header:""); + snprintf(*header_list, 1024, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\r\n\r\n", (deviceId_header!=NULL)?deviceId_header:"",(doc_header!=NULL)?doc_header:"", (version_header!=NULL)?version_header:"", (accept_header!=NULL)?accept_header:"", (schema_header!=NULL)?schema_header:"", (supportedVersion_header!=NULL)?supportedVersion_header:"", (supportedDocs_header!=NULL)?supportedDocs_header:"", (bootTime_header!=NULL)?bootTime_header:"", (FwVersion_header!=NULL)?FwVersion_header:"", (status_header!=NULL)?status_header:"", (currentTime_header!=NULL)?currentTime_header:"", (systemReadyTime_header!=NULL)?systemReadyTime_header:"", (uuid_header!=NULL)?uuid_header:"", (productClass_header!=NULL)?productClass_header:"", (ModelName_header!=NULL)?ModelName_header:"", (contenttype_header!=NULL)?contenttype_header:"", (contentlen_header!=NULL)?contentlen_header:"",(PartnerID_header!=NULL)?PartnerID_header:""); } else { WebcfgInfo("Framing supplementary sync header\n"); snprintf(*header_list, 1024, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\r\n\r\n", (deviceId_header!=NULL)?deviceId_header:"",(doc_header!=NULL)?doc_header:"", (version_header!=NULL)?version_header:"", (accept_header!=NULL)?accept_header:"", (schema_header!=NULL)?schema_header:"", (supportedVersion_header!=NULL)?supportedVersion_header:"", (supportedDocs_header!=NULL)?supportedDocs_header:"", (bootTime_header)?bootTime_header:"", (FwVersion_header)?FwVersion_header:"", (status_header)?status_header:"", (currentTime_header)?currentTime_header:"", (systemReadyTime_header!=NULL)?systemReadyTime_header:"", (uuid_header!=NULL)?uuid_header:"", (productClass_header!=NULL)?productClass_header:"", (ModelName_header!=NULL)?ModelName_header:"",(contenttype_header!=NULL)?contenttype_header:"", (contentlen_header!=NULL)?contentlen_header:"", (PartnerID_header!=NULL)?PartnerID_header:"",(supplementaryDocs_header!=NULL)?supplementaryDocs_header:"", (telemetryVersion_header!=NULL)?telemetryVersion_header:"", (AccountID_header!=NULL)?AccountID_header:"", (DeviceWanMac_header!=NULL)?DeviceWanMac_header:""); + WEBCFG_FREE(DeviceWanMac_header); } writeToDBFile("/tmp/header_list.txt", *header_list, strlen(*header_list)); WebcfgDebug("mqtt header_list is \n%s\n", *header_list); - freeMqttHeaders(contentlen_header,contenttype_header,PartnerID_header,ModelName_header,productClass_header,uuid_header,systemReadyTime_header,currentTime_header,status_header,FwVersion_header,bootTime_header,schema_header,accept_header,version_header,doc_header,deviceId_header,transaction_uuid,DeviceWanMac_header); + freeMqttHeaders(contentlen_header,contenttype_header,PartnerID_header,ModelName_header,productClass_header,uuid_header,systemReadyTime_header,currentTime_header,status_header,FwVersion_header,bootTime_header,schema_header,accept_header,version_header,doc_header,deviceId_header,transaction_uuid); return 0; } -void freeMqttHeaders(char *contentlen_header, char *contenttype_header, char *PartnerID_header, char *ModelName_header, char *productClass_header, char *uuid_header, char *systemReadyTime_header, char *currentTime_header, char *status_header, char *FwVersion_header, char *bootTime_header, char *schema_header, char *accept_header, char *version_header, char *doc_header, char *deviceId_header, char *transaction_uuid, char *DeviceWanMac_header) +void freeMqttHeaders(char *contentlen_header, char *contenttype_header, char *PartnerID_header, char *ModelName_header, char *productClass_header, char *uuid_header, char *systemReadyTime_header, char *currentTime_header, char *status_header, char *FwVersion_header, char *bootTime_header, char *schema_header, char *accept_header, char *version_header, char *doc_header, char *deviceId_header, char *transaction_uuid) { WEBCFG_FREE(contentlen_header); WEBCFG_FREE(contenttype_header); @@ -1000,7 +1006,6 @@ void freeMqttHeaders(char *contentlen_header, char *contenttype_header, char *Pa WEBCFG_FREE(doc_header); WEBCFG_FREE(deviceId_header); WEBCFG_FREE(transaction_uuid); - WEBCFG_FREE(DeviceWanMac_header); } //new thread created for processPayload diff --git a/src/webcfg_mqtt.h b/src/webcfg_mqtt.h index c41acb55..c390595c 100755 --- a/src/webcfg_mqtt.h +++ b/src/webcfg_mqtt.h @@ -72,6 +72,6 @@ void initWebconfigMqttTask(unsigned long status); rbusError_t setBootupSyncHeader(char *publishGetVal); rbusError_t mqttSubscribeInit(); int getMqttCMConnStatus(); -void freeMqttHeaders(char *contentlen_header, char *contenttype_header, char *PartnerID_header, char *ModelName_header, char *productClass_header, char *uuid_header, char *systemReadyTime_header, char *currentTime_header, char *status_header, char *FwVersion_header, char *bootTime_header, char *schema_header, char *accept_header, char *version_header, char *doc_header, char *deviceId_header, char *transaction_uuid, char *DeviceWanMac_header); +void freeMqttHeaders(char *contentlen_header, char *contenttype_header, char *PartnerID_header, char *ModelName_header, char *productClass_header, char *uuid_header, char *systemReadyTime_header, char *currentTime_header, char *status_header, char *FwVersion_header, char *bootTime_header, char *schema_header, char *accept_header, char *version_header, char *doc_header, char *deviceId_header, char *transaction_uuid); pthread_cond_t *get_global_mqtt_sync_condition(void); #endif