Watchport/T and subzero temperatures


I’m having problems getting the right values for the temperature if it’s subzero degrees (C). I don’t use the python libs provided by you but “borrowed” the conversion code from because I could find any decent documentation on the format of the 1S sample response.

According to your library a temp is negative, if the first 5 bits of the sample are set to 1, then all you need to do is negate the valued calculated before.

However this gives me wrong results, f.e. -122,62 or -126,69. After a bit of examination I think I have found the problem, is it possible that you have to flip the bits if the temp. is below zero? This would give me plausible results.

Sensor gives me FF AA as result.

is negative? FF AA & F8 00 != 0 : true
extract the integer: (FF AA & 7F0) >> 4 = 7A (= 122d, 1111010b)

if you flip the bits you’ll get 0000101b which would mean 5 degrees below zero, a plausible value for the temp. outside.

So could anybody give me a hint what’s wrong with the temp. calculation?


I think you are pretty accurate on your work.

The older code looked like this for the temperature determination:

self.temperature = (self.sample[5] & 0x7f0) >> 4
self.temperature += (self.sample[5] & 0xf) / 16.0
if self.sample[5] & 0xf800:
self.temperature = - self.temperature

The if statement does exactly as you say, just negates the value if the upper bits are on.

The newer code (Got from from Digi’s website) has slightly different code:

temp = struct.pack(‘>h’, ~self.sample[5])
self.temperature = ~struct.unpack(‘>h’, temp)[0] / 16.0

The code is doing a bitwise not on the temperature value to do what you mentioned in your post.

To check to see if really worked, I loaded up my gateway with the old code, dunked my 1-wire sensor in some snow (its -16 degress here!) and saw -116.562500 F. I retried it using the updated and got -10.562500 F(It warmed up a bit I guess).

Good find though!