annotate web/test.py @ 543:77dba104dcda

merge
author Matt Johnston <matt@ucc.asn.au>
date Thu, 21 May 2015 00:00:54 +0800
parents 83c83014e5e3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
335
1e22eaf93620 work on web interface
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #!/usr/bin/env python
1e22eaf93620 work on web interface
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
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
1e22eaf93620 work on web interface
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
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])