Example #1
0
 def readLight(self):
     data = Peripheral.readCharacteristic(self, 0x0044)
     data = struct.unpack('<h', data)[0]
     m = data & 0xFFF
     e = (data & 0xF000) >> 12
     result = 0.01 * (m << e)
     return ("{:.2f}".format(result))  # Formatierung
Example #2
0
 def readMagnetometer(self):
     data = Peripheral.readCharacteristic(
         self, 0x003c)  # alle 18 bytes einlesen (zwei bytes je Achse)
     data = struct.unpack(
         "<9h", data
     )[6:7]  # Umwandlung signed Integers(C) in Integer(Python) und Slicing
     data = data[0]  # Umwandlung Tuple in Int
     return ("{:.2f}".format(data))
Example #3
0
 def readAccelerometer(self):
     data = Peripheral.readCharacteristic(
         self, 0x003c)  # alle 18 bytes einlesen (zwei bytes je Achse)
     data = struct.unpack(
         "<9h", data
     )[3:6]  # Umwandlung signed Integers(C) in Integer(Python) und Slicing
     x_y_z = tuple([elem * (4.0 / 32768.0) for elem in data
                    ])  # Umrechnung gemäß Doku mit Acc.- Range 4G
     return x_y_z  # optional als string' '.join(format(f, '.5f') for f in x_y_z)
Example #4
0
 def readGyroscope(self):
     data = Peripheral.readCharacteristic(
         self, 0x003c)  # alle 18 bytes einlesen (zwei bytes je Achse)
     data = struct.unpack(
         "<9h", data
     )[0:3]  # Umwandlung signed Integers(C) in Integer(Python) und Slicing
     x_y_z = tuple([elem * (500.0 / 65536.0)
                    for elem in data])  # Umrechnung gemäß Doku
     return x_y_z  # optional als string' '.join(format(f, '.5f') for f in x_y_z)
Example #5
0
 def readBarometer(self):
     data = Peripheral.readCharacteristic(self, 0x0034)
     #  two 24-bit unsigned integers: the temperature in bytes 0-2, the pressure in bytes 3-5
     (tL, tM, tH, pL, pM, pH) = struct.unpack('<6B', data)
     temp = (
         tH * 65536 + tM * 256 + tL
     ) / 100.0  # nicht im return statement,Temperatur kommt vom Feuchtigkeitssensor
     press = (pH * 65536 + pM * 256 + pL) / 100.0
     return ("{:.2f}".format(temp, press))
Example #6
0
 def readTemperature(self):
     data = Peripheral.readCharacteristic(self, 0x002c)
     (rawT, rawH) = struct.unpack('<HH', data)
     temp = (rawT / 65536.0) * 165.0 - 40.0
     return ("{:.2f}".format(temp))
Example #7
0
 def readHumidity(self):
     data = Peripheral.readCharacteristic(self, 0x002c)
     (rawT, rawH) = struct.unpack('<HH', data)
     RH = (rawH / 65536.0) * 100.0
     return ("{:.2f}".format(RH))
Example #8
0
 def readBattery(self):
     data = Peripheral.readCharacteristic(self, 0x001e)
     data = ord(data)
     return ("{}".format(data))