本文整理汇总了Python中w1thermsensor.W1ThermSensor类的典型用法代码示例。如果您正苦于以下问题:Python W1ThermSensor类的具体用法?Python W1ThermSensor怎么用?Python W1ThermSensor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了W1ThermSensor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: read_temperatures
def read_temperatures(units=W1ThermSensor.DEGREES_F):
'''Read temperatures from attached thermometers.
Parameters
units: int default=W1ThermSensor.DEGREES_F
Temerature units (e.g., Fahrenheit, Celcius, Kelvin) as
Returns
array of dicts, each one containing sensor ID and temperature reading
`[
{
'sensor_id': '80000002d2e0',
'sensor_type': 'DS18B20',
'temperature': 63.16160000000001
},
{
'sensor_id': '80000002d4c1',
'sensor_type': 'DS18B20',
'temperature': 20.8740000000001
}
]`
'''
return [dict(
sensor_id=sensor.id,
sensor_type=sensor.type_name,
temperature=sensor.get_temperature(units)
) for sensor in W1ThermSensor.get_available_sensors()]
开发者ID:jtyberg,项目名称:pi-therm-sensor,代码行数:27,代码来源:therm.py
示例2: get_temp
def get_temp():
global tempeture_1
while True:
yield from asyncio.sleep(1.5)
#tempeture_1=SpiRead()
for sensor in W1ThermSensor.get_available_sensors():
tempeture_1=sensor.get_temperature()
开发者ID:kkdds,项目名称:lmf_bk,代码行数:7,代码来源:lmf7.py
示例3: __init__
def __init__(self,edit):
wx.Dialog.__init__(self, None, title=_('Add DS18B20 sensor'), size=(330,290))
panel = wx.Panel(self)
wx.StaticText(panel, label=_('name'), pos=(10, 10))
self.name = wx.TextCtrl(panel, size=(310, 30), pos=(10, 35))
wx.StaticText(panel, label=_('short name'), pos=(10, 70))
self.short = wx.TextCtrl(panel, size=(100, 30), pos=(10, 95))
list_units=['Celsius','Fahrenheit','Kelvin']
wx.StaticText(panel, label=_('unit'), pos=(120, 70))
self.unit_select= wx.ComboBox(panel, choices=list_units, style=wx.CB_READONLY, size=(200, 32), pos=(120, 95))
list_id=[]
for sensor in W1ThermSensor.get_available_sensors():
list_id.append(sensor.id)
wx.StaticText(panel, label=_('sensor ID'), pos=(10, 130))
self.id_select= wx.ComboBox(panel, choices=list_id, style=wx.CB_READONLY, size=(310, 32), pos=(10, 155))
if edit != 0:
self.name.SetValue(edit[1])
self.short.SetValue(edit[2])
if edit[3]=='C': unit_selection='Celsius'
if edit[3]=='F': unit_selection='Fahrenheit'
if edit[3]=='K': unit_selection='Kelvin'
self.unit_select.SetValue(unit_selection)
self.id_select.SetValue(edit[4])
cancelBtn = wx.Button(panel, wx.ID_CANCEL, pos=(70, 205))
okBtn = wx.Button(panel, wx.ID_OK, pos=(180, 205))
开发者ID:Sailor99,项目名称:openplotter,代码行数:31,代码来源:add_DS18B20.py
示例4: main
def main(post=True):
print 'running main...'
responses = {}
try:
print 'Getting GPIO ready'
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(LIGHT, GPIO.OUT)
_pin = RELAY
# Setup sensors
for sensor in W1ThermSensor.get_available_sensors():
print 'Detected sensor ', sensor.id
_sid = '28-' + sensor.id
if _sid in ID_TO_PIN:
_pin = ID_TO_PIN[_sid]
responses[_sid] = {'status': 'temper'}
GPIO.setup(_pin, GPIO.OUT)
print 'Success with one sensor'
print 'Success with all sensors'
except Exception, e:
print 'EXCEPTION SETTING UP MAIN GPIO'
print e
GPIO.cleanup()
开发者ID:jmasonherr,项目名称:temper,代码行数:25,代码来源:keep_steady.py
示例5: run
def run(self):
while 1:
try:
if SIMULATION_MODE == 1:
for sensor in self.sensors:
timestamp = int(time())
lock.acquire()
with open(self.csv_path, "a") as output_file:
writer = csv.writer(output_file)
row = sensor.id, sensor.name, sensor.get_temperature(), timestamp
writer.writerow(row)
lock.release()
else:
for sensor in W1ThermSensor.get_available_sensors():
# TODO: set a sensor name
timestamp = int(time())
lock.acquire()
with open(self.csv_path, "a") as output_file:
writer = csv.writer(output_file)
row = sensor.id, 'T', sensor.get_temperature(), timestamp
writer.writerow(row)
lock.release()
sleep(self.sleep_time)
finally:
pass
开发者ID:UMONS-GFA,项目名称:ardas,代码行数:26,代码来源:save_sensor_data.py
示例6: test_get_available_sensors
def test_get_available_sensors():
_remove_w1_therm_sensors()
_create_w1_therm_sensor(W1ThermSensor.THERM_SENSOR_DS18B20)
sensors = W1ThermSensor.get_available_sensors()
sensors.should.have.length_of(1)
sensors[0].type.should.be.equal(W1ThermSensor.THERM_SENSOR_DS18B20)
_create_w1_therm_sensor(W1ThermSensor.THERM_SENSOR_DS1822)
_create_w1_therm_sensor(W1ThermSensor.THERM_SENSOR_DS18S20)
sensors = W1ThermSensor.get_available_sensors()
sensors.should.have.length_of(3)
W1ThermSensor.THERM_SENSOR_DS1822.should.be.within(s.type for s in sensors)
W1ThermSensor.THERM_SENSOR_DS18S20.should.be.within(s.type for s in sensors)
W1ThermSensor.THERM_SENSOR_DS18B20.should.be.within(s.type for s in sensors)
开发者ID:claws,项目名称:w1thermsensor,代码行数:17,代码来源:test_core.py
示例7: test_get_available_ds18s20_sensors
def test_get_available_ds18s20_sensors():
_remove_w1_therm_sensors()
# create 3 DS18S20 sensors
_create_w1_therm_sensor(W1ThermSensor.THERM_SENSOR_DS18S20)
_create_w1_therm_sensor(W1ThermSensor.THERM_SENSOR_DS18S20)
_create_w1_therm_sensor(W1ThermSensor.THERM_SENSOR_DS18S20)
sensors = W1ThermSensor.get_available_sensors([W1ThermSensor.THERM_SENSOR_DS18S20])
sensors.should.have.length_of(3)
# create 2 DS18B20 sensors
_create_w1_therm_sensor(W1ThermSensor.THERM_SENSOR_DS18B20)
_create_w1_therm_sensor(W1ThermSensor.THERM_SENSOR_DS18B20)
sensors = W1ThermSensor.get_available_sensors([W1ThermSensor.THERM_SENSOR_DS18S20])
sensors.should.have.length_of(3)
开发者ID:claws,项目名称:w1thermsensor,代码行数:17,代码来源:test_core.py
示例8: handle
def handle(self, *args, **options):
for sensor in W1ThermSensor.get_available_sensors():
if Thermometer.objects.filter(sensor_id=sensor.id).__len__() == 0:
thermometer = Thermometer(sensor_id=sensor.id)
thermometer.save()
if thermometer.id is not None:
self.stdout.write("Sensor o ID: %s dodany do bazy!" % (sensor.id))
else:
self.stdout.write("Sensor o ID: %s juz istnieje w bazie!" % (sensor.id))
开发者ID:piotrchmiel,项目名称:Chmura_Pomiarowa,代码行数:9,代码来源:addsensors.py
示例9: logged_in
def logged_in(*args, **kwargs):
print 'Logged in: %s' % datetime.datetime.now().isoformat()
print args
print kwargs
print 'Creating machines...'
for sensor in W1ThermSensor.get_available_sensors():
client.call('getOrCreateMachine', sensor.id, callback=sensor_create_callback)
for fakesensor in ['refiner1id', 'refiner12id']:
client.call('getOrCreateMachine', fakesensor, callback=sensor_create_callback)
开发者ID:jmasonherr,项目名称:temper,代码行数:9,代码来源:oldestpyversion.py
示例10: flash_error
def flash_error():
# Shutoff all
for sensor in W1ThermSensor.get_available_sensors():
pin = RELAY
# Accomodate multiples
if sensor.id in ID_TO_PIN:
_sid = '28-' + sensor.id
pin = ID_TO_PIN[_sid]
GPIO.output(pin, False)
开发者ID:jmasonherr,项目名称:temper,代码行数:9,代码来源:keep_steady.py
示例11: monitorTemps
def monitorTemps():
global sensor_current
clearSensorAVG()
lastminute=int(time.strftime("%M"))
r = 0
count=0.0
while True:
r += 1
count += 1.0
# Read the DS18B20s
for sensor in W1ThermSensor.get_available_sensors():
temp=sensor.get_temperature(W1ThermSensor.DEGREES_F)
# If the sensor is reading super high then something is wrong..try to read again
while ( temp > 120 ):
print("Sensor %s has high temp %.2f" % (sensor_name[sensor.id], temp))
time.sleep(0.2)
temp=sensor.get_temperature(W1ThermSensor.DEGREES_F)
if (DEBUG == 1):
print("Sensor %s has temperature %.2f" % (sensor_name[sensor.id], temp))
sensor_avg[sensor_name[sensor.id]]+= temp
time.sleep(0.2)
if (DEBUG == 1):
print("-")
minute=int(time.strftime("%M"))
if (minute != lastminute):
# Minute just changed. Write a line to the CSV file
f.write("{},{}".format(time.strftime("%Y/%m/%d %H:%M:%S"),r))
for sensorID,sensorName in sensor_name.iteritems():
f.write(",{:3.2f}".format(sensor_avg[sensorName]/count))
sensor_current[sensorName]=sensor_avg[sensorName]/count
print "Setting sensor_current["+sensorName+"]="+str(sensor_current[sensorName])
f.write("\n")
f.flush()
clearSensorAVG()
count=0
lastminute=minute
time.sleep(3) # Overall INTERVAL second polling.
开发者ID:goldpizza44,项目名称:automation,代码行数:55,代码来源:alltemp.py
示例12: get_sensor_data
def get_sensor_data():
try:
for sensor in W1ThermSensor.get_available_sensors():
#now = '{:%Y-%m-%d %H:%M}'.format(datetime.datetime.now())
room = clean_get(sensor.id, 'room')
sensor_name = clean_get(sensor.id, 'name')
result = room + " " + sensor_name + " " + str(sensor.type_name) + " " + sensor.id + " " + str(sensor.get_temperature(W1ThermSensor.DEGREES_F))
logging.info(result)
except Exception, e:
logging.error('Failed to get sensor information: '+ str(e))
开发者ID:jasonehines,项目名称:logtemp,代码行数:11,代码来源:logtemp.py
示例13: main
def main():
log_path = path.join(PIDAS_DIR, 'logs')
file_path = path.join(PIDAS_DIR, DATA_FILE)
if not path.exists(log_path):
makedirs(log_path)
logging_level = logging.DEBUG
logging.Formatter.converter = gmtime
log_format = '%(asctime)-15s %(levelname)s:%(message)s'
logging.basicConfig(format=log_format, datefmt='%Y/%m/%d %H:%M:%S UTC', level=logging_level,
handlers=[logging.FileHandler(path.join(log_path, 'save_sensor_data.log')),
logging.StreamHandler()])
logging.info('_____ Started _____')
logging.info('saving in' + file_path)
if not path.exists(file_path):
with open(file_path, "w") as output_file:
writer = csv.writer(output_file)
writer.writerow(CSV_HEADER)
client = InfluxDBClient(DATABASE['HOST'], DATABASE['PORT'], DATABASE['USER'], DATABASE['PASSWORD'],
DATABASE['NAME'])
sensors = []
if SIMULATION_MODE == 1:
try:
last_timestamp = client.query('select "timestamp" from temperatures order by desc limit 1;')
if not last_timestamp:
logging.info("Serie is empty, creating new sensors…")
sensors = generate_temp_sensor(NB_SENSOR)
logging.info("Sensors generated")
else:
try:
logging.info("Getting sensors from database…")
result_set = client.query('select distinct(sensorID) as sensorID from temperatures ')
results = list(result_set.get_points(measurement='temperatures'))
for result in results:
s = FakeTempSensor()
s.id = result['sensorID']
sensors.append(s)
except requests.exceptions.ConnectionError:
logging.error("Database connection lost !")
except requests.exceptions.ConnectionError:
logging.error("Database connection lost !")
except exceptions.InfluxDBClientError as e:
logging.error("{}".format(e.content))
else:
sensors = W1ThermSensor.get_available_sensors()
thread_local_save = ThreadLocalSave(file_path=file_path, sensors=sensors)
thread_remote_save = ThreadRemoteSave(client, file_path=file_path)
thread_local_save.start()
thread_remote_save.start()
# wait until threads terminates
thread_local_save.join()
thread_remote_save.join()
开发者ID:UMONS-GFA,项目名称:ardas,代码行数:52,代码来源:save_sensor_data.py
示例14: temp
def temp(downlink, tempLED):
try:
data_raw = []
data = []
for sensor in W1ThermSensor.get_available_sensors():
data_raw.append(sensor.get_temperature())
for i in range(len(data_raw)):
data.append(data_raw[i])
#data.append(temp_cal[i] + data_raw[i])
if (not tempLED.is_set()) and tempCheck(data):
# If the flag isn't set, and things are on fire.
tempLED.set()
downlink.put(["SE", "T%i" % (len(data)), cs_str(data)])
except:
print("Temperature reading failed")
开发者ID:dbeattyspace,项目名称:HELIOSV,代码行数:15,代码来源:sensors.py
示例15: t_temp
def t_temp():
while True:
for sensor in W1ThermSensor.get_available_sensors():
lock.acquire()
temps[sensor.id] = sensor.get_temperature(W1ThermSensor.DEGREES_F)
temptimes[sensor.id] = time.time()
print 'hwr>'+sensor.id+':'+str(temps[sensor.id])
lock.release()
lock.acquire()
todelete = []
expire = time.time() - 60 * 10
for t in temptimes:
if temptimes[t] < expire:
todelete.append(t)
for t in todelete:
temptimes.pop(t,None)
temps.pop(t,None)
print "del>"+t
lock.release()
time.sleep(120)
开发者ID:42six,项目名称:PiClock-test,代码行数:22,代码来源:TempServer.py
示例16: get_w1_devices
def get_w1_devices(self):
log.debug('Scanning for 1W devices.')
for sensor in W1ThermSensor.get_available_sensors():
self._w1_devices[sensor.id] = {'id': sensor.id, 'type': '1-Wire device'}
return self._w1_devices
开发者ID:yuregir,项目名称:AGR,代码行数:5,代码来源:sensormanager.py
示例17:
#!/usr/bin/python
import sys
import time
from lib import BMP085
from lib import TSL2561
from w1thermsensor import W1ThermSensor
import Adafruit_DHT
bmp = BMP085.BMP085(0x77, 3)
lux = TSL2561.TSL2561()
dht = Adafruit_DHT.DHT22
temps = {}
for sensor in W1ThermSensor.get_available_sensors():
temps[sensor.id] = sensor.get_temperature()
bartemp = bmp.readTemperature()
pressure = bmp.readPressure() / 100.0
light = lux.getAnyLux()
humidity, humtemp = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 23)
for id in temps.keys():
print "Temperature on %s: %.3f C" % (id, temps[id])
print "Barometer Temperature: %.1f C" % bartemp
print "Hygrometer Temperature: %.1f C" % humtemp
print "Pressure: %.2f hPa" % pressure
print "Humidity: %.2f %%" % humidity
print "Lightness: %.2f Lux" % light
开发者ID:Himura2la,项目名称:RPi_Weather_Station,代码行数:31,代码来源:get.py
示例18: open
logfile= r"logfile-" + period + ".txt"
if ( os.path.exists(logfile) ):
new_file[period] = False
else:
new_file[period] = True
output[period] = open(logfile,"a")
#logfile = file_timestamp + "-records_log.txt"
logfile = "records_log.txt"
if ( os.path.exists(logfile) ):
new_file["records"] = False
else:
new_file["records"] = True
output["records"] = open(logfile,"a")
all_sensors = W1ThermSensor.get_available_sensors()
record_count = {}
last_reading = {}
for sensor in all_sensors:
match_sensor_to_loc(sensor)
init_sensor_stats(sensor)
for period in stats_periods.keys():
record_count[period] = 0
last_reading[period] = 0
if (new_file[period]):
output[period].write("%20s |" % " ")
for sensor in all_sensors:
output[period].write("%23s |" % sensor.location)
开发者ID:pie-man,项目名称:Small_Python_Scripts,代码行数:31,代码来源:thermometer.py
示例19:
detected_imu=imu.IMUName()
if imu.getCompassCalibrationValid() and imu.getCompassCalibrationEllipsoidValid() and imu.getAccelCalibrationValid():
calibrated=1
SETTINGS_FILE2 = "RTIMULib2"
s2 = RTIMU.Settings(SETTINGS_FILE2)
pressure = RTIMU.RTPressure(s2)
if pressure.pressureName()!='none': detected_pressure=pressure.pressureName()
SETTINGS_FILE3 = "RTIMULib3"
s3 = RTIMU.Settings(SETTINGS_FILE3)
humidity = RTIMU.RTHumidity(s3)
if humidity.humidityName()!='none': detected_humidity=humidity.humidityName()
try:
DS18B20=W1ThermSensor.get_available_sensors()
except: pass
if detected_imu: print detected_imu
else: print 'none'
if calibrated: print calibrated
else: print '0'
if detected_pressure: print detected_pressure
else: print 'none'
if detected_humidity: print detected_humidity
else: print 'none'
开发者ID:OskarRaftegard,项目名称:openplotter,代码行数:30,代码来源:check_sensors.py
示例20: test_get_available_sensors_no_sensors
def test_get_available_sensors_no_sensors():
_remove_w1_therm_sensors()
sensors = W1ThermSensor.get_available_sensors()
sensors.should.be.empty
开发者ID:claws,项目名称:w1thermsensor,代码行数:5,代码来源:test_core.py
注:本文中的w1thermsensor.W1ThermSensor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论