diff --git a/.gitignore b/.gitignore index 47042f4..7735a4f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ epd_4in2_test.py __pycache__/ lib/ img/Font.ttc +*.log diff --git a/README.md b/README.md index 069a7d3..5078e0f 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ \- **\_\_pycache\_\_/** - aint nobody got time for compiled python binaries. \- **lib/** - library files from waveshare, available on their github page. \- **img/Font.ttc** - font file provided by waveshare, available on their github page. +\- **\*.log** - nobody needs the log files in their repo **ePaper Pins:** diff --git a/octomonitor.py b/octomonitor.py index 3032537..6e529b4 100644 --- a/octomonitor.py +++ b/octomonitor.py @@ -24,7 +24,7 @@ libdir = "/home/pi/epaper/lib"#os.path.join(os.path.dirname(os.path.dirname(os.p if os.path.exists(libdir): sys.path.append(libdir) -import logging +import logging,logging.handlers from waveshare_epd import epd4in2 import time from PIL import Image,ImageDraw,ImageFont @@ -36,6 +36,11 @@ requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) logging.basicConfig(level=logging.DEBUG) #logging.basicConfig(level=logging.INFO) +logger=logging.getLogger('octopimonitor') +formatter=logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', '%Y-%m-%d %H:%M:%S', style='{') +handler=logging.handlers.RotatingFileHandler(filename='octopimonitor.log', encoding='utf-8', maxBytes=32*1024*1024, backupCount=5) +handler.setFormatter(formatter) +logger.addHandler(handler) def timestr(time): return f"{datestr(time)} {time.hour:02}:{time.minute:02}" diff --git a/octomonitor.service b/octomonitor.service new file mode 100644 index 0000000..287a79e --- /dev/null +++ b/octomonitor.service @@ -0,0 +1,24 @@ +# Adjust the paths below as necessary +# (WorkingDirectory & ExecStart) +# Copy this file to /etc/systemd/system/ +# Run 'sudo systemctl daemon-reload' +# Now you can 'sudo systemctl [start|stop|reload] octomonitor' +# Run 'sudo systemctl enable octomonitor' if +# you want the service to start on boot + +[Unit] +Description=Octopi ePaper Monitor +After=syslog.target +After=network.target + +[Service] +RestartSec=30s +Type=simple +User=pi +Group=pi +WorkingDirectory=/home/pi/epaper/ +ExecStart=/usr/bin/python3 /home/pi/epaper/octomonitor.py +Restart=on-failure + +[Install] +WantedBy=multi-user.target