def sample(channel): """ Callback function for button interrupt that causes a sample to be taken from both sensors. """ time.sleep(0.1) print("Button pushed!") DAQC.getINTflags(0) # clear the interrupt # use light strobes to indicate measurement DAQC.setDOUTall(0, 0) for j in range(7): DAQC.setDOUTbit(0, j) time.sleep(0.1) DAQC.clrDOUTbit(0, j) time.sleep(0.1) # measure from the BME280 (ORDER MATTERS!) temp = sensor.read_temperature() pressure = sensor.read_pressure() / 100. # convert to hectopascals humidity = sensor.read_humidity() t = sensor.t_fine # measure from the (analog) photo-sensor light = DAQC.getADC(0, 0) global data data.append([t, temp, pressure, humidity, light]) # turn off LEDs DAQC.setDOUTall(0, 0)
def compressor(state=None): if state == None: return DAQC.getDOUTbyte(0) if state == True: DAQC.setDOUTbit(0, 0) if state == False: DAQC.clrDOUTbit(0, 0)
def setValues(self, address, values): caddress = self.corrected_address(address) for i, value in enumerate(values): bit_addr = caddress + i self.log('writing {} to {}'.format(value, bit_addr)) if value: dp.setDOUTbit(self._board_address, bit_addr) else: dp.clrDOUTbit(self._board_address, bit_addr)
def triggerINT(): """Callback rountine when a Digital Input has been triggered. """ logger.debug("triggerINT") DAQC.setDOUTbit(0, 0) DAQC.getINTflags(0) if DEBUG: print("\033[94m _-*xmit triggered!*-_ \033[0m") vswr() DAQC.clrDOUTbit(0, 0)
def main(): signal.signal(signal.SIGINT, signal_handler) while True: value = round(DAQC.getADC(0, DACport), 2) if (value < 3.20) or (value > 3.7) : print "Value " + str(value) + ", Activated!" DAQC.setDOUTbit(0,0) playAudio() DAQC.clrDOUTbit(0,0) else: print "Value " + str(value) + ", Waiting..." time.sleep(0.1) GPIO.cleanup()
Return: percent : int - returns the percentage of the sensor ''' if percent > 100: percent = 100 if percent < 0: percent = 0 return percent def soundTheAlarm(state): ''' Description: Recieves the voltage input from the DACQ board to determine if the alarm needs to go on or off. Parameters: state : char - 'c' for Cancel alarm, or 's' Sound alarm Return: percent : int - returns the percentage of the sensor ''' #try to get a reading, and get the voltage input from the daqc board try: #Allows voltage to go through to turn off the alarm if state == 'c': DAQC.clrDOUTbit(0, 0) #Allows voltage to go through to turn on the alarm if state == 's': DAQC.setDOUTbit(0, 0) #If not voltage was read or it errored except: print("") #checkValue of the percentage bounds and than return it
def createIote2eRequest(self ): logger.info('ProcessPillDispenser dispenseState: ' + str(self.dispenseState) ) iote2eRequest = None if None == self.dispenseState: time.sleep(1) elif 'DISPENSING' == self.dispenseState: # Tell the pill dispenser to dispense the number of pills self.handlePillDispenser.dispensePills(self.numPillsToDispense) # Turn on the LED DAQC.setDOUTbit(self.daqcBoard,0) # Sleep for half a second, then take a picture time.sleep(.5) # Byte64 encode the picture imageByte64 = self.takePicture() # Turn off the LED DAQC.clrDOUTbit(self.daqcBoard,0) #with open("/home/pete/development/gitrepo/iote2e/iote2e-tests/iote2e-shared/images/iote2e-test4.png", "rb") as image_file: # imageByte64 = base64.b64encode(image_file.read()) # Create Iote2eRequest that contains the confirmation image self.dispenseState = 'DISPENSED_PENDING' pairs = { self.sensorName: imageByte64} metadata = { 'PILLS_DISPENSED_UUID': self.pillsDispensedUuid, 'PILLS_DISPENSED_STATE' : 'DISPENSED', 'NUM_PILLS_TO_DISPENSE' : str(self.numPillsToDispense) } iote2eRequest = Iote2eRequest( login_name=self.loginVo.loginName,source_name=self.loginVo.sourceName, source_type='pill_dispenser', request_uuid=str(uuid.uuid4()), request_timestamp=ClientUtils.nowIso8601(), pairs=pairs, metadata=metadata, operation='SENSORS_VALUES') elif 'DISPENSED' == self.dispenseState: logger.info('self.pillsDispensedDelta: ' + str(self.pillsDispensedDelta) ) if self.pillsDispensedDelta == 0: msg = 'Correct number of pills dispensed' logger.info( msg ) self.blinkLedThread = BlinkLedThread(ledColor='green') self.blinkLedThread.start() else: if self.pillsDispensedDelta < 0: msg = "Not enough pills dispensed" else: msg = "Too many pills dispensed" logger.info( msg ) self.blinkLedThread = BlinkLedThread(ledColor='red') self.blinkLedThread.start() # Wait for button being pushed on separate thread self.dispenseState = 'CONFIRMED_PENDING' self.buttonPushedThread = ButtonPushedThread( self ) self.buttonPushedThread.start() elif 'CONFIRMING' == self.dispenseState: pairs = { self.sensorName: '' } metadata = { 'PILLS_DISPENSED_UUID': self.pillsDispensedUuid, 'PILLS_DISPENSED_STATE' : 'CONFIRMED'} iote2eRequest = Iote2eRequest( login_name=self.loginVo.loginName,source_name=self.loginVo.sourceName, source_type='pill_dispenser', request_uuid=str(uuid.uuid4()), request_timestamp=ClientUtils.nowIso8601(), pairs=pairs, metadata=metadata, operation='ACTUATOR_CONFIRM') self.dispenseState = 'CONFIRMED_PENDING' time.sleep(.25) elif 'CONFIRMED' == self.dispenseState: self.dispenseState = None time.sleep(.25) else: time.sleep(1) return iote2eRequest
break print(json.dumps(resp)) elif (plate_type == "DAQC"): with simpleflock.SimpleFlock("/tmp/daqc.lock", timeout=3): if (cmd == "getDINbit"): bit = args['bit'] try: state = DP.getDINbit(addr, bit) except AssertionError: state = DP2.getDINbit(addr, bit) resp['bit'] = bit resp['state'] = state elif (cmd == "setDOUTbit"): bit = args['bit'] try: DP.setDOUTbit(addr, bit) except AssertionError: DP2.setDOUTbit(addr, bit) resp['bit'] = bit resp['state'] = 1 elif (cmd == "clrDOUTbit"): bit = args['bit'] try: DP.clrDOUTbit(addr, bit) except AssertionError: DP2.clrDOUTbit(addr, bit) resp['bit'] = bit resp['state'] = 0 elif (cmd == "toggleDOUTbit"): bit = args['bit'] try:
def blink_dio(c): DAQC.setDOUTbit(0, c) sleep(0.1) DAQC.clrDOUTbit(0, c) sleep(0.1)
from __future__ import print_function import piplates.RELAYplate as RELAY import piplates.DAQCplate as DAQC import time ppADDR = 1 volt = 0.0 i = 0 while True: if volt >= 4.095: volt = 0.0 if i > 6: i = 0 DAQC.setDAC(1, 0, volt) DAQC.setDOUTbit(1, i) time.sleep(0.1) volt = volt + .01 i = i + 1
MainAmps = Curr(0,0) HotAmps = Curr(0,1) ColdAmps = Curr(0,2) Temp = daqc.getTEMP(0, 0, TempUnits[0]) #Check our last run time, if > minCycle, see if we need to toggle SSRs lrf = open("{0}/last.run".format(PID_PATH), 'r') lastRun = float(lrf.read()) lrf.close() now = time.time() if now > (lastRun + MinCycle): Toggled = 0 if Temp > MaxTemp: if ColdState == 0: daqc.clrDOUTbit(0,0) #Hot Off daqc.setDOUTbit(0,1) #Cold On HotState = 0 ColdState = 1 Toggled = 1 elif Temp < MinTemp: if HotState == 0: daqc.setDOUTbit(0,0) #Hot On daqc.clrDOUTbit(0,1) #Cold Off HotState = 1 ColdState = 0 Toggled = 1 else: if (ColdState == 1) or (HotState == 1): daqc.setDOUTall(0,0) #all Off HotState = 0 ColdState = 0
async def run(self): msgCnt = 0 # Set device client from Azure IoT SDK and connect device_client = None try: while True: GPIO.output(self.Wait, GPIO.HIGH) await asyncio.sleep(self.config["TelemetryFrequencyInSeconds"]) msgCnt = msgCnt + 1 GPIO.output(self.Wait, GPIO.LOW) GPIO.output(self.Good, GPIO.HIGH) print("[%s]: Reading Thermocoupler Values" % self.config["NameSpace"]) print("[%s]: Plate Cold Value" % ThermoPlate.getCOLD(self.ThermoPlate_addr)) # READ FIREBOX print("[%s]: Reading the FIRE BOX TEMPERATURE" % self.config["NameSpace"]) DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.FireBoxStatus) self.TemperatureFireBox = ThermoPlate.getTEMP( self.ThermoPlate_addr, self.FireBox) await asyncio.sleep( self.config["ReadTimeBetweenTemperatureInSeconds"]) DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.FireBoxStatus) # READ WARMING BOX print("[%s]: Reading the WARMING BOX TEMPERATURE" % self.config["NameSpace"]) DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.WarmingBoxStatus) self.TemperatureWarmingBox = ThermoPlate.getTEMP( self.ThermoPlate_addr, self.WarmingBox) await asyncio.sleep( self.config["ReadTimeBetweenTemperatureInSeconds"]) DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.WarmingBoxStatus) # READ LEFT BACK CHAMBER print("[%s]: Reading the LEFT BACK CHAMBER TEMPERATURE" % self.config["NameSpace"]) DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.LeftBackStatus) self.TemperatureLeftBack = ThermoPlate.getTEMP( self.ThermoPlate_addr, self.LeftBack) await asyncio.sleep( self.config["ReadTimeBetweenTemperatureInSeconds"]) DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.LeftBackStatus) # READ RIGHT BACK CHAMBER print("[%s]: Reading the RIGHT BACK CHAMBER TEMPERATURE" % self.config["NameSpace"]) DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.RightBackStatus) self.TemperatureRightBack = ThermoPlate.getTEMP( self.ThermoPlate_addr, self.RightBack) await asyncio.sleep( self.config["ReadTimeBetweenTemperatureInSeconds"]) DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.RightBackStatus) # READ LEFT FRONT CHAMBER print("[%s]: Reading the LEFT FRONT CHAMBER TEMPERATURE" % self.config["NameSpace"]) DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.LeftFrontStatus) self.TemperatureLeftFront = ThermoPlate.getTEMP( self.ThermoPlate_addr, self.LeftFront) await asyncio.sleep( self.config["ReadTimeBetweenTemperatureInSeconds"]) DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.LeftFrontStatus) # READ RIGHT FRONT CHAMBER print("[%s]: Reading the RIGHT FRONT CHAMBER TEMPERATURE" % self.config["NameSpace"]) DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.RightFrontStatus) self.TemperatureRightFront = ThermoPlate.getTEMP( self.ThermoPlate_addr, self.RightFront) await asyncio.sleep( self.config["ReadTimeBetweenTemperatureInSeconds"]) DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.RightFrontStatus) self.TemperatureAmbient = ThermoPlate.getTEMP( self.ThermoPlate_addr, self.Ambient, "f") table = Texttable() table.set_deco(Texttable.HEADER) table.set_cols_dtype(["t", "f", "f", "f"]) table.set_cols_align(["l", "r", "r", "r"]) table.add_rows([ [ "Sensor Name", "Temperature", "Last Temperature", "Smoothing" ], [ self.AmbientDisplayText, self.TemperatureAmbient, self.LastTemperatureAmbient, self.TemperatureAmbient / self.smoothing_value ], [ self.FireBoxDisplayText, self.TemperatureFireBox, self.LastTemperatureFireBox, self.TemperatureFireBox / self.smoothing_value ], [ self.WarmingBoxDisplayText, self.TemperatureWarmingBox, self.LastTemperatureWarmingBox, self.TemperatureWarmingBox / self.smoothing_value ], [ self.LeftBackDisplayText, self.TemperatureLeftBack, self.LastTemperatureLeftBack, self.TemperatureLeftBack / self.smoothing_value ], [ self.RightBackDisplayText, self.TemperatureRightBack, self.LastTemperatureRightBack, self.TemperatureRightBack / self.smoothing_value ], [ self.LeftFrontDisplayText, self.TemperatureLeftFront, self.LastTemperatureLeftFront, self.TemperatureLeftFront / self.smoothing_value ], [ self.RightFrontDisplayText, self.TemperatureRightFront, self.LastTemperatureRightFront, self.TemperatureRightFront / self.smoothing_value ] ]) print(table.draw()) print("***") # Smooth Values self.TemperatureAmbient = self.TemperatureAmbient / self.smoothing_value self.TemperatureFireBox = self.TemperatureFireBox / self.smoothing_value self.TemperatureWarmingBox = self.TemperatureWarmingBox / self.smoothing_value self.TemperatureLeftBack = self.TemperatureLeftBack / self.smoothing_value self.TemperatureRightBack = self.TemperatureRightBack / self.smoothing_value self.TemperatureLeftFront = self.TemperatureLeftFront / self.smoothing_value self.TemperatureRightFront = self.TemperatureLeftFront / self.smoothing_value # Capture Last Values self.LastTemperatureAmbient = self.TemperatureAmbient self.LastTemperatureFireBox = self.TemperatureFireBox self.LastTemperatureWarmingBox = self.TemperatureWarmingBox self.LastTemperatureLeftBack = self.TemperatureLeftBack self.LastTemperatureRightBack = self.TemperatureRightBack self.LastTemperatureLeftFront = self.TemperatureLeftFront self.LastTemperatureRightFront = self.TemperatureLeftFront # Send Data to IoT Central for device in self.map_telemetry["Devices"]: if device_client == None: self.logger.info( "[BBQ MONITOR] CONNECTING IOT CENTRAL: %s" % device_client) device_client = DeviceClient(self.logger, device["Name"]) print(device_client) await device_client.connect() for interface in device["Interfaces"]: self.logger.info("[BBQ MONITOR] InterfacelId: %s" % interface["InterfacelId"]) self.logger.info( "[BBQ MONITOR] InterfaceInstanceName: %s" % interface["InterfaceInstanceName"]) self.telemetry_dict = {} for capability in interface["Capabilities"]: # Assign variable name and value to dictionary if capability[ "Name"] == self.TemperatureAmbientMapName: self.telemetry_dict[capability[ "Name"]] = self.TemperatureAmbient elif capability[ "Name"] == self.TemperatureFireBoxMapName: self.telemetry_dict[capability[ "Name"]] = self.TemperatureFireBox elif capability[ "Name"] == self.TemperatureWarmingBoxMapName: self.telemetry_dict[capability[ "Name"]] = self.TemperatureWarmingBox elif capability[ "Name"] == self.TemperatureLeftBackMapName: self.telemetry_dict[capability[ "Name"]] = self.TemperatureLeftBack elif capability[ "Name"] == self.TemperatureRightBackMapName: self.telemetry_dict[capability[ "Name"]] = self.TemperatureRightBack elif capability[ "Name"] == self.TemperatureLeftFrontMapName: self.telemetry_dict[capability[ "Name"]] = self.TemperatureLeftFront elif capability[ "Name"] == self.TemperatureRightFrontMapName: self.telemetry_dict[capability[ "Name"]] = self.TemperatureRightFront else: self.telemetry_dict[capability["Name"]] = 0 self.logger.info("[BBQ MONITOR] DICTIONARY: %s" % self.telemetry_dict) self.logger.info( "[BBQ MONITOR] SENDING PAYLOAD IOT CENTRAL") await device_client.send_telemetry( self.telemetry_dict, interface["InterfacelId"], interface["InterfaceInstanceName"]) self.logger.info("[BBQ MONITOR] SUCCESS") GPIO.output(self.Good, GPIO.LOW) return except Exception as ex: self.logger.error("[ERROR] %s" % ex) self.logger.error( "[TERMINATING] We encountered an error in BBQ Monitor Run::run()" ) finally: await device_client.disconnect()