Modify the kiln logger to be less redundant, and modify the CSV parser bit
This commit is contained in:
parent
96c968d698
commit
f484d7b5f9
1 changed files with 24 additions and 16 deletions
|
|
@ -12,7 +12,7 @@ from luma.led_matrix.device import max7219
|
||||||
from luma.core.interface.serial import spi, noop
|
from luma.core.interface.serial import spi, noop
|
||||||
from luma.core.virtual import viewport, sevensegment
|
from luma.core.virtual import viewport, sevensegment
|
||||||
|
|
||||||
import requests
|
# import requests
|
||||||
|
|
||||||
|
|
||||||
STD_HEADER = [
|
STD_HEADER = [
|
||||||
|
|
@ -65,7 +65,7 @@ def logger(hostname, csvfile, noprofilestats, pidstats, stdout):
|
||||||
csv_stdout = None
|
csv_stdout = None
|
||||||
|
|
||||||
# setup seven segment display
|
# setup seven segment display
|
||||||
|
# remove comment on the next line if using SPI interface 0. currently using SPI interface 1
|
||||||
#serial = spi(port=0, device=0, gpio=noop())
|
#serial = spi(port=0, device=0, gpio=noop())
|
||||||
serial = spi(port=1, device=0, gpio=noop())
|
serial = spi(port=1, device=0, gpio=noop())
|
||||||
device = max7219(serial, cascaded=2)
|
device = max7219(serial, cascaded=2)
|
||||||
|
|
@ -104,32 +104,40 @@ def logger(hostname, csvfile, noprofilestats, pidstats, stdout):
|
||||||
msg[k] = '{:5.3f}'.format(v)
|
msg[k] = '{:5.3f}'.format(v)
|
||||||
csv_stdout.writerow(msg)
|
csv_stdout.writerow(msg)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
# ADD THE TEMPERATURE HERE
|
|
||||||
try:
|
|
||||||
req = requests.get('http://127.0.0.1:8081/api/stats')
|
|
||||||
|
|
||||||
except KeyError:
|
# ADD THE TEMPERATURE HERE with requests library, however, this is redundant, as the
|
||||||
try:
|
# websocket messaging already has the temp value.
|
||||||
req = requests.get('http://127.0.0.1:8081/api/stats')
|
# try:
|
||||||
except Exception:
|
# req = requests.get('http://127.0.0.1:8081/api/stats')
|
||||||
time.sleep(25)
|
|
||||||
|
|
||||||
continue
|
# except KeyError:
|
||||||
|
# try:
|
||||||
|
# req = requests.get('http://127.0.0.1:8081/api/stats')
|
||||||
|
# except Exception:
|
||||||
|
# time.sleep(25)
|
||||||
|
|
||||||
temp = round(req.json()['ispoint'])
|
# continue
|
||||||
|
|
||||||
|
# TODO: temp needs to be error checked if using the requests library.
|
||||||
|
# expected value is a decimal/float value between -58 and 2372 deg F
|
||||||
|
# temp = round(req.json()['ispoint'])
|
||||||
|
|
||||||
|
temp = round(msg['temperature'])
|
||||||
|
# time remaining for the display, calculated for rounded seconds
|
||||||
time_rem = msg['totaltime'] - msg['runtime']
|
time_rem = msg['totaltime'] - msg['runtime']
|
||||||
hours = round(time_rem // 3600)
|
hours = round(time_rem // 3600)
|
||||||
minutes = round((time_rem - (hours * 3600)) // 60)
|
minutes = round((time_rem - (hours * 3600)) // 60)
|
||||||
seconds = round((time_rem - (hours * 3600) - (minutes * 60)))
|
seconds = round((time_rem - (hours * 3600) - (minutes * 60))) - 1
|
||||||
|
|
||||||
seg.text = f"TEMP{temp:4.0f}{hours:2.0f}-{minutes:2.0f}-{seconds:2.0f}"
|
seg.text = f"{hours:2.0f}-{minutes:2.0f}-{seconds:2.0f}TEMP{temp:4.0f}"
|
||||||
# END ADD TEMP
|
# END ADD TEMP
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Log kiln data for analysis.')
|
parser = argparse.ArgumentParser(description='Log kiln data for analysis.')
|
||||||
parser.add_argument('--hostname', type=str, default="localhost:8081", help="The kiln-controller hostname:port")
|
parser.add_argument('--hostname', type=str, default="localhost:8081", help="The kiln-controller hostname:port")
|
||||||
parser.add_argument('--csvfile', type=str, default="/tmp/kilnstats.csv", help="Where to write the kiln stats to")
|
# parser.add_argument('--csvfile', type=str, default="/tmp/kilnstats.csv", help="Where to write the kiln stats to")
|
||||||
|
parser.add_argument('--csvfile', type=str, default=f"/tmp/kilnstats-{datetime.today().strftime("%Y_%m_%d-%I_%M")}.csv", help="Where to write the kiln stats to")
|
||||||
parser.add_argument('--pidstats', action='store_true', help="Include PID stats")
|
parser.add_argument('--pidstats', action='store_true', help="Include PID stats")
|
||||||
parser.add_argument('--noprofilestats', action='store_true', help="Do not store profile stats (default is to store them)")
|
parser.add_argument('--noprofilestats', action='store_true', help="Do not store profile stats (default is to store them)")
|
||||||
parser.add_argument('--stdout', action='store_true', help="Also print to stdout")
|
parser.add_argument('--stdout', action='store_true', help="Also print to stdout")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue