Minor changes

This commit is contained in:
Loic Guegan 2023-07-15 14:02:43 +02:00
parent b80973cbd0
commit 5e8c2ae3b5
3 changed files with 36 additions and 27 deletions

View file

@ -8,32 +8,40 @@
#include "utils.h"
int main (int argc, char *argv [])
{
// Socket to talk to server
printf ("Collecting updates from weather server...\n");
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
int rc = zmq_connect (subscriber, "tcp://"STRINGIFY(PUBLISHER_ADDR)":"STRINGIFY(PUBLISHER_PORT));
assert (rc == 0);
if(argc != 3){
printf("Usage: %s <address> <port>",argv[0]);
exit(1);
}
// Subscribe to zipcode, default is NYC, 10001
// Subscribe to zipcode, default is NYC, 10001
const char *filter = "Hello";
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
filter, strlen(filter));
assert (rc == 0);
char *ip=argv[1];
int port=atoi(argv[2]);
// Process 100 updates
int update_nbr;
char buffer[10];
for (update_nbr = 0; update_nbr < 100; update_nbr++) {
zmq_recv (subscriber, buffer, 10, 0);
printf("Received!");
}
// Socket to talk to server
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
char bindto[30];
sprintf(bindto,"tcp://%s:%d",ip,port);
int rc = zmq_connect (subscriber, bindto);
if(rc!=0){
printf("Failed to bind zmq on %s\n",bindto);
exit(1);
}
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
ZMQ_TOKEN, strlen(ZMQ_TOKEN));
zmq_close (subscriber);
zmq_ctx_destroy (context);
return 0;
char buffer[10];
zmq_recv (subscriber, buffer, 10, 0);
printf("Received!");
zmq_close (subscriber);
zmq_ctx_destroy (context);
return 0;
}

View file

@ -14,7 +14,7 @@ char *__logdir;
int __loginterval;
int __port;
void publish(char *filepath, char* client, int interval);
void publish(void *publisher, char *filepath, char* client, int interval);
int main (int argc, char *argv [])
{
@ -60,7 +60,7 @@ int main (int argc, char *argv [])
}
// Send current one
if(FILE_EXISTS(logfile)){
publish(logfile,client,interval);
publish(publisher,logfile,client,interval);
remove(logfile);
}
}
@ -88,6 +88,7 @@ int main (int argc, char *argv [])
return 0;
}
void publish(char *filepath, char* client, int interval){
void publish(void *publisher, char *filepath, char* client, int interval){
printf("Publish!\n");
zmq_send (publisher, ZMQ_TOKEN, strlen(ZMQ_TOKEN), 0);
}

View file

@ -6,9 +6,9 @@
#include <string.h>
#define MIN_INTERVAL 30
#define INA260_SYSFS "/sys/kernel/ina260"
#define INA260_POWER_REGISTER "registers/power"
#define ZMQ_TOKEN "ina260-zmq-publisher"
#define STR(symbol) #symbol
#define STRINGIFY(symbol) STR(symbol)