pres = temp = humi = wet = None if data is not None: if 'pressure' in data: pres = data['pressure'] if 'temp' in data: temp = data['temp'] if 'humidity' in data: humi = data['humidity'] if 'temp' in data and 'humidity' in data: wet = web_met.GetWetTemp(temp, humi) elif cr.json['met'].upper() == 'BMP180': from bmp180measureunit import BMP180MeasureUnit from i2ciface import I2CIface from bmp180 import BMP180 bmp_mu = BMP180MeasureUnit() i2c = I2CIface(None, 0x77) try: bmp = BMP180('BMP180', bmp_mu, i2c) except IOError: logging.fatal("BMP180 sensor not found") sys.exit(1) pres = float(bmp.GetPressure()['pressure']) temp = float(bmp.GetTemp()['temp']) wet = None # wet temperature unknown elif cr.json['met'].upper() == 'SENSEHAT': from sense_hat import SenseHat from webmet import WebMet sense = SenseHat() pres = sense.get_pressure() temp = sense.get_temperature() humi = sense.get_humidity()
def GetMag(self): """ get magnetometer data :returns: 3 axis magneto data """ msg = self.measureUnit.GetMagMsg() return self._process(msg, 0) if __name__ == '__main__': import math from i2ciface import I2CIface from echowriter import EchoWriter i1d = I2CIface('accel', 0x1d) # iface for acellero/magnetic i6b = I2CIface('gyro', 0x6b) # iface for gyroscope munit = LSM9DS0Unit() wunit = EchoWriter() s9dof = LSM9DS0('9 DOF', munit, [i1d, i6b], wunit) for i in range(5): print("Accelerometer") w = s9dof.GetAccel() print(math.sqrt(w['acc_x']**2 + w['acc_y']**2 + w['acc_z']**2)) print("Magnetometer") w = s9dof.GetMag() print(math.sqrt(w['mag_x']**2 + w['mag_y']**2 + w['mag_z']**2)) #print("Gyro") #w = s9dof.GetGyro() #print(math.sqrt(w['gyro_x']**2 + w['gyro_y']**2 + w['gyro_z']**2))