-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cpp
63 lines (47 loc) · 1.25 KB
/
main.cpp
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
#include <iostream>
#include <fstream>
#include <ctime>
#include <string>
#include <sstream>
#include <sys/stat.h>
#include <stdlib.h>
#include "clientsocket.h"
#include "socketexception.h"
#include "jfyconnection.h"
using namespace std;
int main( int argc, char** argv )
{
Jfy::Connection conn( "/dev/ttyUSB0" );
string logPathRoot = "/var/log/solarmonj/";
if ( !conn.init() ) {
cerr << "Cannot initialise the connection." << endl;
return 1;
}
// Get the current time
time_t now = time(0);
// Get the data
Jfy::InverterData data;
conn.readNormalInfo( &data );
// Write to logstash
try
{
ClientSocket client_socket ( "localhost", 7022 );
try
{
stringstream ss;
ss << now << "," << data.temperature << "," << data.energyCurrent << "," << data.energyToday << "," << data.pvoltageAc << "," << data.voltageDc << "," << data.voltageAc << "," << data.frequency << "," << data.current << "\n";
client_socket << ss.str();
std::cout << "Sent\n";
}
catch (SocketException& e)
{
std::cout << "Error writing to logging server:\n\"" << e.description() << "\"\n";
}
}
catch (SocketException& e)
{
std::cout << "Error connecting to logging server:\n\"" << e.description() << "\"\n";
}
conn.close();
return 0;
}