Minor changes

This commit is contained in:
Loic Guegan 2023-07-15 14:36:48 +02:00
parent 5e8c2ae3b5
commit 59c454173d
4 changed files with 22 additions and 13 deletions

View file

@ -4,4 +4,5 @@ PUBLISHER_ADDR=localhost
##### Logger/Publisher
LOGGERS_DIR=./logs
LOG_INTERVAL=30
LOG_INTERVAL=30
KEY=node1

View file

@ -15,10 +15,11 @@ int main (int argc, char *argv [])
exit(1);
}
//----- Arguments
char *ip=argv[1];
int port=atoi(argv[2]);
// Socket to talk to server
//----- Init ZMQ
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
char bindto[30];
@ -31,12 +32,14 @@ int main (int argc, char *argv [])
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
ZMQ_TOKEN, strlen(ZMQ_TOKEN));
char buffer[10];
zmq_recv (subscriber, buffer, 10, 0);
printf("Received!");
//----- Listen
char buffer[ZMQ_MSG_SIZE];
int size;
while(1){
size=zmq_recv (subscriber, buffer, ZMQ_MSG_SIZE-1, 0);
buffer[size < ZMQ_MSG_SIZE ? size : ZMQ_MSG_SIZE - 1] = '\0';
printf("Received: %s\n",buffer);
}

View file

@ -11,15 +11,16 @@
// Global:
char *__logdir;
char *__key;
int __loginterval;
int __port;
void publish(void *publisher, char *filepath, char* client, int interval);
void publish(void *publisher, char *filepath, char* client, long int interval);
int main (int argc, char *argv [])
{
if(argc != 4){
printf("Usage: %s <abslogdir> <loginterval> <port>",argv[0]);
if(argc != 5){
printf("Usage: %s <abslogdir> <loginterval> <port> <key>",argv[0]);
exit(1);
}
@ -27,6 +28,7 @@ int main (int argc, char *argv [])
__logdir=argv[1];
__loginterval=atoi(argv[2]);
__port=atoi(argv[3]);
__key=argv[4];
//----- Prepare our context and publisher
void *context = zmq_ctx_new ();
@ -88,7 +90,9 @@ int main (int argc, char *argv [])
return 0;
}
void publish(void *publisher, char *filepath, char* client, int interval){
void publish(void *publisher, char *filepath, char* client, long int interval){
printf("Publish!\n");
zmq_send (publisher, ZMQ_TOKEN, strlen(ZMQ_TOKEN), 0);
char buffer[ZMQ_MSG_SIZE];
sprintf(buffer,"%s\n%s\n%ld",ZMQ_TOKEN,__key,interval);
zmq_send (publisher, buffer, ZMQ_MSG_SIZE, 0);
}

View file

@ -9,6 +9,7 @@
#define INA260_SYSFS "/sys/kernel/ina260"
#define INA260_POWER_REGISTER "registers/power"
#define ZMQ_TOKEN "ina260-zmq-publisher"
#define ZMQ_MSG_SIZE 255
#define STR(symbol) #symbol
#define STRINGIFY(symbol) STR(symbol)