Exemple #1
0
    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)
            # Sleep for half a second, then take a picture
            time.sleep(.5)
            # Byte64 encode the picture
            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
    def createIote2eRequest(self):
        time.sleep(2)
        logger.info('ProcessTempToFan createIote2eRequest:')
        if self.tempDirectionIncrease and self.tempNow < self.TEMP_MAX:
            self.tempNow += self.TEMP_INCR
        elif (not self.tempDirectionIncrease) and self.tempNow > self.TEMP_MIN:
            self.tempNow -= self.TEMP_INCR
        logger.info("tempNow: {}".format(self.tempNow))

        if self.tempNow <= self.TEMP_MIN or self.tempNow >= self.TEMP_MAX:
            logger.error("Temp exceeded: {}".format(self.tempNow))
            # TODO: need to throw an exception or something so the calling thread exits
            sys.exit(8)

        # TODO: read temp from sensor here
        pairs = {self.sensorName: str(self.tempNow)}
        iote2eRequest = Iote2eRequest(
            login_name=self.loginVo.loginName,
            source_name=self.loginVo.sourceName,
            source_type='temperature',
            request_uuid=str(uuid.uuid4()),
            request_timestamp=ClientUtils.nowIso8601(),
            pairs=pairs,
            operation='SENSORS_VALUES')
        return iote2eRequest
    def createIote2eRequest(self ):
        time.sleep(1)
        logger.info('ProcessTempToFan createIote2eRequest:')
        #TODO: get temp from DAQC
        tempC = str(round(DAQC.getTEMP(0,0,'c'),2))
        pairs = { self.sensorName: tempC }

        iote2eRequest = Iote2eRequest( login_name=self.loginVo.loginName,source_name=self.loginVo.sourceName, source_type='temperature', 
                                       request_uuid=str(uuid.uuid4()), 
                                       request_timestamp=ClientUtils.nowIso8601(), 
                                       pairs=pairs, operation='SENSORS_VALUES')
        return iote2eRequest
 def createIote2eRequest(self ):
     iote2eRequest = None
     if self.cnt < 1001:
         pairs = { self.sensorName : str(self.cnt) }
         iote2eRequest = Iote2eRequest( login_name=self.loginVo.loginName,source_name=self.loginVo.sourceName, source_type='switch', 
                                        request_uuid=str(uuid.uuid4()), 
                                        request_timestamp=ClientUtils.nowIso8601(), 
                                        pairs=pairs, operation='SENSORS_VALUES')
         logger.info( "ProcessSwitch iote2eRequest {}".format(iote2eRequest))    
         self.cnt = self.cnt + 1
         #time.sleep(1)   
     return iote2eRequest
Exemple #5
0
def main(conf_file):
    import logging.config
    logging.config.fileConfig(conf_file, disable_existing_loggers=False)
    logger = logging.getLogger(__name__)
    logger.info('Starting')

    schemaRequest = avro.schema.parse(
        open('../../../../iote2e-schema/src/main/avro/iote2e-request.avsc',
             'rb').read())

    testPairs = {
        'testPairNameA': 'testPairValueA',
        'testPairNameB': 'testPairValueB'
    }
    testMetadata = {
        'testMetadataNameA': 'testMetadataValueA',
        'testMetadataNameB': 'testMetadataValueB'
    }

    iote2eRequestBefore = Iote2eRequest(
        login_name='testLogin',
        source_name='testSourceName',
        source_type='testSourceType',
        request_uuid='testRequestUuid',
        request_timestamp='testRequestTimestamp',
        pairs=testPairs,
        operation='SENSORS_VALUES',
        metadata=testMetadata)
    logger.info(iote2eRequestBefore)
    b = Iote2eRequest.commonToAvroBinarySchema(
        schema=schemaRequest, dictContent=iote2eRequestBefore.__dict__)
    logger.info(len(str(iote2eRequestBefore)))
    logger.info(len(b))

    iote2eRequestAfter = Iote2eRequest.requestFromAvroBinarySchema(
        schema=schemaRequest, rawBytes=b)
    logger.info(iote2eRequestAfter)
    logger.info(iote2eRequestAfter.pairs['testPairNameB'])
Exemple #6
0
    def createIote2eRequest(self):
        time.sleep(2)
        ledGreenState = self.getLedGreenState()
        # TODO: read switch on/off from here
        logger.info(
            "ProcessSimLedGreen createIote2eRequest ledGreenState: {}".format(
                ledGreenState))

        pairs = {self.sensorName: str(ledGreenState)}
        iote2eRequest = Iote2eRequest(
            login_name=self.loginVo.loginName,
            source_name=self.loginVo.sourceName,
            source_type='switch',
            request_uuid=str(uuid.uuid4()),
            request_timestamp=ClientUtils.nowIso8601(),
            pairs=pairs,
            operation='SENSORS_VALUES')
        return iote2eRequest
Exemple #7
0
 def createIote2eRequest(self):
     iote2eRequest = None
     if DAQC.getINTflags(0) == 256:
         logger.info("ProcessLedGreen createIote2eRequest {}".format(
             self.sensorName))
         pairs = {self.sensorName: self.btnPressed}
         iote2eRequest = Iote2eRequest(
             login_name=self.loginVo.loginName,
             source_name=self.loginVo.sourceName,
             source_type='switch',
             request_uuid=str(uuid.uuid4()),
             request_timestamp=ClientUtils.nowIso8601(),
             pairs=pairs,
             operation='SENSORS_VALUES')
         if self.btnPressed == '1':
             self.btnPressed = '0'
         else:
             self.btnPressed = '1'
     return iote2eRequest
Exemple #8
0
 def run(*args):
     loginVoJson = json.dumps(self.loginVo.__dict__)
     ws.send(loginVoJson)
     while True:
         if self.isShutdown:
             break
         if self.socketState == SocketState.ERROR or self.socketState == SocketState.CLOSED:
             break
         try:
             iote2eRequest = self.requestQueue.get(True, 2)
             if iote2eRequest != None:
                 byteArray = Iote2eRequest.commonToAvroBinarySchema(
                     schema=self.schemaRequest,
                     dictContent=iote2eRequest.__dict__)
                 ws.send(byteArray, opcode=ABNF.OPCODE_BINARY)
         except Empty:
             pass
     time.sleep(1)
     ws.close()
     logger.info(self.loginVo.loginName + " Thread terminating ")