@@ -54,10 +54,11 @@ def __init__(self, block):
5454 self .pressure = (block [0 ] << 16 | block [1 ] << 8 | block [2 ]) >> 4
5555 self .temperature = (block [3 ] << 16 | block [4 ] << 8 | block [5 ]) >> 4
5656 self .humidity = block [6 ] << 8 | block [7 ]
57+ self .sensorid = (((block [11 ] + (block [10 ] << 8 )) & 0x7fff ) << 16 ) + ((block [9 ]) << 8 ) + block [8 ]
5758
5859 def __repr__ (self ):
59- return "uncompensated_reading(temp=0x{0:08X}, pressure=0x{1:08X}, humidity=0x{2:08X}, block={3 })" .format (
60- self .temperature , self .pressure , self .humidity ,
60+ return "uncompensated_reading(temp=0x{0:08X}, pressure=0x{1:08X}, humidity=0x{2:08X}, sensorid=0x{3:08X}, block={4 })" .format (
61+ self .temperature , self .pressure , self .humidity , self . sensorid ,
6162 ":" .join ("{0:02X}" .format (c ) for c in self ._block ))
6263
6364
@@ -84,6 +85,7 @@ def __init__(self, raw_readings, compensation_params):
8485 raw_readings .temperature )
8586 self .pressure = self .__calc_pressure (raw_readings .pressure ,
8687 raw_readings .temperature ) / 100.0
88+ self .sensorid = raw_readings .sensorid
8789
8890 def __tfine (self , t ):
8991 v1 = (t / 16384.0 - self ._comp .dig_T1 / 1024.0 ) * self ._comp .dig_T2
@@ -116,8 +118,8 @@ def __calc_pressure(self, p, t):
116118 return res
117119
118120 def __repr__ (self ):
119- return "compensated_reading(id={0}, timestamp={1:%Y-%m-%d %H:%M:%S.%f%Z}, temp={2:0.3f} °C, pressure={3:0.2f} hPa, humidity={4:0.2f} % rH)" .format (
120- self .id , self .timestamp , self .temperature , self .pressure , self .humidity )
121+ return "compensated_reading(sensorid=0x{5:08X}, id={0}, timestamp={1:%Y-%m-%d %H:%M:%S.%f%Z}, temp={2:0.3f} °C, pressure={3:0.2f} hPa, humidity={4:0.2f} % rH)" .format (
122+ self .id , self .timestamp , self .temperature , self .pressure , self .humidity , self . sensorid )
121123
122124
123125class params (dict ):
@@ -217,5 +219,6 @@ def sample(bus, address=DEFAULT_PORT, compensation_params=None, sampling=oversam
217219 time .sleep (delay )
218220
219221 block = bus .read_i2c_block_data (address , 0xF7 , 8 )
222+ block .extend (bus .read_i2c_block_data (address , 0x83 , 4 ))
220223 raw_data = uncompensated_readings (block )
221224 return compensated_readings (raw_data , compensation_params )
0 commit comments