Skip to content

Instantly share code, notes, and snippets.

@miccoli
Last active May 16, 2020 16:15
Show Gist options
  • Save miccoli/5a6fcb400e13a22873863df6d3b48c02 to your computer and use it in GitHub Desktop.
Save miccoli/5a6fcb400e13a22873863df6d3b48c02 to your computer and use it in GitHub Desktop.
Refactored python code
import sys
import time
from pyownet import protocol
temp_type = "F"
pyownet_flags = protocol.FLG_TEMP_F | protocol.FLG_UNCACHED
tc_1_mac = "FF8AD3641402"
sensor_file_1 = "/28.{}/temperature".format(tc_1_mac)
def main():
try:
owproxy = protocol.proxy(persistent=True, flags=pyownet_flags)
except protocol.ConnError as exc:
print("No connection: {}".format(exc), file=sys.stderr)
sys.exit(1)
except protocol.ProtocolError as exc:
print("Protocol error: {}".format(exc), file=sys.stderr)
sys.exit(1)
while True:
try:
heater_temp_1 = float(owproxy.read(sensor_file_1))
print("SENSOR #1 = {:.2f} {}".format(heater_temp_1, temp_type))
except IOError:
print("SENSOR #1 READ FAIL")
time.sleep(10)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment