diff --git a/pevNoGui.py b/pevNoGui.py new file mode 100755 index 0000000..254c02c --- /dev/null +++ b/pevNoGui.py @@ -0,0 +1,33 @@ + +# The non-GUI variant of the PEV side + +import time +import pyPlcWorker +from pyPlcModes import * +import sys # for argv + +def cbAddToTrace(s): + print(s) + +def cbShowStatus(s, selection=""): + pass + +myMode = C_PEV_MODE + +isSimulationMode=0 +if (len(sys.argv) > 1): + if (sys.argv[1] == "S"): + isSimulationMode=1 + +print("starting in PEV_MODE") +print("press Ctrl-C to exit") + +worker=pyPlcWorker.pyPlcWorker(cbAddToTrace, cbShowStatus, myMode, isSimulationMode) + +nMainloops=0 +while (1): + time.sleep(.03) # 'do some calculation' + nMainloops+=1 + worker.mainfunction() + +#--------------------------------------------------------------- diff --git a/starter.py b/starter.py new file mode 100755 index 0000000..ce6c3b3 --- /dev/null +++ b/starter.py @@ -0,0 +1,83 @@ + +# https://noisefloor-net.blogspot.com/2015/10/systemd-timer-unter-raspbian.html +# In /etc/systemd/system we need to create 2 files: +# pevStarter.service +# pevStarter.timer +# cd /etc/systemd/system +# sudo nano pevStarter.service +# ... add content... +# sudo nano pevStarter.timer +# ... add content ... +# Make executable: +# sudo chmod +x pevStarter.* +# start and enable the unit: +# sudo systemctl start pevStarter.timer +# sudo systemctl enable pevStarter.timer + +# https://gist.github.com/emxsys/a507f3cad928e66f6410e7ac28e2990f + +# View log: +# journalctl --unit=pevStarter + +# sudo systemctl status pevStarter + +import subprocess +import datetime +from time import sleep + + +def writeStartLog(): + file_object = open('/home/pi/myprogs/pyPlc/starterlog.txt', 'a') + now = datetime.datetime.now() + s = str(now) + file_object.write("starter was started at " + s + "\n") + file_object.close() + +def checking(): + file_object = open('/home/pi/myprogs/pyPlc/starterlog.txt', 'a') + #file_object.write('hello\n') + now = datetime.datetime.now() + s = str(now) + file_object.write("It is " + s + "\n") + + command = "ps" + param1 = "axj" + result = subprocess.run( + [command, param1], capture_output=True, text=True) + + if (len(result.stderr)>0): + strOut = "Error:" + result.stderr + "\n" + else: + strOut = result.stdout + + blRunning=False + lines = strOut.split("\n") + for line in lines: + if (line.find("pevNoGui.py")>0): + blRunning = True + + if (blRunning): + file_object.write("its running\n") + else: + file_object.write("its NOT running. Trying to start...\n") + #processvar = subprocess.Popen(["python", "/home/pi/myprogs/pyPlc/pevNoGui.py"]) + result = subprocess.run(["python", "/home/pi/myprogs/pyPlc/pevNoGui.py"]) + if (len(result.stderr)>0): + strOut = "Error:" + result.stderr + "\n" + else: + strOut = "" + strOut = "done\n" + file_object.write(strOut) + + file_object.close() + + +try: + writeStartLog() + while True: + #print("Hello World") + checking() + sleep(10) +except KeyboardInterrupt as e: + print("Stopping...") + \ No newline at end of file diff --git a/starter.sh b/starter.sh new file mode 100755 index 0000000..1d17d3a --- /dev/null +++ b/starter.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +date >> /home/pi/myprogs/pyPlc/test2.txt +pwd >> /home/pi/myprogs/pyPlc/test2.txt +cd /home/pi/myprogs/pyPlc/ +/usr/bin/python /home/pi/myprogs/pyPlc/starter.py +pwd >> /home/pi/myprogs/pyPlc/test2.txt +date >> /home/pi/myprogs/pyPlc/test3.txt