if path[0] == "=":
import subprocess
+ sleep(3)
command=path[1:]
try:
command,args=command.split(' ',1)
try:
timeout_timer = Timer(timeout, thread.interrupt_main)
timeout_timer.start()
- line = ser.readline()
- return line.strip()
+
+ line=''
+ while line=='':
+ line = ser.readline()
+ line = line.strip()
+
+ return line
+
except KeyboardInterrupt:
return "<<TIMEOUT>>"
finally:
line=read_port(ser)
if line=="<<TIMEOUT>>":
print "Reopening port..."
+ print line
ser.close()
if proc:
- print "Terminating process..."
- proc.terminate()
- sleep(5)
+ try:
+ print "Terminating process..."
+ proc.terminate()
+ sleep(5)
+ finally:
+ None
ser=open_port(path)
if line:
callback(line)
def main():
weather_mon()
-try:
+def init():
+
+ global dbhost,dbuser,dbpasswd,path,serialnum,logging;
+ global timeout,baud,narmon,devid;
+ global owmuser,owmpasswd,owm_temp,owm_pres,owm_humi,owm_lat,owm_lon,owm_station;
+ global alarm_script;
- cfg = ConfigParser.RawConfigParser(allow_no_value=True)
- cfg.readfp(open('/etc/weathermon.conf'))
- dbhost = cfg.get("mysql","host")
- dbuser = cfg.get("mysql","user")
- dbpasswd = cfg.get("mysql","passwd")
- try:
- path = cfg.get("serial","port");
- except:
- path = None
- try:
- serialnum = cfg.get("serial","id")
- except:
- serialnum = None
- try:
- logging = cfg.get("logging","enabled")
- except:
- logging = None
- try:
- timeout = int(cfg.get("serial","timeout"))
- except:
- timeout = 120
- try:
- baud = int(cfg.get("serial","baud"))
- except:
- baud = 57600
- try:
- narmon = cfg.get("narodmon","enable")
- except:
- narmon = 'off'
- try:
- devid = cfg.get("narodmon","devid")
- except:
- devid = "{:0>12X}".format(getnode())
- try:
- owmuser = cfg.get("openweathermap","user")
- owmpasswd = cfg.get("openweathermap",'passwd')
- except:
- owmuser = None
- if owmuser:
- owm_temp = cfg.get("openweathermap",'temp')
- owm_pres = cfg.get("openweathermap",'pres')
- owm_humi = cfg.get("openweathermap",'humi')
- owm_lat = cfg.get("openweathermap",'lat')
- owm_lon = cfg.get("openweathermap",'lon')
- owm_station = cfg.get("openweathermap",'station')
try:
- alarm_script = cfg.get("alarm","exec")
- import subprocess
- except:
- alarm_script = None
-
- reconnect()
+
+ cfg = ConfigParser.RawConfigParser(allow_no_value=True)
+ cfg.readfp(open('/etc/weathermon.conf'))
+ dbhost = cfg.get("mysql","host")
+ dbuser = cfg.get("mysql","user")
+ dbpasswd = cfg.get("mysql","passwd")
+ try:
+ path = cfg.get("serial","port");
+ except:
+ path = None
+ try:
+ serialnum = cfg.get("serial","id")
+ except:
+ serialnum = None
+ try:
+ logging = cfg.get("logging","enabled")
+ except:
+ logging = None
+ try:
+ timeout = int(cfg.get("serial","timeout"))
+ except:
+ timeout = 120
+ try:
+ baud = int(cfg.get("serial","baud"))
+ except:
+ baud = 57600
+ try:
+ narmon = cfg.get("narodmon","enable")
+ except:
+ narmon = 'off'
+ try:
+ devid = cfg.get("narodmon","devid")
+ except:
+ devid = "{:0>12X}".format(getnode())
+ try:
+ owmuser = cfg.get("openweathermap","user")
+ owmpasswd = cfg.get("openweathermap",'passwd')
+ except:
+ owmuser = None
+ if owmuser:
+ owm_temp = cfg.get("openweathermap",'temp')
+ owm_pres = cfg.get("openweathermap",'pres')
+ owm_humi = cfg.get("openweathermap",'humi')
+ owm_lat = cfg.get("openweathermap",'lat')
+ owm_lon = cfg.get("openweathermap",'lon')
+ owm_station = cfg.get("openweathermap",'station')
+ try:
+ alarm_script = cfg.get("alarm","exec")
+ import subprocess
+ except:
+ alarm_script = None
+
+ reconnect()
-except:
+ except:
- print_log("Cannot intialize system")
- exit()
+ print_log("Cannot intialize system")
+ exit()
if __name__ == "__main__":
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
+ init()
main()