diff --git a/src/logger.c b/src/logger.c index d09220e..3f49528 100644 --- a/src/logger.c +++ b/src/logger.c @@ -115,8 +115,6 @@ int main (int argc, char *argv []) // Get power measurement timestamp: clock_gettime(CLOCK_REALTIME,&power_ts); char line[MAX_RECORD_LEN]; - sprintf(line,"%ld,%ld,%d\n",power_ts.tv_sec,power_ts.tv_nsec,atoi(buffer)); - int linelen=strlen(line); if((queues[queue_id].size+MAX_RECORD_LEN)>ZMQ_MSG_SIZE){ printf("To many measurements to publish. Please increase ZMQ_MSG_SIZE\n"); } else { diff --git a/src/subscriber.c b/src/subscriber.c index 1024041..9902d92 100644 --- a/src/subscriber.c +++ b/src/subscriber.c @@ -73,7 +73,11 @@ int main (int argc, char *argv []) } // Now open output file: sprintf(path,"%s/%s/%s/%ld",cdatadir,key,client,interval); + char exists=FILE_EXISTS(path); fptr=fopen(path,"a"); + if(!exists){ + fwrite(CSV_HEADER"\n", strlen(CSV_HEADER)+1, 1, fptr); + } } // Write all the measurements: diff --git a/src/utils.h b/src/utils.h index 2f5f82a..5cf2b3c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -12,6 +12,7 @@ #define STATIC_LEN 255 #define MAX_RECORD_LEN 100 #define MAX_QUEUES 1 +#define CSV_HEADER "timestamp,nsecs,power" #ifndef ZMQ_TOKEN #define ZMQ_TOKEN "ina260-zmq-publisher"