From 3fd934fc66956e08777aaa10bd2ee27c1bc62758 Mon Sep 17 00:00:00 2001 From: Roman Bazalevsky Date: Mon, 23 May 2016 19:56:26 +0300 Subject: [PATCH 1/1] =?utf8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0?= =?utf8?q?=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B0=20?= =?utf8?q?=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D1=8F=20=D0=BE=D1=82=D0=BB=D0=B0?= =?utf8?q?=D0=B4=D0=BE=D1=87=D0=BD=D0=BE=D0=B9=20=D0=B8=D0=BD=D1=84=D0=BE?= =?utf8?q?=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B2=20stdout=20-=20?= =?utf8?q?=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8?= =?utf8?q?=D1=8E=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B0?= =?utf8?q?=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BF=D0=B8=D1=88?= =?utf8?q?=D0=B5=D1=82=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B2=20s?= =?utf8?q?yslog?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- weathermon | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/weathermon b/weathermon index 8470f63..19688cb 100755 --- a/weathermon +++ b/weathermon @@ -55,9 +55,10 @@ def find_port(): 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 @@ -106,12 +107,14 @@ def read_loop(ser,callback): try: line=read_port(ser) if line=="<>": - print "Reopening port..." - print line + if debug>0: + print "Reopening port..." + print line ser.close() if proc: try: - print "Terminating process..." + if debug>0: + print "Terminating process..." proc.terminate() sleep(5) finally: @@ -126,7 +129,8 @@ def read_loop(ser,callback): def print_log(str): global logging - print str + if debug>0: + print str if logging == "on": system("logger -t weathermon \""+str+"\"") @@ -151,11 +155,14 @@ def submit_narodmon(): queue=c.fetchall() - pprint(queue) + if debug>1: + pprint(queue) for (sensor,value) in queue: param[sensor] = value - pprint (param) + + if debug>1: + pprint (param) url = "http://narodmon.ru/post.php" @@ -208,11 +215,13 @@ def submit_owm(): queue=c.fetchall() - pprint(queue) + if debug>1: + pprint(queue) for (sensor,value) in queue: params[sensor]=value - pprint (params) + if debug>1: + pprint (params) try: @@ -360,7 +369,7 @@ def main(): 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; @@ -372,6 +381,10 @@ def init(): 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: -- 2.34.1