def init_mashing(batch): # (Re)set defaults for batch set_batch_defaults(batch) set_variable('active_mashingprocess_batch_id', str(batch.id)) # Initialize Arduino with Nanpy if not settings.ARDUINO_SIMULATION: sensor = DallasTemperature(ARDUINO_TEMPERATURE_PIN) addr = sensor.getAddress(ARDUINO_TEMPERATURE_PIN) Arduino.pinMode(ARDUINO_HEAT_PIN, Arduino.OUTPUT) Arduino.pinMode(ARDUINO_COOL_PIN, Arduino.OUTPUT) Arduino.pinMode(ARDUINO_STATUS_PIN, Arduino.OUTPUT) Arduino.digitalWrite(ARDUINO_HEAT_PIN, Arduino.LOW) Arduino.digitalWrite(ARDUINO_COOL_PIN, Arduino.LOW) Arduino.digitalWrite(ARDUINO_STATUS_PIN, Arduino.HIGH) else: # Set initial dummy temperature batch.temperature = 20 # Testing purpose only batch.save() batch = Batch.objects.get(id=batch.id) # Run Mashing proces while get_variable('active_mashingprocess_batch_id', 'None') == str(batch.id): # Measure data measured_data = {} if settings.ARDUINO_SIMULATION: measured_data['temp'] = get_dummy_temperature(batch) else: sensor.requestTemperatures() measured_data['temp'] = sensor.getTempC(addr) # Define actions depending on measured data batch = process_measured_data(batch.id, measured_data) # Send updates to arduino if not settings.ARDUINO_SIMULATION: send_updates_to_arduino(batch) # Send to logging department handle_logging(batch) # Delay sleep(DELAY_BETWEEN_MEASUREMENTS) Arduino.digitalWrite(ARDUINO_STATUS_PIN, Arduino.LOW) Arduino.digitalWrite(ARDUINO_COOL_PIN, Arduino.LOW) Arduino.digitalWrite(ARDUINO_HEAT_PIN, Arduino.LOW) return 'Mashing proces ended'
def init_sensor(self): self.sensors = DallasTemperature(self.pin, connection=self.connection) self.sensor_bus = self.sensors.getDeviceCount() # read data using pin specified pin print("There are", self.sensor_bus, "devices connected on pin ", self.sensors.pin) self.addresses = [] for i in range(self.sensor_bus): self.addresses.append(self.sensors.getAddress(i)) print("There addresses", self.addresses) #I guess this is something with bit rates? TODO: Look this up self.sensors.setResolution(10)
class TemperatureSensor(Service): def on_init(self): self.communicator.listen() print 'init' print self.params['tp1'] self.sensors = DallasTemperature(self.params['tp1']) def on_shutdown(self): pass def on_process(self): self.sensors.requestTemperatures(0) addr = self.sensors.getAddress(0) temp = self.sensors.getTempC(addr) print temp self.communicator.send(str(temp)) time.sleep(5)
class TemperatureSensor(Sensor): def __init__(self, pin, name='TemperatureHumiditySensor', key=None, connection=default_connection, redis_conn=None): super().__init__(pin, name=name, key=key, connection=connection, redis_conn=redis_conn) return def init_sensor(self): self.sensors = DallasTemperature(self.pin, connection=self.connection) self.sensor_bus = self.sensors.getDeviceCount() # read data using pin specified pin Logger.log(LOG_LEVEL["debug"], "There are", self.sensor_bus, "devices connected on pin ", self.sensors.pin) self.addresses = [] for i in range(self.sensor_bus): self.addresses.append(self.sensors.getAddress(i)) Logger.log(LOG_LEVEL["debug"], "Their addresses", self.addresses) #I guess this is something with bit rates? TODO: Look this up self.sensors.setResolution(10) #sensor = id of sensor you want in addresses[] def read(self): #temp = self.sensors.getTempF(sensor) #self.r.set('temp_'+str(sensor), temp) #return temp return self.readAll() def readAll(self): self.sensors.requestTemperatures() temps = {} for i in range(self.sensor_bus): temp = self.sensors.getTempC(i) temps['temp_' + str(i)] = temp #self.r.set(self.key+'_'+str(i), temp) #print("Device %d (%s) " % (i, self.addresses[i])) #print("Let's convert it in Fahrenheit degrees: %0.2f" % DallasTemperature.toFahrenheit(temp)) self.r.set(self.key, temps) return temps
#!/usr/bin/env python # Author: Andrea Stagi <*****@*****.**> # Description: just a test for DallasTemperature # Dependencies: None from nanpy import DallasTemperature sensors = DallasTemperature(5) while True: sensors.requestTemperatures() temp = sensors.getTempCByIndex(0) print "The temperature, in Celsius degrees is %0.2f" % temp print "Let's convert it in Fahrenheit degrees: %0.2f" % DallasTemperature.toFahrenheit( temp)
from nanpy import DallasTemperature, SerialManager device = '/dev/cu.usbmodem1411' connection = SerialManager(device=device) connection.open() sensors = DallasTemperature(connection=connection, pin=2) n_sensors = sensors.getDeviceCount() print("There are %d devices connected on pin %d" % (n_sensors, sensors.pin)) addresses = [] for i in range(n_sensors): addresses.append(sensors.getAddress(i)) sensors.setResolution(12) while True: sensors.requestTemperatures() for i in range(n_sensors): temp = sensors.getTempC(i) print("Device %d (%s) temperature, in Celsius degrees is %0.2f" % (i, addresses[i], temp)) print("Let's convert it in Fahrenheit degrees: %0.2f" % DallasTemperature.toFahrenheit(temp)) print("\n")
#!/usr/bin/env python # Author: Andrea Stagi <*****@*****.**> # Description: just a test for DallasTemperature # Dependencies: None from nanpy import DallasTemperature sensors = DallasTemperature(5) while True: sensors.requestTemperatures() temp = sensors.getTempCByIndex(0) print "The temperature, in Celsius degrees is %0.2f" % temp print "Let's convert it in Fahrenheit degrees: %0.2f" % DallasTemperature.toFahrenheit(temp)
#!/usr/bin/env python # Author: Andrea Stagi <*****@*****.**> # Description: just a test for DallasTemperature # Dependencies: None from nanpy import DallasTemperature sensors = DallasTemperature(5) while True: print("There are %d devices connected on pin %d" % (sensors.getDeviceCount(), sensors.pin)) sensors.requestTemperatures(0) addr = sensors.getAddress(0) temp = sensors.getTempC(addr) print("The temperature, in Celsius degrees is %0.2f" % temp) print("Let's convert it in Fahrenheit degrees: %0.2f" % DallasTemperature.toFahrenheit(temp))
# Load settings device = settings.get('Arduino', 'SERIAL_PORT') pin_sound = settings.getint('Arduino', 'PIN_SOUND') pin_temp = settings.getint('Arduino', 'PIN_TEMPERATURE') app_id = settings.get('Instapush', 'INSTAPUSH_APP_ID') app_secret = settings.get('Instapush', 'INSTAPUSH_APP_SECRET') event_id = settings.get('Instapush', 'INSTAPUSH_EVENT_NAME') threshold = settings.getfloat('Fridge', 'THRESHOLD') notify_every_x_seconds = settings.getfloat('Fridge', 'NOTIFY_EVERY_X_SECONDS') write_log_every_x_measurements = 50 # Startup arduino connection connection = SerialManager(device=device) connection.open() arduino = ArduinoApi(connection=connection) temperature_sensors = DallasTemperature(connection=connection, pin=pin_temp) temperature_sensors.setResolution(12) # Mute sound by default arduino.pinMode(pin_sound, arduino.OUTPUT) arduino.digitalWrite(pin_sound, 0) # Initial values last_alert = time.time() threshold_reached = False write_log_counter = 0 while True: temperature_sensors.requestTemperatures() temp = temperature_sensors.getTempC( 0) # Fetches the temperature on the first DS18B20 found on the pin.
#!/usr/bin/env python # Author: Andrea Stagi <*****@*****.**> # Description: just a test for DallasTemperature # Dependencies: None from nanpy import DallasTemperature sensors = DallasTemperature(5) print("There are %d devices connected on pin %d" % (sensors.getDeviceCount(), sensors.pin)) addr = sensors.getAddress(0) sensors.setResolution(9) while True: sensors.requestTemperatures(0) temp = sensors.getTempC(addr) print("The temperature, in Celsius degrees is %0.2f" % temp) print("Let's convert it in Fahrenheit degrees: %0.2f" % DallasTemperature.toFahrenheit(temp))
from nanpy import DallasTemperature #arduino = Arduino() #a.pinMode(13, a.OUTPUT) #a.digitalWrite(13, a.HIGH) # o = OneWire(a) sensors = DallasTemperature(2) addr = sensors.getAddress(2) sensors.requestTemperatures() temp = sensors.getTempC(addr) print temp
#!/usr/bin/env python # Author: Andrea Stagi <*****@*****.**> # Description: just a test for DallasTemperature # Dependencies: None from nanpy import DallasTemperature sensors = DallasTemperature(5) n_sensors = sensors.getDeviceCount() print("There are %d devices connected on pin %d" % (n_sensors, sensors.pin)) addresses = [] for i in range(n_sensors): addresses.append(sensors.getAddress(i)) sensors.setResolution(12) while True: sensors.requestTemperatures() for i in range(n_sensors): temp = sensors.getTempC(i) print("Device %d (%s) temperature, in Celsius degrees is %0.2f" % (i, addresses[i], temp)) print("Let's convert it in Fahrenheit degrees: %0.2f" % DallasTemperature.toFahrenheit(temp)) print("\n")
# Load settings device = settings.get('Arduino', 'SERIAL_PORT') pin_sound = settings.getint('Arduino', 'PIN_SOUND') pin_temp = settings.getint('Arduino', 'PIN_TEMPERATURE') app_id = settings.get('Instapush', 'INSTAPUSH_APP_ID') app_secret = settings.get('Instapush', 'INSTAPUSH_APP_SECRET') event_id = settings.get('Instapush', 'INSTAPUSH_EVENT_NAME') threshold = settings.getfloat('Fridge', 'THRESHOLD') notify_every_x_seconds = settings.getfloat('Fridge', 'NOTIFY_EVERY_X_SECONDS') write_log_every_x_measurements = 50 # Startup arduino connection connection = SerialManager(device=device) connection.open() arduino = ArduinoApi(connection=connection) temperature_sensors = DallasTemperature(connection=connection, pin=pin_temp) temperature_sensors.setResolution(12) # Mute sound by default arduino.pinMode(pin_sound, arduino.OUTPUT) arduino.digitalWrite(pin_sound, 0) # Initial values last_alert = time.time() threshold_reached = False write_log_counter = 0 while True: temperature_sensors.requestTemperatures() temp = temperature_sensors.getTempC(0) # Fetches the temperature on the first DS18B20 found on the pin.
def on_init(self): self.communicator.listen() print 'init' print self.params['tp1'] self.sensors = DallasTemperature(self.params['tp1'])