mirror of
https://gitlab.com/manzerbredes/ina260-zmq-publisher.git
synced 2025-04-06 03:46:25 +02:00
Minor changes
This commit is contained in:
parent
5e8c2ae3b5
commit
59c454173d
4 changed files with 22 additions and 13 deletions
|
@ -4,4 +4,5 @@ PUBLISHER_ADDR=localhost
|
|||
|
||||
##### Logger/Publisher
|
||||
LOGGERS_DIR=./logs
|
||||
LOG_INTERVAL=30
|
||||
LOG_INTERVAL=30
|
||||
KEY=node1
|
17
src/client.c
17
src/client.c
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue