mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-20 01:13:58 +00:00
PEV no-GUI version with autostart on Raspberry
This commit is contained in:
parent
a469c5a6e1
commit
97d8a3435b
3 changed files with 124 additions and 0 deletions
33
pevNoGui.py
Executable file
33
pevNoGui.py
Executable file
|
@ -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()
|
||||
|
||||
#---------------------------------------------------------------
|
83
starter.py
Executable file
83
starter.py
Executable file
|
@ -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...")
|
||||
|
8
starter.sh
Executable file
8
starter.sh
Executable file
|
@ -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
|
Loading…
Reference in a new issue