Skip to content

Commit

Permalink
✨ Add onewire runner as adhoc util script
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Dec 2, 2024
1 parent f6eff97 commit 7e69909
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions util/onewire_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Poll the OneWire bus for devices."""

import os
import subprocess
import time
from datetime import datetime

os.environ["TZ"] = "CST6CDT"


def work():
"""Do the work."""
with subprocess.Popen(
["./digitemp", "-q", "-a", "-s", "/dev/ttyS0", "-o", "%s %.2F"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
) as proc:
stdout, stderr = proc.communicate()
d = stdout.decode("ascii").split("\n")
with open("onewire.txt", "w") as fh:
fh.write("\n".join(d))
data = {}
for line in d:
if not line:
continue
t = line.split()
try:
data[int(t[0])] = t[1]
except Exception:
print(line)
if len(data) < 4:
print("ERROR: not enough data")
return
now = datetime.now()
fp = f"ot0003_{now:%Y%m%d%H%M}.dat"
with open(fp, "w") as fh:
fh.write(
"104,%s,%s, %s, %s, %s,11.34\n"
% (now.strftime("%Y,%j,%H%M"), data[0], data[1], data[2], data[3])
)
subprocess.call(["/home/meteor_ldm/bin/pqinsert", fp])
os.remove(fp)


def main():
"""Go Main Go."""
with open("runner.pid", "w") as fh:
fh.write(f"{os.getpid()}")
while 1:
work()
time.sleep(58)


if __name__ == "__main__":
main()

0 comments on commit 7e69909

Please sign in to comment.