コード例 #1
0
ファイル: httpserver.py プロジェクト: daviessm/temper-python
def main():
    args = parse_args()
    quiet = args.celsius or args.fahrenheit or args.humidity

    logging.basicConfig(level = logging.ERROR if quiet else logging.WARNING)

    th = TemperHandler()
    devs = th.get_devices()
    if not quiet:
        print("Found %i devices" % len(devs))

    if(args.http_port):
        for dev in devs:
            if args.sensor_count is not None:
                # Override auto-detection from args
                dev.set_sensor_count(int(args.sensor_count))

            if args.sensor_ids == 'all':
                sensors = range(dev.get_sensor_count())
            else:
                sensors = [int(args.sensor_ids)]

            dev.attach()

        HTTPRequestHandler.devs = devs
        HTTPRequestHandler.sensors = sensors
        HTTPRequestHandler.quiet = quiet
        HTTPRequestHandler.args = args
        httpd = HTTPServer(('', args.http_port), HTTPRequestHandler)
        httpd.serve_forever()
コード例 #2
0
ファイル: snmp.py プロジェクト: rkabadi/temper-python
class Updater:
    def __init__(self, pp, logger, testmode=False):
        self.logger = logger
        self.pp = pp
        self.testmode = testmode
        self.usb_lock = threading.Lock()  # used to stop reinitialization interfering with update-thread
        self._initialize()

    def _initialize(self):
        with self.usb_lock:
            try:
                self.th = TemperHandler()
                self.devs = self.th.get_devices()
                self.logger.write_log("Found %i thermometer devices." % len(self.devs))
                for i, d in enumerate(self.devs):
                    self.logger.write_log(
                        "Initial temperature of device #%i: %0.1f degree celsius" % (i, d.get_temperature())
                    )
            except Exception as e:
                self.logger.write_log("Exception while initializing: %s" % str(e))

    def _reinitialize(self):
        # Tries to close all known devices and starts over.
        self.logger.write_log("Reinitializing devices")
        with self.usb_lock:
            for i, d in enumerate(self.devs):
                try:
                    d.close()
                except Exception as e:
                    self.logger.write_log("Exception closing device #%i: %s" % (i, str(e)))
        self._initialize()

    def update(self):
        if self.testmode:
            # APC Internal/Battery Temperature
            self.pp.add_int("318.1.1.1.2.2.2.0", 99)
            # Cisco devices temperature OIDs
            self.pp.add_int("9.9.13.1.3.1.3.1", 97)
            self.pp.add_int("9.9.13.1.3.1.3.2", 98)
            self.pp.add_int("9.9.13.1.3.1.3.3", 99)
        else:
            try:
                with self.usb_lock:
                    self.pp.add_int("318.1.1.1.2.2.2.0", int(max([d.get_temperature() for d in self.devs])))
                    for i, dev in enumerate(self.devs[:3]):  # use max. first 3 devices
                        self.pp.add_int("9.9.13.1.3.1.3.%i" % (i + 1), int(dev.get_temperature()))
            except Exception as e:
                self.logger.write_log("Exception while updating data: %s" % str(e))
                # Report an exceptionally large temperature to set off all alarms.
                # snmp_passpersist does not expose an API to remove an OID.
                for oid in ("318.1.1.1.2.2.2.0", "9.9.13.1.3.1.3.1", "9.9.13.1.3.1.3.2", "9.9.13.1.3.1.3.3"):
                    self.pp.add_int(oid, ERROR_TEMPERATURE)
                self.logger.write_log("Starting reinitialize after error on update")
                self._reinitialize()
コード例 #3
0
ファイル: cli.py プロジェクト: GM3D/temper-python
def main():
    th = TemperHandler()
    devs = th.get_devices()
    readings = []
    print("Found %i devices" % len(devs))

    for i, dev in enumerate(devs):
        readings.append({'device': i,
                         'temperature_c': dev.get_temperature(id=i),
                         'temperature_f':
                         dev.get_temperature(format="fahrenheit", id=i)
                         })

    for reading in readings:
        print('Device #%i: %0.1f°C %0.1f°F' % (reading['device'],
                                               reading['temperature_c'],
                                               reading['temperature_f']))
