Добавлен ретранслятор MQTT-MYSQL
[weathermon.git] / weathermon
index 8470f635247e88eeeaf5e4052d03c3b91b12e3ce..19688cb9607ed4c95f086eb9d13195353a8b82fa 100755 (executable)
@@ -55,9 +55,10 @@ def find_port():
 
 def open_port(path):
 
 
 def open_port(path):
 
-  global proc
+  global proc, debug
 
 
-  print "Opening path "+path
+  if debug>0:
+    print "Opening path "+path
 
   if path == "-":
     return sys.stdin
 
   if path == "-":
     return sys.stdin
@@ -106,12 +107,14 @@ def read_loop(ser,callback):
     try:
       line=read_port(ser)
       if line=="<<TIMEOUT>>":
     try:
       line=read_port(ser)
       if line=="<<TIMEOUT>>":
-        print "Reopening port..."
-        print line
+        if debug>0:
+          print "Reopening port..."
+          print line
         ser.close()
         if proc:
           try:
         ser.close()
         if proc:
           try:
-            print "Terminating process..."
+            if debug>0:
+              print "Terminating process..."
             proc.terminate()
             sleep(5)
           finally:
             proc.terminate()
             sleep(5)
           finally:
@@ -126,7 +129,8 @@ def read_loop(ser,callback):
 
 def print_log(str):
   global logging
 
 def print_log(str):
   global logging
-  print str
+  if debug>0:
+    print str
   if logging == "on":
     system("logger -t weathermon \""+str+"\"")
 
   if logging == "on":
     system("logger -t weathermon \""+str+"\"")
 
@@ -151,11 +155,14 @@ def submit_narodmon():
 
   queue=c.fetchall()
 
 
   queue=c.fetchall()
 
-  pprint(queue)
+  if debug>1:
+    pprint(queue)
 
   for (sensor,value) in queue:
     param[sensor] = value  
 
   for (sensor,value) in queue:
     param[sensor] = value  
-  pprint (param)
+  
+  if debug>1:
+    pprint (param)
 
   url = "http://narodmon.ru/post.php"
 
 
   url = "http://narodmon.ru/post.php"
 
@@ -208,11 +215,13 @@ def submit_owm():
 
   queue=c.fetchall()
 
 
   queue=c.fetchall()
 
-  pprint(queue)
+  if debug>1:
+    pprint(queue)
 
   for (sensor,value) in queue:
     params[sensor]=value
 
   for (sensor,value) in queue:
     params[sensor]=value
-  pprint (params)
+  if debug>1:  
+    pprint (params)
 
   try:
 
 
   try:
 
@@ -360,7 +369,7 @@ def main():
 
 def init():
 
 
 def init():
 
-  global dbhost,dbuser,dbpasswd,path,serialnum,logging;
+  global dbhost,dbuser,dbpasswd,path,serialnum,logging,debug;
   global timeout,baud,narmon,devid;
   global owmuser,owmpasswd,owm_temp,owm_pres,owm_humi,owm_lat,owm_lon,owm_station;
   global alarm_script;
   global timeout,baud,narmon,devid;
   global owmuser,owmpasswd,owm_temp,owm_pres,owm_humi,owm_lat,owm_lon,owm_station;
   global alarm_script;
@@ -372,6 +381,10 @@ def init():
     dbhost = cfg.get("mysql","host")
     dbuser = cfg.get("mysql","user")
     dbpasswd = cfg.get("mysql","passwd")
     dbhost = cfg.get("mysql","host")
     dbuser = cfg.get("mysql","user")
     dbpasswd = cfg.get("mysql","passwd")
+    try:
+      debug = cfg.get("logging","debug")
+    except:
+      debug = 0  
     try:
       path = cfg.get("serial","port");
     except:
     try:
       path = cfg.get("serial","port");
     except: