mirror of
https://gitlab.com/manzerbredes/ina260-zmq-publisher.git
synced 2025-04-07 04:16:26 +02:00
Minor changes
This commit is contained in:
parent
adee9af472
commit
9f4eb5b6b8
1 changed files with 25 additions and 21 deletions
|
@ -17,7 +17,6 @@ void publish(void *publisher, char *filepath, char* client, long int interval);
|
||||||
|
|
||||||
int main (int argc, char *argv [])
|
int main (int argc, char *argv [])
|
||||||
{
|
{
|
||||||
printf("%s\n",ZMQ_TOKEN);
|
|
||||||
if(argc != 6){
|
if(argc != 6){
|
||||||
printf("Usage: %s <abslogdir> <loginterval> <ip> <port> <key>",argv[0]);
|
printf("Usage: %s <abslogdir> <loginterval> <ip> <port> <key>",argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -37,7 +36,7 @@ int main (int argc, char *argv [])
|
||||||
sprintf(bindto,"tcp://%s:%d",__ip,__port);
|
sprintf(bindto,"tcp://%s:%d",__ip,__port);
|
||||||
int rc = zmq_connect (publisher, bindto);
|
int rc = zmq_connect (publisher, bindto);
|
||||||
if(rc!=0){
|
if(rc!=0){
|
||||||
printf("Failed to bind zmq on %s\n",bindto);
|
printf("Failed to connect to %s\n",bindto);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,27 +46,32 @@ int main (int argc, char *argv [])
|
||||||
int interval=INTERVAL(__loginterval);
|
int interval=INTERVAL(__loginterval);
|
||||||
int interval_next=INTERVAL_NEXT(__loginterval);
|
int interval_next=INTERVAL_NEXT(__loginterval);
|
||||||
DIR *dr = opendir(__logdir);
|
DIR *dr = opendir(__logdir);
|
||||||
while ((de = readdir(dr)) != NULL){
|
if(dr !=NULL){
|
||||||
if(strcmp(de->d_name,".") && strcmp(de->d_name,"..")){
|
while ((de = readdir(dr)) != NULL){
|
||||||
char *client=de->d_name;
|
if(strcmp(de->d_name,".") && strcmp(de->d_name,"..")){
|
||||||
char logfile[255];
|
char *client=de->d_name;
|
||||||
char logfile_next[255];
|
char logfile[255];
|
||||||
sprintf(logfile,"%s/%s/%ld",__logdir,client,interval);
|
char logfile_next[255];
|
||||||
sprintf(logfile_next,"%s/%s/%ld",__logdir,client,interval_next);
|
sprintf(logfile,"%s/%s/%ld",__logdir,client,interval);
|
||||||
// As long as next logfile is not available, we should wait
|
sprintf(logfile_next,"%s/%s/%ld",__logdir,client,interval_next);
|
||||||
// for sending the current one
|
// As long as next logfile is not available, we should wait
|
||||||
printf("Waiting for %s...%s\n",client,logfile_next);
|
// for sending the current one
|
||||||
while(!FILE_EXISTS(logfile_next)){
|
printf("Waiting for %s logger measurements...\n",client);
|
||||||
sleep(1);
|
while(!FILE_EXISTS(logfile_next)){
|
||||||
}
|
sleep(1);
|
||||||
// Send current one
|
}
|
||||||
if(FILE_EXISTS(logfile)){
|
// Send current one
|
||||||
publish(publisher,logfile,client,interval);
|
if(FILE_EXISTS(logfile)){
|
||||||
remove(logfile);
|
publish(publisher,logfile,client,interval);
|
||||||
|
remove(logfile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
closedir(dr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
closedir(dr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq_close (publisher);
|
zmq_close (publisher);
|
||||||
|
@ -77,7 +81,7 @@ int main (int argc, char *argv [])
|
||||||
}
|
}
|
||||||
|
|
||||||
void publish(void *publisher, char *filepath, char* client, long int interval){
|
void publish(void *publisher, char *filepath, char* client, long int interval){
|
||||||
printf("Publish!\n");
|
printf("Publishing %s measurements\n",client);
|
||||||
char buffer[ZMQ_MSG_SIZE];
|
char buffer[ZMQ_MSG_SIZE];
|
||||||
sprintf(buffer,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,client,interval);
|
sprintf(buffer,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,client,interval);
|
||||||
int msglen=strlen(buffer);
|
int msglen=strlen(buffer);
|
||||||
|
|
Loading…
Add table
Reference in a new issue