コード例 #4
0
ファイル: snmp.py プロジェクト: GM3D/temper-python
class Updater():
    def __init__(self, pp, logger, testmode=False):
        self.logger = logger
        self.pp = pp
        self.testmode = testmode
        self.usb_lock = threading.Lock() # used to stop reinitialization interfering with update-thread
        self._initialize()

    def _initialize(self):
        with self.usb_lock:
            try:
                self.th = TemperHandler()
                self.devs = self.th.get_devices()
                self.logger.write_log('Found %i thermometer devices.' % len(self.devs))
                for i, d in enumerate(self.devs):
                    self.logger.write_log('Initial temperature of device #%i: %0.1f degree celsius' % (i, d.get_temperature(id=i)))
            except Exception, e:
                self.logger.write_log('Exception while initializing: %s' % str(e))
コード例 #5
0
class Updater():
    def __init__(self, pp, logger, testmode=False):
        self.logger = logger
        self.pp = pp
        self.testmode = testmode
        self.usb_lock = threading.Lock() # used to stop reinitialization interfering with update-thread
        self._initialize()

    def _initialize(self):
        with self.usb_lock:
            try:
                self.th = TemperHandler()
                self.devs = self.th.get_devices()
                self.logger.write_log('Found %i thermometer devices.' % len(self.devs))
                for i, d in enumerate(self.devs):
                    self.logger.write_log('Initial temperature of device #%i: %0.1f degree celsius' % (i, d.get_temperature()))
            except Exception, e:
                self.logger.write_log('Exception while initializing: %s' % str(e))
コード例 #6
0
ファイル: cli.py プロジェクト: allo-/temper-python
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], ":hp", ["help"])
    except getopt.GetoptError as err:
        print(str(err))
        usage()
        sys.exit(2)
    disp_ports = False
    for o, a in opts:
        if o == "-p":
            disp_ports = True
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        else:
            assert False, "unhandled option"

    th = TemperHandler()
    devs = th.get_devices()
    readings = []
    print("Found %i devices" % len(devs))

    for i, dev in enumerate(devs):
        readings.append({'device': i,
                         'temperature_c': dev.get_temperature(),
                         'temperature_f':
                         dev.get_temperature(format="fahrenheit"),
                         'ports': dev.get_ports(),
                         'bus': dev.get_bus()
                         })

    for reading in readings:
        if disp_ports:
            portinfo = " (bus %s - port %s)" % (reading['bus'],
                                                reading['ports'])
        else:
            portinfo = ""
        print('Device #%i%s: %0.1f°C %0.1f°F' 
              % (reading['device'],
                 portinfo,
                 reading['temperature_c'],
                 reading['temperature_f']))
コード例 #7
0
def getTemp():
    th = TemperHandler()
    devs = th.get_devices()
    t = devs[0].get_temperatures()
    return  t[0]['temperature_c']
コード例 #8
0
    def temp_data():
        args = parse_args()
        quiet = args.celsius or args.fahrenheit
        logging.basicConfig(level = logging.ERROR if quiet else logging.WARNING)

        th = TemperHandler()
        devs = th.get_devices()
        if not quiet:
            print("Found %i devices" % len(devs))
        
        readings = []

        for dev in devs:
            if args.sensor_count is not None:
                # Override auto-detection from args
                dev.set_sensor_count(int(args.sensor_count))

            if args.sensor_ids == 'all':
                sensors = range(dev.get_sensor_count())
            else:
                sensors = [int(args.sensor_ids)]

            temperatures = dev.get_temperatures(sensors=sensors)
            humidities = dev.get_humidity(sensors=sensors)
            combinations = {}
            for k, v in temperatures.items():
                c = v.copy()
                try:
                    c.update(humidities[k])
                except:
                    pass
                combinations[k] = c
            readings.append(combinations)

        for i, reading in enumerate(readings):
            output = ''
            if quiet:
                if args.celsius:
                    dict_key = 'temperature_c'
                elif args.fahrenheit:
                    dict_key = 'temperature_f'
                elif args.humidity:
                    dict_key = 'humidity_pc'

                for sensor in sorted(reading):
                    output += '%0.1f; ' % reading[sensor][dict_key]
                output = output[0:len(output) - 2]
            else:
                portinfo = []
                tempinfo = [-1000]
                huminfo = [-1000]
                for sensor in sorted(reading):
                    if args.disp_ports and portinfo == '':
                        portinfo = " (bus %(bus)s - port %(ports)s)" % reading[sensor]
                    try:
                        tempinfo = reading[sensor]['temperature_c']
                    except:
                        pass
                    try:
                        huminfo = reading[sensor]['humidity_pc']
                    except:
                        pass
                # tempinfo = tempinfo[0:len(output) - 2]
                # huminfo = huminfo[0:len(output) - 2]
    
        return tempinfo,huminfo
