bravohe / sma-bluetooth

Automatically exported from code.google.com/p/sma-bluetooth
0 stars 0 forks source link

Fails to open database - when it shouldn't be trying! #114

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Configure smatool not to use mysql (comment out mysql lines in sma.conf)
2. Run smatool when no mysql database is listening

What is the expected output? What do you see instead?
Expected output is stuff from inverter.  Actual output is:
Can't connect to local MySQL server through socket 
'/var/run/mysqld/mysqld.sock' (2)

What version of the product are you using? On what operating system?
Latest version obtained through:
hg clone https://code.google.com/p/sma-bluetooth/
201302031126

Please provide any additional information below.

Code has not been auditted for similar problems, but patch to fix immediate 
issue follows.  Note the first segment of the patch seems to have been caused 
by someone adding some debug; IMHO braces are cheap and should almost always be 
used :-)

diff -r 5b25c83a1efc smatool.c
--- a/smatool.c Fri Oct 19 20:02:37 2012 +1100
+++ b/smatool.c Sun Feb 03 11:31:04 2013 +1100
@@ -1470,10 +1470,11 @@
            update_almanac(  &conf, sunrise_time, sunset_time );
         }
     }
-    if( mysql==1 ) 
-        if( debug == 1 ) printf( "Before Check Schema\n" ); 
-           if( check_schema( &conf, SCHEMA, debug ) != 1 )
+    if( mysql==1 ) {
+   if( debug == 1 ) printf( "Before Check Schema\n" ); 
+   if( check_schema( &conf, SCHEMA, debug ) != 1 )
             exit(-1);
+    }
     if(daterange==0 ) { //auto set the dates
         if( debug == 1 ) printf( "auto_set_dates\n" ); 
         auto_set_dates( &conf, &daterange, mysql, datefrom, dateto );
@@ -1974,7 +1975,9 @@
                   {
                       printf("%d-%02d-%02d %02d:%02d:%02d %-20s = %.0f %-20s\n", year, month, day, hour, minute, second, returnkeylist[return_key].description, currentpower_total/returnkeylist[return_key].divisor, returnkeylist[return_key].units );
                       inverter_serial=serial[3]*16777216+serial[2]*65536+serial[1]*256+serial[0];
-                      live_mysql( &conf, year, month, day, hour, minute, second, 
conf.Inverter, inverter_serial, returnkeylist[return_key].description, 
currentpower_total/returnkeylist[return_key].divisor, 
returnkeylist[return_key].units, debug );
+                      if (mysql) {
+                      live_mysql( &conf, year, month, day, hour, minute, second, 
conf.Inverter, inverter_serial, returnkeylist[return_key].description, 
currentpower_total/returnkeylist[return_key].divisor, 
returnkeylist[return_key].units, debug );
+                      }
                                    }
                                    else
                       printf("%d-%02d-%02d %02d:%02d:%02d NO DATA for %02x %02x = %.0f NO UNITS\n", year, month, day, hour, minute, second, (data+i+1)[0], (data+i+1)[1], currentpower_total );

Original issue reported on code.google.com by blard...@gmail.com on 3 Feb 2013 at 12:33