def get_measurement(self): logger.debug('air quality sensor data') try: # Get sensor value sensor_value = grovepi.analogRead(self.air_sensor) if sensor_value > 700: air_quality = "High pollution" elif sensor_value > 300: air_quality = "Low Pollution" else: air_quality = "Air fresh" return Response( { 'time': datetime.now().timestamp(), 'value': sensor_value, 'airQuality': air_quality }, errors=None) except IOError as exc: return Response(response=None, errors=[ IoTError('IOError', ErrorCode.UNKNOWN, exc.__cause__, exc.__traceback__) ])
def get_measurement(self): self.global_counter += 1 if self.global_counter % 10 == 0: return Response(response=None, errors=[ IoTError('MockError', ErrorCode.STATUS_OFF, 'The MockSensor mocks an error every 10 iterations', 'blah->nooooo->save me->dead')]) else: return Response({'time': datetime.now().timestamp(), 'value': random.random() * 1000}, errors=None)
def get_measurement(self): logger.debug('temp data') return Response({ 'time': datetime.now().timestamp(), 'value': 37 }, errors=None)
def get_measurement(self) -> Response: res = {} errs = [] for key, value in self.pins: try: res[key] = self.read_pin(value) except Exception as exc: errs.append( IoTError(type=exc.__class__.__name__, code=ErrorCode.UNKNOWN, reason=str(exc.__cause__), trace=str(exc.__traceback__))) pass return Response(response=res, errors=errs)