Mercurial > templog
annotate web/test.py @ 500:136b1343e640
merge
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 24 Mar 2014 20:49:00 +0800 |
parents | 83c83014e5e3 |
children |
rev | line source |
---|---|
335 | 1 #!/usr/bin/env python |
2 import time | |
381
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
3 import struct |
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
4 import sys |
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
5 import binascii |
335 | 6 |
381
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
7 def convert_ds18b20_12bit(reading): |
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
8 value = struct.unpack('>h', binascii.unhexlify(reading))[0] |
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
9 return value * 0.0625 |
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
10 |
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
11 if __name__ == '__main__': |
83c83014e5e3
report raw ds18b20 values instead
Matt Johnston <matt@ucc.asn.au>
parents:
335
diff
changeset
|
12 print convert_ds18b20_12bit(sys.argv[1]) |