Hallo
mein Plugin zum auslesen der ELV Wetterstation macht Probleme.
Vielleicht kann ja der ein oder andere mal drüber schauen ob grobe Schnitzer zu sehen sind.
Es läuft eine weile (1 bis 2 Tage), dann kommt ein Fehler.
Danach erschein cycle takes 1 seconds , was ja aus dem Plugin kommt nicht mehr im log. Jedoch gehen die Threads dieses Plugins in die Höhe.
Irrgentwas fange ich nicht ab.
Grüße Ronny
mein Plugin zum auslesen der ELV Wetterstation macht Probleme.
Vielleicht kann ja der ein oder andere mal drüber schauen ob grobe Schnitzer zu sehen sind.
Es läuft eine weile (1 bis 2 Tage), dann kommt ein Fehler.
Code:
2013-10-23 20:13:28 ERROR Dummy-8 Unhandled exception: 'utf-8' codec can't decode byte 0xdf in position 2719: invalid continuation byte <class 'UnicodeDecodeError'> File "/usr/lib/python3.2/threading.py", line 722, in _bootstrap self._bootstrap_inner() File "/usr/lib/python3.2/threading.py", line 762, in _bootstrap_inner (self.name, _format_exc())) File "/usr/lib/python3.2/traceback.py", line 269, in format_exc format_exception(etype, value, tb, limit, chain)) File "/usr/lib/python3.2/traceback.py", line 186, in format_exception list.extend(format_tb(tb, limit)) File "/usr/lib/python3.2/traceback.py", line 75, in format_tb return format_list(extract_tb(tb, limit)) File "/usr/lib/python3.2/traceback.py", line 100, in extract_tb line = linecache.getline(filename, lineno, f.f_globals) File "/usr/lib/python3.2/linecache.py", line 15, in getline lines = getlines(filename, module_globals) File "/usr/lib/python3.2/linecache.py", line 41, in getlines return updatecache(filename, module_globals) File "/usr/lib/python3.2/linecache.py", line 132, in updatecache lines = fp.readlines() File "/usr/lib/python3.2/codecs.py", line 300, in decode (result, consumed) = self._buffer_decode(data, self.errors, final)
Irrgentwas fange ich nicht ab.
Code:
#!/usr/bin/env python3 # vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab ######################################################################### # Copyright 2011 KNX-User-Forum e.V. https://knx-user-forum.de/ ######################################################################### # This file is part of SmartHome.py. http://smarthome.sourceforge.net/ # # SmartHome.py is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # SmartHome.py is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with SmartHome.py. If not, see <http://www.gnu.org/licenses/>. ######################################################################### import logging import threading from serial import Serial import struct import sys import string import time logger = logging.getLogger('usb_wde1') class usb_wde1(): def __init__(self, smarthome, tty, baudrate=9600, cycle=30): self._sh = smarthome self._cycle = int(cycle) self._baudrate = int(baudrate) self._tty = tty self._is_connected = False self._lock = threading.Lock() self._items = {} self.alive = True try: self._port_usb = Serial(port=self._tty, timeout=1, baudrate=self._baudrate) except Exception as e: logger.error("Could not open Serial Port {0} --> {1}".format(self._port_usb, e)) return else: self._is_connected = self._port_usb._isOpen if self._is_connected: logger.info("usb_wde1 connected") else: logger.error("Could not connect to usb_wde1") return def run(self): self.alive = True self._sh.scheduler.add('usb_wd1', self._refresh_data, prio=5, cycle=self._cycle) def stop(self): self.self._port_usb.close() self.alive = False def parse_item(self, item): if 'usb_wde1' in item.conf: sensor = item.conf['usb_wde1'] logger.debug("usb_wde1 item {0} connected to Sensor {1} ".format(item, sensor)) self._items[sensor] = {'item': item, 'logics': None} return None def parse_logic(self, logic): pass #regelmaeßig alles lesen def _refresh_data(self): if not self._is_connected: return False start = time.time() self._lock.acquire() rx = self._port_usb.readlines() logger.debug(" Read Data, {0} ".format(rx) ) if rx != []: for sensor in rx: data = str(sensor,'utf-8').split(';') for a in self._items: item = self._items[a]['item'] value = self._decode(a, data) logger.debug(" Decode Data, -- {0} --, item Value = {1} , item {2} ".format(a,value,item) ) item(value, 'usb_wde1', 'refresh') self._lock.release() cycletime = time.time() - start logger.info("cycle takes %d seconds", cycletime) def _decode(self, sensor, Data): if sensor == 'S1_Temp': return float(Data[3].replace(',', '.')) if sensor == 'S2_Temp': return float(Data[4].replace(',', '.')) if sensor == 'S3_Temp': return float(Data[5].replace(',', '.')) if sensor == 'S4_Temp': return float(Data[6].replace(',', '.')) if sensor == 'S5_Temp': return float(Data[7].replace(',', '.')) if sensor == 'S6_Temp': return float(Data[8].replace(',', '.')) if sensor == 'S7_Temp': return float(Data[9].replace(',', '.')) if sensor == 'S8_Temp': return float(Data[10].replace(',', '.')) if sensor == 'S1_Hum': return Data[11] if sensor == 'S2_Hum': return Data[12] if sensor == 'S3_Hum': return Data[13] if sensor == 'S4_Hum': return Data[14] if sensor == 'S5_Hum': return Data[15] if sensor == 'S6_Hum': return Data[16] if sensor == 'S7_Hum': return Data[17] if sensor == 'S8_Hum': return Data[18] if sensor == 'Komb_Temp': return float(Data[19].replace(',', '.')) if sensor == 'Komb_Hum': return Data[20] if sensor == 'Komb_Wind': return float(Data[21].replace(',', '.')) if sensor == 'Komb_Wippen': return Data[22] if sensor == 'Komb_Regen': return Data[23] return None
Kommentar