I was able to follow successfully the suggestion in the link you provided.
However when I tried to run my python script nothing appears to have happened. Maybe it is because mine is a command line application so I may need to add other stuff to get it to work.
As far as I remember, Python's stdin and stdout behave far from obvious when scripts are being executed by cron and/or service. I use printing to file for debugging 'silent' scripts.
I wish you could format the .service as code so it is easily readable. I don't have a BPI to test but can you share the python code (ECU.py)? I assume python3 is under /bin but in most systems python3 is under /usr/bin/
[Unit]
Description=example systemd service unit file.
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/usr/bin/python3 ECU.py
[Install]
WantedBy=multi-user.target
I am sorry I did not format the .service as code. I need to understand how to do this on this forum and will do so in the future. However note that what I posted was simply a cut and paste from the link provided by @ugnvs.
I can of course provide you with the code in my script but I fear it will probably confuse the issue more than help resolve it. My script is in fact a rewrite of a working script which I had written for the original rasperberry pi installed with TinyCore linux. It is a fairly lengthy piece of code and the current conversion is still not completely debugged.
Basically it picks up data coming in on the "rs232" gpio pin from a motorbike ECU, parses it and stores it in a .csv file for eventual offline analysis. Whilst running it sends some comments to a command line screen (if connected) but when on the bike a flashing led indicates that the script is still running and not stalled.
Where can I find how to properly attach code on this forum?
On reply, select the text you want to format and click on the 6th icon </> it will format the text as code (monospace) and thus easily readable.
I don't really want the script, I want to make sure it runs properly under systemd. You described what it does, my only suggestion is to use the command journalctl -xe to find out what's going on with the execution.
In order to ensure that the failure to startup is not due to some bugs in my own code I created the following simple script which basically blinks an LED and also sends periodically some messages to the command line screen.
This was then placed in a test.service file.
At start up systemd invokes this command successfully since blinking starts taking place even before the Ubuntu MATE GUI comes up. At the left of the bottom status bar a message is displayed stating that Python3.8 is running. This eventually turns off.
However the messages in my code which I am sending to the command line screen do not appear and also I cannot do Cntrl+C to terminate my script.
It seems the issue is therefore of how to automatically open a terminal screen and how to direct my messages to this.
import RPi.GPIO as GPIO
import time
phyledpin = 11 # pin13, bcm27
def setup_board():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(phyledpin, GPIO.OUT)
def blink_board():
while True:
GPIO.output(phyledpin, GPIO.HIGH)
print("********set phy pin ", phyledpin, " High********")
time.sleep(0.5)
GPIO.output(phyledpin, GPIO.LOW)
print("********set phy pin ", phyledpin, " Low********")
time.sleep(0.5)
def shutdown():
GPIO.cleanup()
if __name__ == '__main__': # Program start
print('LED flashes at 0.5s interval')
print('Press Ctrl-C to exit')
setup_board()
print("Hardware information: ", GPIO.RPI_INFO)
try:
blink_board()
except KeyboardInterrupt:
shutdown()