forked from arjenv/omnikstats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omnikstats.c
95 lines (77 loc) · 1.93 KB
/
omnikstats.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
** omnikstats.c
**
** This program searches the LAN for your Omnik inverter and -if found-
** downloads statistics from it
**
** Author: Beach
** V1.1 sept,13 2013
** V1.1 Changed: Added optional IP & serialnumber to be read from omnik.conf file
*/
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <unistd.h>
#include "omnikstats.h"
static void usage(const char *name)
{
fprintf(stderr, "Usage: %s [-v] [-l]\n\n"
"Where:\n"
"\t-v be verbose\n"
"\t-vv be more verbose\n"
"\t-vvv Even more verbose\n"
"\t-l Log statistics in a CSV file\n"
"\n", name);
exit(1);
}
int main(int argc, char *argv[])
{
int i;
char server_reply[256];
int opt;
stats.verbose = 0;
stats.logcsv = 0;
*stats.IPnumber = 0;
stats.serial_number = 0;
while ((opt = getopt(argc, argv, "vl")) != -1) {
switch (opt) {
case 'v': //verbose`
stats.verbose += 1;
break;
case 'l': // Log to CSV
stats.logcsv = 1;
break;
case '?':
usage(argv[0]);
}
}
if (stats.verbose) {
printf("Verbose %d\n", stats.verbose);
if (stats.logcsv)
printf("Data will be logged to /<year>/data.csv\n");
}
// Read the config file
if (omnikreadconfig()) {
printf("Error in config file\n");
exit(1);
}
// If not predefined try and search for the Omnik
if (!stats.IPnumber) {
if ((i=omniksearch()) !=0) {
printf("Error in UDP: %d\n", i);
exit(1);
}
}
// Get the statistics
if ((i=omnikgetstats(server_reply)) != 0) {
printf("Error in TCP: %d\n", i);
exit(1);
}
// Fill the stats structure print to stdout if 2nd argument=1
omnikfillstruct(server_reply);
// append it to a CSV data file
if (stats.logcsv) omnikcsv();
// send it to pvoutput.org
omnikpvoutput();
return 0;
}