当前位置: 首页>>代码示例>>Python>>正文


Python IPConnection.disconnect方法代码示例

本文整理汇总了Python中tinkerforge.ip_connection.IPConnection.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python IPConnection.disconnect方法的具体用法?Python IPConnection.disconnect怎么用?Python IPConnection.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tinkerforge.ip_connection.IPConnection的用法示例。


在下文中一共展示了IPConnection.disconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: collect_data

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def collect_data(suffix):
    global SAMPLE_RATE
    global w1
    global row
    print "Now recording " + suffix

    ipcon = IPConnection() # Create IP connection
    imu = IMU(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Set period for quaternion callback to 1s
    imu.set_all_data_period(SAMPLE_RATE)
    imu.set_orientation_period(SAMPLE_RATE)
    imu.set_quaternion_period(SAMPLE_RATE)    
   
    f1 = open('data/letters/all_data_'+suffix+'.csv', 'wb')
    w1 = csv.writer(f1)
    row = []
    # Register quaternion callback
    imu.register_callback(imu.CALLBACK_ALL_DATA, cb_all_data)
    imu.register_callback(imu.CALLBACK_ORIENTATION, cb_orientation_data)
    imu.register_callback(imu.CALLBACK_QUATERNION, cb_quaternion_data)   
  
    
    raw_input('Press key to quit recording ' + suffix + ' \n') # Use input() in Python 3
    ipcon.disconnect()
开发者ID:jbleich89,项目名称:the_pen,代码行数:30,代码来源:recordstuff.py

示例2: temperature

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def temperature(connection, table):
    ipcon = IPConnection()
    t = Temperature(TEMPERATURE_UID, ipcon)
    ipcon.connect(HOST, PORT)
    value = t.get_temperature() / 100.0
    insert(connection, table, time.time(), value)
    ipcon.disconnect()
开发者ID:locked-fg,项目名称:Weatherstation-Python,代码行数:9,代码来源:sqlitesaver.py

示例3: humidity

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def humidity(connection, table):
    ipcon = IPConnection()
    h = Humidity(HUMIDITY_UID, ipcon)
    ipcon.connect(HOST, PORT)
    value = h.get_humidity() / 10.0
    insert(connection, table, time.time(), value)
    ipcon.disconnect()
开发者ID:locked-fg,项目名称:Weatherstation-Python,代码行数:9,代码来源:sqlitesaver.py

示例4: barometer

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def barometer(connection, table):
    ipcon = IPConnection()
    b = Barometer(BAROMETER_UID, ipcon)
    ipcon.connect(HOST, PORT)
    value = b.get_air_pressure() / 1000.0  # Get current air pressure (unit is mbar/1000)
    insert(connection, table, time.time(), value)
    ipcon.disconnect()
开发者ID:locked-fg,项目名称:Weatherstation-Python,代码行数:9,代码来源:sqlitesaver.py

示例5: ambient

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def ambient(connection, table):
    ipcon = IPConnection()
    al = AmbientLight(AMBIENT_UID, ipcon)
    ipcon.connect(HOST, PORT)
    value = al.get_illuminance() / 10.0  # Get current illuminance (unit is Lux/10)
    insert(connection, table, time.time(), value)
    ipcon.disconnect()
开发者ID:locked-fg,项目名称:Weatherstation-Python,代码行数:9,代码来源:sqlitesaver.py

示例6: sound_activated

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
class sound_activated(modes.standard.abstractMode):
    _ipcon = None
    _si = None

    def __init__(self):
        '''
        Constructor
        '''
        modes.standard.abstractMode.__init__(self)
        config = ConfigParser.ConfigParser()
        config.read("config.ini")

        if config.has_section("Tinkerforge") and config.has_option('Tinkerforge', 'HOST') and config.has_option('Tinkerforge', 'PORT') and config.has_option('Tinkerforge', 'UID'):
            HOST = config.get('Tinkerforge', 'HOST')
            PORT = config.getint('Tinkerforge', 'PORT')
            UID = config.get('Tinkerforge', 'UID')
        else:
            print "Can't load Tinkerforge Settings from config.ini"

        self._ipcon = IPConnection()  # Create IP connection
        self._si = SoundIntensity(UID, self._ipcon)  # Create device object

        self._ipcon.connect(HOST, PORT)  # Connect to brickd

    def __del__(self):
        self._ipcon.disconnect()

    def myround(self, x, base=5):
        return int(base * round(float(x) / base))

    def start(self):
        high = 0.0
        count = 0
        while True:
            intensity = self._si.get_intensity()
            # reset high_level after a Song
            if count > 100:
                high = intensity
                count = 0
            if intensity > high:
                high = intensity
            else:
                count += 1
            if high > 0:
                level = self.myround((100 / float(high)) * float(intensity))
            else:
                level = 0

            RED = BLUE = GREEN = 0
            if level <= 33:
                BLUE = 100
            elif level <= 66:
                GREEN = 100
            else:
                RED = 100
            self.setRGB([RED, GREEN, BLUE])
            time.sleep(self._DELAY)

    def getName(self):
        return "Sound Activated"
开发者ID:BennySamir,项目名称:Pi-LEDController,代码行数:62,代码来源:tinkerforgebricks.py

示例7: connect

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
        class RedBrickResource:
            def connect(self, uid, host, port):
                self.ipcon = IPConnection()
                self.ipcon.connect(host, port)
                self.rb = BrickRED(uid, self.ipcon)

            def disconnect(self):
                self.ipcon.disconnect()
开发者ID:Loremipsum1988,项目名称:tinkervision,代码行数:10,代码来源:rb_setup.py

示例8: index

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def index():
    ipcon = IPConnection() # Create IP connection
    t = Temperature(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get current temperature (unit is °C/100)
    temperature = t.get_temperature()/100.0

    ipcon.disconnect()
    return PAGE.format(temperature)
开发者ID:Tinkerforge,项目名称:doc,代码行数:14,代码来源:index.py

示例9: lies_temp

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def lies_temp(host, port, uid):
	temp = None
	
	try:
		ipcon = IPConnection()
		b = BrickletTemperature(uid, ipcon)
		ipcon.connect(host, port)
	
		temp = b.get_temperature() / 100.0
		
		ipcon.disconnect()
	except:
		print("Temperaturabfrage fehlgeschlagen")
		
	return temp
开发者ID:GolemMediaGmbH,项目名称:OfficeTemperature,代码行数:17,代码来源:tf_temperature.py

示例10: get_airpressure

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def get_airpressure(id):
    
    cfg = configparser.ConfigParser()
    
    cfg.read(cfg_filename) # open config file to read from
    
    if cfg.has_section("Barometer") == True:
    
        port = cfg.getint('Connection', 'Port') # get port entry from config file
        
        host = cfg.get('Connection', 'Host') # get host entry from config file
        
        uid = cfg.get('Barometer', 'bricklet_uid') # uid port entry from config file
        
        ipcon = IPConnection() # Create IP connection
        
        ipcon.connect(host, port) # Connect to brickd
        
        b = Barometer(uid, ipcon) # Create device object
        
        air_pressure = b.get_air_pressure()/1000.0 # Get current air pressure (unit is mbar/1000)
        
        altitude = b.get_altitude()/100.0
        
        db = sqlite3.connect(local_db) # build connection to local database
        
        c = db.cursor() # create cursor
        
        c.execute(wd_table) # create weatherdata table
        
        c.execute('''INSERT INTO weatherdata(uid , value, keyword, date_id, device_name) VALUES(?,?,?,?,?)''', (uid,air_pressure,'air_pressure',id,'barometer',))
        # insert the uid, device name the id from the date table an die humdity value into the weather table
        
        c.execute('''INSERT INTO weatherdata(uid , value, keyword, date_id, device_name) VALUES(?,?,?,?,?)''', (uid,altitude,'altitude',id,'barometer',))
        
        db.commit() # save creates and inserts permanent  

        ipcon.disconnect()
    
        return({"air_pressure": air_pressure, "altitude": altitude})
开发者ID:wegtam,项目名称:weather-client,代码行数:42,代码来源:barometer.py

示例11: discover

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def discover():
    HOST = "localhost"
    PORT = 4223
    global ipcon
    ipcon = IPConnection()
    ipcon.register_callback(IPConnection.CALLBACK_CONNECTED, cb_connected)
    ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, cb_enumerate)
    try:
        ipcon.connect(HOST, PORT)
        w = threading.Thread(target=wait)
        w.start()
        w.join()
        print("baromenter id: " + str(barometerid))
        print("humidity id: " + str(humidityid))
        print("ambient id: " + str(ambientid))
        print("lcd id: " + str(lcdid))
        
        ipcon.disconnect()
    except socket.error, e:
        global discovery_timed_out
        discovery_timed_out = True
        print("Error: ipconnection failed " + str(e))
开发者ID:jforge,项目名称:tinkerforge-RED-Brick,代码行数:24,代码来源:weatherstation.py

示例12: get_humidity

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def get_humidity(id):
    
    cfg = configparser.ConfigParser()
    
    cfg.read(cfg_filename) # open config file to read from
    
    port = cfg.getint('Connection', 'Port') # get port entry from config file
    
    host = cfg.get('Connection', 'Host') # get host entry from config file
    
    uid = cfg.get('Humidity', 'bricklet_uid') # uid port entry from config file
    
    ipcon = IPConnection() # Create IP connection
    
    ipcon.connect(host, port) # Connect to brickd
    
    h = Humidity(uid, ipcon) # Create device object
    
    rh = h.get_humidity()/10.0 # Get current humidity (unit is %RH/10)
    
    db = sqlite3.connect(local_db) # build connection to local database
    
    c = db.cursor() # create cursor
    
    c.execute(wd_table) # create weatherdata table
    
    c.execute('''INSERT INTO weatherdata(uid , value, keyword, date_id, device_name) VALUES(?,?,?,?,?)''', (uid,rh,'rel. humidity', id,'humidity',))
    # insert the uid, device name the id from the date table an die humdity value into the weather table
    
    db.commit() # save creates and inserts permanent  
    
    print()
    print('Relative Humidity: ' + str(rh) + ' %RH')
    print()
        
    ipcon.disconnect()

    return(rh)
开发者ID:wegtam,项目名称:weather-client,代码行数:40,代码来源:humidity.py

示例13: read_data

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
def read_data():
    try:
        ipcon = IPConnection()
        temp_bricklet = Temperature('qnk', ipcon)
        humidity_bricklet = Humidity('nLC', ipcon)
        barometer_bricklet = Barometer('k5g', ipcon)
        ipcon.connect(cfg['weather']['host'], int(cfg['weather']['port']))
        temp_bricklet.set_i2c_mode(Temperature.I2C_MODE_SLOW)

        temp = temp_bricklet.get_temperature() / 100.0
        if 45 < temp < -30:
            weather_data['temperature'] = None
            logger.warn('Got temperature value of %s Grade which is out of range' % temp)
        else:
            weather_data['temperature'] = temp

        humidity = humidity_bricklet.get_humidity() / 10.0
        if humidity < 5:
            weather_data['humidity'] = None
            logger.warn('Got humidity value of %s RH which is out of range' % humidity)
        else:
            weather_data['humidity'] = humidity

        pressure = barometer_bricklet.get_air_pressure() / 1000.0
        if 1090 < pressure < 920:
            weather_data['pressure'] = None
            logger.warn('Got pressure value of %s mbar which is out of range' % pressure)
        else:
            weather_data['pressure'] = pressure

        ipcon.disconnect()
        return weather_data

    except Exception as e:
        logger.error('Cloud not connect to weather sensors: %s' % str(e))
        return
开发者ID:RaphaelVogel,项目名称:base,代码行数:38,代码来源:weather.py

示例14: __init__

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
class ClimateSensors:

    def __init__(self, host, port):
        self.hum = None
        self.hum_value = 0.0
        self.temp = None
        self.temp_value = 0.0
        self.lcd = None

        self.port = port
        self.host = host
        self.conn = IPConnection()

        self.conn.register_callback(IPConnection.CALLBACK_ENUMERATE, self.cb_enumerate)
        self.conn.register_callback(IPConnection.CALLBACK_CONNECTED, self.cb_connected)

    def update_display(self):
        if self.lcd is not None:
            self.lcd.write_line(1, 2, 'Temp:   {:3.2f} C'.format(self.temp_value))
            self.lcd.write_line(2, 2, 'RelHum: {:3.2f} %'.format(self.hum_value))

    def connect(self):
        if self.conn.get_connection_state() == self.conn.CONNECTION_STATE_DISCONNECTED:
            self.conn.connect(self.host, self.port)
            self.conn.enumerate()

    def disconnect(self):
        if self.conn.get_connection_state() != self.conn.CONNECTION_STATE_DISCONNECTED:
            if self.lcd is not None:
                self.lcd.backlight_off()
                self.lcd.clear_display()
            self.conn.disconnect()

    def cb_connected(self, connected_reason):
        self.conn.enumerate()

    def cb_enumerate(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type):
        if enumeration_type == IPConnection.ENUMERATION_TYPE_DISCONNECTED:
            # print("DISCONNECTED")
            return

        if device_identifier == Temperature.DEVICE_IDENTIFIER:
            self.temp = Temperature(uid, self.conn)
            self.temp.register_callback(self.temp.CALLBACK_TEMPERATURE, self.cb_temperature)
            self.update_temperature(self.temp.get_temperature())
            self.temp.set_temperature_callback_period(UPDATE_PERIOD)

        if device_identifier == Humidity.DEVICE_IDENTIFIER:
            self.hum = Humidity(uid, self.conn)
            self.hum.register_callback(self.hum.CALLBACK_HUMIDITY, self.cb_humidity)
            self.update_humidity(self.hum.get_humidity())
            self.hum.set_humidity_callback_period(UPDATE_PERIOD)

        if device_identifier == LCD20x4.DEVICE_IDENTIFIER:
            self.lcd = LCD20x4(uid, self.conn)
            self.lcd.backlight_on()

    def cb_temperature(self, temperature):
        self.update_temperature(temperature)
        self.update_display()

    def update_temperature(self, raw_temperature):
        self.temp_value = raw_temperature / 100.0

    def cb_humidity(self, humidity):
        self.update_humidity(humidity)
        self.update_display()

    def update_humidity(self, raw_humidity):
        self.hum_value = raw_humidity / 10.0
开发者ID:chaquotay,项目名称:IndoorClimateStation,代码行数:72,代码来源:ClimateSensors.py

示例15: CheckTFTemperature

# 需要导入模块: from tinkerforge.ip_connection import IPConnection [as 别名]
# 或者: from tinkerforge.ip_connection.IPConnection import disconnect [as 别名]
class CheckTFTemperature(object):
    def __init__(self, host = 'localhost', port = 4223):
        self.host = host
        self.port = port
        self.ipcon = IPConnection()
        self.name = 'unknown'
        self.unit = 'unknown'
        self.is_humidity_v2 = False

    def connect(self, type, uid):
        self.ipcon.connect(self.host, self.port)
        self.connected_type = type

        if self.connected_type == TYPE_PTC:
            ptc = PTC(uid, self.ipcon)

            if ptc.get_identity().device_identifier == PTCV2.DEVICE_IDENTIFIER:
                ptc = PTCV2(uid, self.ipcon)

            self.func = ptc.get_temperature
            self.name = 'temperature'
            self.unit = '°C'
        elif self.connected_type == TYPE_TEMPERATURE:
            temperature = Temperature(uid, self.ipcon)

            if temperature.get_identity().device_identifier == TemperatureV2.DEVICE_IDENTIFIER:
                temperature = TemperatureV2(uid, self.ipcon)

            self.func = temperature.get_temperature
            self.name = 'temperature'
            self.unit = '°C'
        elif self.connected_type == TYPE_HUMIDITY:
            humidity = Humidity(uid, self.ipcon)

            if humidity.get_identity().device_identifier == HumidityV2.DEVICE_IDENTIFIER:
                humidity = HumidityV2(uid, self.ipcon)
                self.is_humidity_v2 = True
            else:
                self.is_humidity_v2 = False

            self.func = humidity.get_humidity
            self.name = 'humidity'
            self.unit = '%RH'
        elif self.connected_type == TYPE_MOTION_DETECTOR:
            md = MotionDetector(uid, self.ipcon)

            if md.get_identity().device_identifier == MotionDetectorV2.DEVICE_IDENTIFIER:
                md = MotionDetectorV2(uid, self.ipcon)

            self.func = md.get_motion_detected
        elif self.connected_type == TYPE_AMBIENT_LIGHT:
            al = AmbientLight(uid, self.ipcon)

            if al.get_identity().device_identifier == AmbientLightV2.DEVICE_IDENTIFIER:
                al = AmbientLightV2(uid, self.ipcon)
            elif al.get_identity().device_identifier == AmbientLightV3.DEVICE_IDENTIFIER:
                al = AmbientLightV3(uid, self.ipcon)

            self.func = al.get_illuminance
            self.name = 'Illuminance'
            self.unit = 'lux'
        elif self.connected_type == TYPE_SEGMENT_DISPLAY_4X7:
            display = SegmentDisplay4x7(uid, self.ipcon)
            self.func = display.set_segments

    def disconnect(self):
        self.ipcon.disconnect()

    def error(self, e):
        if e == 'true':
            self.func((0, 80, 80, 121), 8, False)
        else:
            self.func((0, 0, 0, 0), 8, False)

    def read_sensor(self):
        if self.connected_type == TYPE_HUMIDITY:
            if not self.self.is_humidity_v2:
                return self.func()/10.0
            else:
                return self.func()/100.0
        elif self.connected_type == TYPE_MOTION_DETECTOR:
            return self.func()
        else: # Temperature, PTC, Ambient Light.
            return self.func()/100.0

    def read(self, warning, critical, mode = 'none', warning2 = 0, critical2 = 0):
        val = self.read_sensor()

        if self.connected_type == TYPE_MOTION_DETECTOR:
            if val == 1:
                print 'motion detected'
                return MOTION_DETECTED
            else:
                print 'no motion detected'
                return NO_MOTION_DETECTED
        else:
            if mode == 'none':
                print "%s %s %s" % (self.name, val, self.unit)
            else:
                if mode == 'low':
#.........这里部分代码省略.........
开发者ID:Tinkerforge,项目名称:server-room-monitoring,代码行数:103,代码来源:check_tf_temp_ext.py


注:本文中的tinkerforge.ip_connection.IPConnection.disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。