powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. 56490f832d5a


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. 56490f832d5a50916a85fa80784f0b020efd5a44
Date: Sat, 22 Dec 2018 15:20:06 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  56490f832d5a50916a85fa80784f0b020efd5a44 (commit)
       via  b4a25a082210fc2067c6bd14e819082b68973c14 (commit)
       via  feb6d46fce148b2c00c81c8ea1410b74b429a5f5 (commit)
      from  a1c4e149e35485194c91d0a24c36059faa4fcc05 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=56490f832d5a50916a85fa80784f0b020efd5a44


commit 56490f832d5a50916a85fa80784f0b020efd5a44
Author: Rob Savoye <address@hidden>
Date:   Sat Dec 22 13:19:00 2018 -0700

    Handle errrors from PQexec

diff --git a/daemon/main.cc b/daemon/main.cc
index 455cf5c..07e2d83 100644
--- a/daemon/main.cc
+++ b/daemon/main.cc
@@ -1,5 +1,5 @@
 // 
-// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, 
Inc.
+// Copyright (C) 2005, 2006-2018 Free Software Foundation, Inc.
 // 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -83,14 +83,17 @@ std::mutex queue_lock;
 std::queue <XML> tqueue;
 std::condition_variable queue_cond;
 
+const char DEFAULT_ARGV[] = "-s 192.168.0.50:4304";
+
 int
 main(int argc, char *argv[])
 {
     int c, i;
-    string item, str;
+    std::string item, str;
     const char *filespec;
     MenuItem ti;
-    string hostname;
+    std::string hostname;
+    std::string owserver;
     bool poll;
     bool use_db;
     bool snmp;
@@ -153,7 +156,7 @@ main(int argc, char *argv[])
     
     filespec = DEFAULT_UART;
     // Process the command line arguments.
-    while ((c = getopt (argc, argv, "d:ahvm:cexnob:pu:w:rj")) != -1) {
+    while ((c = getopt (argc, argv, "d:ahvw:s:")) != -1) {
         switch (c) {
           case 'p':
               poll = true;
@@ -168,13 +171,23 @@ main(int argc, char *argv[])
               usage (argv[0]);
               break;
 
+          case 'w':
+              owserver = strdup(optarg);
+              break;
+#if 0
+          case 'c':
+              client = true;
+              daemon = false;
+              break;
+
           case 'o':
-              //outbackmode = true;
+              outbackmode = true;
               break;
 
           case 'r':
-              //background = true;
+              background = true;
               break;
+#endif
 
 #ifdef USE_SNMP
           case 'j':
@@ -183,40 +196,13 @@ main(int argc, char *argv[])
               client = false;
               break;
 #endif
-          case 'e':
-              echo = true;
-              break;
-        
-              // Don't use the database. The default is to use the database.
-          case 'n':
-              use_db = false;
-              break;
-
               // Specify database host machine.
 #if defined(HAVE_MARIADB) && defined(HAVE_POSTGRESQL)
           case 'm':
               pdb.dbHostSet(optarg);
               break;
               // Specify database name.
-          case 'b':
-              pdb.dbNameSet(optarg);
-              break;
-        
-              // Specify database user name.
-          case 'u':
-              pdb.dbUserSet(optarg);
-              break;
-        
-              // Specify database user password.
-          case 'w':
-              pdb.dbPasswdSet(optarg);
-              break;
 #endif
-          case 'c':
-              client = true;
-              daemon = false;
-              break;
-
           case 'v':
               // verbosity++;
               dbglogfile.set_verbosity();
@@ -246,7 +232,7 @@ main(int argc, char *argv[])
 
     std::thread client_thread (client_handler, std::ref(net));
 #ifdef BUILD_OWNET
-    Ownet ownet("localhost:4303");
+    Ownet ownet(DEFAULT_ARGV);
     std::thread ownet_thread (ownet_handler, std::ref(ownet));
 #endif
 #ifdef BUILD_XANTREX
@@ -324,35 +310,6 @@ main(int argc, char *argv[])
     }
 #endif
 
-#if 0
-    // Open a console for user input
-    Console con;
-    con.openCon();
-    con.makeRaw();
-    int ch = 0;
-    while ((ch = con.getcCon()) != 'q') {
-        if (ch > 0) {                // If we have something, process it
-            con.putcCon (ch);          // echo inputted character to screen
-            switch (ch) {
-              case 'Q':
-              case 'q':
-                  dbglogfile << "Qutting PowerGuru due to user input!" << 
std::endl;
-                  break;
-              case '?':
-                  con.putsCon("PowerGuru client\n");
-                  con.putsCon("\t? - help\r\n");
-                  con.putsCon("\tq - Quit\r\n");
-                  con.putsCon("\tQ - Quit\r\n");
-                  sleep(1);
-              default:
-                  break;
-            };
-        }
-    }
-
-    con.resetCon();
-#endif
-
     // Commands from the client via the client_handler get processed here
     // so messages can be passed between threads.
     while (true) {
@@ -431,11 +388,11 @@ usage (const char *prog)
     cerr << "for an inverter or charge controller" << endl;
     cerr << "Usage: " << prog << " [sglvphmdcx]" << endl;
 
+#if 0
     // enable SNMP daemon mode
     cerr << "SNMP Mode:" << endl;
     cerr << "\t-j\t\t\t\tEnable SNMP agent mode" << endl;
     cerr << "\t-r\t\t\t\trun in the background as a daemon." << endl;
-#if 0
     // Display the End User options
     cerr << "User Options:" << endl;
     // cerr << "\t-s [heading:item or name]\tSet Item value" << endl;
@@ -459,9 +416,6 @@ usage (const char *prog)
     // Display the Database options
     cerr << "Database Options:" << endl;
     cerr << "\t-m hostname\t\t\tSpecify Database hostname or IP" << endl;
-    cerr << "\t-u username\t\t\tSpecify User Name" << endl;
-    cerr << "\t-b dbname\t\t\tSpecify the Database" << endl;
-    cerr << "\t-w password\t\t\tSpecify the password" << endl;
 
     exit (-1);
 }
diff --git a/lib/postgresql.cc b/lib/postgresql.cc
index 7540588..aaab241 100644
--- a/lib/postgresql.cc
+++ b/lib/postgresql.cc
@@ -122,16 +122,19 @@ Database::closeDB (void)
 bool
 Database::queryInsert(const std::string &query)
 {
-    DEBUGLOG_REPORT_FUNCTION;
+    //DEBUGLOG_REPORT_FUNCTION;
 
     int retries, result;
     std::string str = "INSERT INTO onewire VALUES(";
     str += query + ");";
+
+    //dbglogfile << "Query is: " << query << endl;
     
-    PQexec(_connection, str.c_str());
-    dbglogfile << "Query is: " << str << endl;
+    if (PQexec(_connection, str.c_str()) == nullptr) {
+        std::cerr << "Lost connection to the database server, shutting 
down..." << endl;
+        std::cerr << PQerrorMessage(_connection) << std::endl;
+    }
     
-    dbglogfile << "Lost connection to the database server, shutting down..." 
<< endl;
     return false;
 }
 

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=b4a25a082210fc2067c6bd14e819082b68973c14


commit b4a25a082210fc2067c6bd14e819082b68973c14
Author: Rob Savoye <address@hidden>
Date:   Sat Dec 22 13:18:31 2018 -0700

    Move database access to thread

diff --git a/daemon/threads.cc b/daemon/threads.cc
index 62c57e7..8c6e01b 100644
--- a/daemon/threads.cc
+++ b/daemon/threads.cc
@@ -139,6 +139,13 @@ ownet_handler(Ownet &ownet)
     DEBUGLOG_REPORT_FUNCTION;
     dbglogfile << "PowerGuru - 1 Wire Mode" << std::endl;
     bool poll = true;
+#ifdef HAVE_LIBPQ
+    Database pdb;
+    if (!pdb.openDB()) {
+        dbglogfile << "ERROR: Couldn't open database!" << std::endl;
+        exit(1);
+    }
+#endif
 
     // Open the network connection to the database.
     std::string query = "INSERT INTO onewire VALUES(";
@@ -147,16 +154,30 @@ ownet_handler(Ownet &ownet)
 
     std::map<std::string, ownet_t *> sensors = ownet.getSensors();
     std::map<std::string, ownet_t *>::iterator it;
-    while (ownet.getPollSleep() != 0) {
+    while (ownet.getPollSleep() > 0) {
         for (it = sensors.begin(); it != sensors.end(); it++) {
-            if (it->second->family == "10") {
-                ownet.getTemperature(it->first.c_str());
+            if (it->second->family == "10" | it->second->family == "28") {
+                boost::shared_ptr<temperature_t> temp = 
ownet.getTemperature(it->first.c_str());
+#ifdef HAVE_LIBPQ
+                std::string stamp;
+                stamp = pdb.gettime(stamp);
+                std::string query = temp->family;
+                query += ",\'" + temp->id + "\'";
+                query += ", \'" + temp->type + "\'";
+                query += ", \'" + stamp + "\'";
+                query += ", " + std::to_string(temp->lowtemp);
+                query +=  ", " + std::to_string(temp->hightemp);
+                query += ", " + std::to_string(temp->temp) + ", \'";
+                query += temp->scale;
+                query += "\'";
+                pdb.queryInsert(query);
+#endif
+                //ownet.dump();
             }
-        }
-        ownet.dump();
         
-        // Don't eat up all the cpu cycles!
-        
std::this_thread::sleep_for(std::chrono::seconds(ownet.getPollSleep()));
+            // Don't eat up all the cpu cycles!
+            
std::this_thread::sleep_for(std::chrono::seconds(ownet.getPollSleep()));
+        }
     }
 }
 #endif

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=feb6d46fce148b2c00c81c8ea1410b74b429a5f5


commit feb6d46fce148b2c00c81c8ea1410b74b429a5f5
Author: Rob Savoye <address@hidden>
Date:   Sat Dec 22 13:16:20 2018 -0700

    Fix port number

diff --git a/client/cmd.cc b/client/cmd.cc
index 945f0dd..3730376 100644
--- a/client/cmd.cc
+++ b/client/cmd.cc
@@ -101,7 +101,7 @@ main(int argc, char *argv[])
 
 #ifdef BUILD_OWNET_XXX
     // Talk directly to the OW daemon
-    Ownet ownet(pserver + ":4303");
+    Ownet ownet(pserver + ":4304");
     if (ownet.isConnected()) {
         if (ownet.hasSensors()) {
             dbglogfile << "and has sensors attached" << std::endl;

-----------------------------------------------------------------------

Summary of changes:
 client/cmd.cc     |  2 +-
 daemon/main.cc    | 88 +++++++++++++------------------------------------------
 daemon/threads.cc | 35 +++++++++++++++++-----
 lib/postgresql.cc | 11 ++++---
 4 files changed, 57 insertions(+), 79 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]