def __init__(self): self.version = sv.Version('0.0.1') self._logger = lager.Lager(os.path.join(config.DB_ROOT, 'events.json')) #kegs and flow self._flowMeters = [] self._flowMeters.append(sf800.SF800(config.FLOW_1_PIN)) self._flowMeters.append(sf800.SF800(config.FLOW_2_PIN)) self._kegManager = keg.KegManager(flow_meters=self._flowMeters, logger=self._logger) #thermostat self.tempSensor = w1thermsensor.W1ThermSensor() self.compressorRelay = relay.Relay(config.RELAY_PIN) self._thermostat = thermostat.Thermostat( self.tempSensor.get_temperature, self.compressorRelay, on_adds_heat=0, logger=self._logger) self._thermostat.start() #pressure self._adcManager = ads1x15.ADS1x15Manager([ ads1x15.Channel(id=0, gain=4096, sps=8), ads1x15.Channel(id=1, gain=4096, sps=8) ]) self._adcManager.start() self._kegPressure = ms.M7139_200PG(lambda: self._adcManager.read(0)) self._tankPressure = ms.M7139_03KPN(lambda: self._adcManager.read(1)) self._carbonationVolumes = lambda: carbonation.volumes( self.tempSensor.get_temperature(), self._kegPressure.read()) RPIO.wait_for_interrupts(threaded=True)
def main(protocol): try: print("\nPython %s\n" % sys.version) print("IoT Hub Client for Python") hub_manager = HubManager(protocol) sensor = w1thermsensor.W1ThermSensor() print("Starting the IoT Hub Python sample using protocol %s..." % hub_manager.client_protocol) print( "The sample is now waiting for messages and will indefinitely. Press Ctrl-C to exit. " ) while True: temp = sensor.get_temperature() print("Got temperature: %s" % temp) hub_manager.SendTemperatureData(str(temp)) time.sleep(10) except IoTHubError as iothub_error: print("Unexpected error %s from IoTHub" % iothub_error) return except KeyboardInterrupt: print("IoTHubModuleClient sample stopped")
def data_update(data, file_path): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) sensor = w1thermsensor.W1ThermSensor() temp = sensor.get_temperature() GPIO.setup(21, GPIO.OUT) GPIO.setup(26, GPIO.OUT) data["temp"] = temp alarms = data["alarms"] fire = data["fire_sensor"] if alarms == 1: GPIO.output(21, GPIO.HIGH) elif alarms == 0: GPIO.output(21, GPIO.LOW) if fire == 1: GPIO.output(26, GPIO.HIGH) elif fire == 0: GPIO.output(26, GPIO.LOW) with open(file_path, 'r+') as fh: fh.seek(0) json.dump(data, fh, indent=4) fh.truncate() return data
def __init__(self, *args, sensor_type, sensor_id, **kwargs): super().__init__(*args, **kwargs) if sensor_type == "None": sensor_type = None if sensor_id == "None": sensor_id = None self.w1ThermSensor = w1thermsensor.W1ThermSensor(sensor_type = sensor_type, sensor_id = sensor_id)
def initialise_w1thermsensor(): os.environ['W1THERMSENSOR_NO_KERNEL_MODULE'] = '1' from w1thermsensor.errors import KernelModuleLoadError del os.environ['W1THERMSENSOR_NO_KERNEL_MODULE'] try: import w1thermsensor w1thermsensor.core.load_kernel_modules() return w1thermsensor.W1ThermSensor() except KernelModuleLoadError: log.error('Module w1thermsensor could not load required kernel ' 'modules. Run as root or load them yourself.') return None
def _read(self, **kwargs): logger.debug("Reading DS18B20 sensor") try: sensor = w1thermsensor.W1ThermSensor() temp = sensor.get_temperature() except RuntimeError as e: raise SensorNotAvailableException(e) temp = round(temp, 3) logger.info("Read {}°C".format(temp)) return [temp]
def main(): init_soc() mcp = init_ads() sensor = w1thermsensor.W1ThermSensor() print("Everything is properly configured!") while True: time.sleep(2) UV = 0 INTENSITY = 2 values = [0] * 8 for i in range(8): values[i] = mcp.read_adc(i) insert_data(gauge.readVoltage(), gauge.readPercentage(), sensor.get_temperature(), values[INTENSITY], values[UV])
def __init__(self, *args, configuration): super().__init__(*args) self.measurement_interval = configuration["intervals"][ "measurementInterval"] self.aggregate_interval = configuration["intervals"][ "aggregateInterval"] sensor_type = (configuration["sensorType"] if "sensorType" in configuration else None) sensor_id = configuration[ "sensorId"] if "sensorId" in configuration else None self.w1ThermSensor = w1thermsensor.W1ThermSensor( sensor_type=sensor_type, sensor_id=sensor_id)
def get(self, request): try: sensor = w1thermsensor.W1ThermSensor() temperature = sensor.get_temperature() date = datetime.datetime.now() GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(21, GPIO.OUT) GPIO.output(21, GPIO.HIGH) time.sleep(1) GPIO.output(21, GPIO.LOW) except: print("problem") tempo = Temperature.objects.create(temperature=temperature, date=date) return render(request, self.template_name, {'temp': tempo})
def get_soil_temperature(): ''' Provides a helper to get the soil temperature. ''' sensor = W1.W1ThermSensor() return sensor.get_temperature()
def ds18b20(): sensor = w1thermsensor.W1ThermSensor() temp = sensor.get_temperature() print(f'DS18B200 Temp : {temp}')
from sensors import * import time import w1thermsensor as ts import picamera as cam from settings import Settings from sensor_functions import * from time_agent import TimeAgent settings = Settings() scans_active = True PIRsensor = Sensor(io, settings.PIRsensor_line_in, settings.PIRsensor_line_out, settings.gpio_mode, 'low') USsensor = Sensor(io, settings.USsensor_line_in, settings.USsensor_line_out, settings.gpio_mode, 'low') sensors = (PIRsensor, USsensor) setup_sensors(sensors) temp_sensor = TemperatureSensor(ts.W1ThermSensor()) timeagent = TimeAgent(settings) while scans_active: try: #body sensor scan if PIRsensor.read_line_in(): timeagent.increment_alert_no() timeagent.start_series() PIRsensor.set_line_out(settings.PIRsensor_line_out, True) timeagent.check_range() if timeagent.in_range: make_photo(settings) else:
#!/usr/bin/env python import json import urllib2 import sqlite3 import time import w1thermsensor as therm sensor = therm.W1ThermSensor() while True: try: # Get Mountain View temperature from Wunderground f=urllib2.urlopen('http://api.wunderground.com/api/e260c734250b742d/conditions/q/CA/Mountain_View.json') json_string = f.read() parsed_json = json.loads(json_string) location = 'Mountain View' try: temp_f_WeatherChannel = parsed_json['current_observation']['temp_f'] except: print parsed_json['response'] continue print 'Current temperature in {} is {}'.format(location,temp_f_WeatherChannel) f.close() # Get temperature from sensor temp_f_Sensor = sensor.get_temperature(therm.W1ThermSensor.DEGREES_F) print 'Sensor temperature is {}'.format(temp_f_Sensor) conn = sqlite3.connect('test.db')
def __init__(self): super().__init__() self.thermosensor = w1thermsensor.W1ThermSensor()
def _get_temperature(self, addr, type): if type.lower() == 'ds18b20': sensor_type = w1thermsensor.W1ThermSensor.THERM_SENSOR_DS18B20 sensor = w1thermsensor.W1ThermSensor(sensor_type, addr) return sensor.get_temperature()
LODOWKA = 3 GPIO.setmode(GPIO.BCM) # GPIO Numbers instead of board numbers GPIO.setup(LODOWKA, GPIO.OUT) # GPIO Assign mode def log(a, on): now = datetime.now() t = now.strftime("%d/%m/%Y %H:%M:%S") file = open('./metrics.json', 'w+') metrics = dict(time=str(t), temperature=a, on=on) json.dump(metrics, file) print(str(t) + ": " + "temperature=" + str(temp) + " on=" + str(on)) sys.stdout.flush() while True: sensor = w1thermsensor.W1ThermSensor() temp = sensor.get_temperature() if temp < 19: GPIO.output(LODOWKA, GPIO.LOW) if temp > 21: GPIO.output(LODOWKA, GPIO.HIGH) on = GPIO.input(LODOWKA) log(temp, on) time.sleep(5)
# Based on example.py in dht11 import RPi.GPIO as GPIO import dht11 import w1thermsensor import time import datetime import paho.mqtt.client as mqtt # initialize GPIO GPIO.setwarnings(True) GPIO.setmode(GPIO.BCM) # read data using pin 17 indoortemp = dht11.DHT11(pin=17) outdoortemp = w1thermsensor.W1ThermSensor() auth = {'username': '******', 'password': '******'} do_configuration = True def on_connect(client, userdata, flags, rc): # (Re)Subscribe to topic on connection. client.subscribe("homeassistant/sensor/restart/state") def on_message(client, userdata, msg): if msg.topic == "homeassistant/sensor/restart/state": do_configuration = True def on_disconnect(client, userdata, rc):