def read():
    global sht21, lock_handle
    try:
        if lock_handle:
            flock(lock_handle, LOCK_EX)
        temperature = sht21.read_temperature()
        humidity = sht21.read_humidity()
        if lock_handle:
            flock(lock_handle, LOCK_UN)
    except IOError as e:
        collectd.error(('sht21 plugin: Could not read sensor data: %s' % e))
        return
    try:
        dewpoint = td(temperature, humidity)
    except ValueError as e:
        collectd.error(('sht21 plugin: Could not calculate dew point: %s' % e))
        dewpoint = 0
    absolute_humidity = ah(temperature, humidity)
    v_tmp = collectd.Values(plugin='sht21', type='temperature', type_instance='current')
    v_tmp.dispatch(values=[temperature])
    v_hum = collectd.Values(plugin='sht21', type='humidity', type_instance='relative_humidity')
    v_hum.dispatch(values=[humidity])
    v_abs = collectd.Values(plugin='sht21', type='gauge', type_instance='absolute_humidity')
    v_abs.dispatch(values=[absolute_humidity])
    v_dew = collectd.Values(plugin='sht21', type='temperature', type_instance='dewpoint')
    v_dew.dispatch(values=[dewpoint])
def read():
    global sht21, lock_handle
    try:
        if lock_handle:
            flock(lock_handle, LOCK_EX)
        temperature = sht21.read_temperature()
        humidity = sht21.read_humidity()
        if lock_handle:
            flock(lock_handle, LOCK_UN)
    except IOError as e:
        collectd.error(('sht21 plugin: Could not read sensor data: %s' % e))
        return
    try:
        dewpoint = td(temperature, humidity)
    except ValueError as e:
        collectd.error(('sht21 plugin: Could not calculate dew point: %s' % e))
        dewpoint = 0
    absolute_humidity = ah(temperature, humidity)
    v_tmp = collectd.Values(plugin='sht21', type='temperature', type_instance='current')
    v_tmp.dispatch(values=[temperature])
    v_hum = collectd.Values(plugin='sht21', type='humidity', type_instance='relative_humidity')
    v_hum.dispatch(values=[humidity])
    v_abs = collectd.Values(plugin='sht21', type='gauge', type_instance='absolute_humidity')
    v_abs.dispatch(values=[absolute_humidity])
    v_dew = collectd.Values(plugin='sht21', type='temperature', type_instance='dewpoint')
    v_dew.dispatch(values=[dewpoint])