コード例 #9
0
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], ":hpcfq", ["help"])
    except getopt.GetoptError as err:
        print(str(err))
        usage()
        sys.exit(2)
    degree_unit = False
    disp_ports = False
    quiet_output = False
    for o, a in opts:
        if o == "-p":
            disp_ports = True
        elif o == "-c":
            degree_unit = 'c'
        elif o == "-f":
            degree_unit = 'f'
        elif o == "-q":
            quiet_output = True
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        else:
            assert False, "unhandled option"

    if quiet_output and not degree_unit:
        print('You need to specify unit (-c of -f) when using -q option')
        sys.exit(1)

    th = TemperHandler()
    devs = th.get_devices()
    readings = []
    if not quiet_output:
        print("Found %i devices" % len(devs))

    for i, dev in enumerate(devs):
        readings.append({
            'device':
            i,
            'temperature_c':
            dev.get_temperature(),
            'temperature_f':
            dev.get_temperature(format="fahrenheit"),
            'ports':
            dev.get_ports(),
            'bus':
            dev.get_bus()
        })

    for reading in readings:
        if quiet_output:
            if degree_unit == 'c':
                print('%0.1f' % reading['temperature_c'])
            elif degree_unit == 'f':
                print('%0.1f' % reading['temperature_f'])
            else:
                print('how did I end up here?')
                sys.exit(1)
        else:
            if disp_ports:
                portinfo = " (bus %s - port %s)" % (reading['bus'],
                                                    reading['ports'])
            else:
                portinfo = ""
            print('Device #%i%s: %0.1f°C %0.1f°F' %
                  (reading['device'], portinfo, reading['temperature_c'],
                   reading['temperature_f']))
コード例 #10
0
def getTemp():
    th = TemperHandler()
    devs = th.get_devices()
    t = devs[0].get_temperatures()
    return  t[0]['temperature_c']
コード例 #11
0
ファイル: cli.py プロジェクト: TheTitanrain/temper-python
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], ":hpcfq", ["help"])
    except getopt.GetoptError as err:
        print(str(err))
        usage()
        sys.exit(2)
    degree_unit = False
    disp_ports = False
    quiet_output = False
    for o, a in opts:
        if o == "-p":
            disp_ports = True
        elif o == "-c":
            degree_unit = 'c'
        elif o == "-f":
            degree_unit = 'f'
        elif o == "-q":
            quiet_output = True
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        else:
            assert False, "unhandled option"

    if quiet_output and not degree_unit:
        print('You need to specify unit (-c of -f) when using -q option')
        sys.exit(1)

    th = TemperHandler()
    devs = th.get_devices()
    readings = []
    if not quiet_output:
        print("Found %i devices" % len(devs))

    for i, dev in enumerate(devs):
        readings.append({'device': i,
                         'temperature_c': dev.get_temperature(),
                         'temperature_f':
                         dev.get_temperature(format="fahrenheit"),
                         'ports': dev.get_ports(),
                         'bus': dev.get_bus()
                         })

    for reading in readings:
        if quiet_output:
            if degree_unit == 'c':
                print('%0.1f'
                    % reading['temperature_c'])
            elif degree_unit == 'f':
                print('%0.1f'
                    % reading['temperature_f'])
            else:
                print('how did I end up here?')
                sys.exit(1)
        else:
            if disp_ports:
                portinfo = " (bus %s - port %s)" % (reading['bus'],
                                                    reading['ports'])
            else:
                portinfo = ""
            print('Device #%i%s: %0.1f°C %0.1f°F' 
                  % (reading['device'],
                     portinfo,
                     reading['temperature_c'],
                     reading['temperature_f']))