How to start my own script at the end of boot on Nano?

Hi,
I am trying to run my own python script at startup. Or more specifically at the END of the boot sequence
The python code does
a) writes to the I2C LCD screen
b) announces via sound that its ‘Ready’
When tested in a normal session this all works.

I tried, and suceeded, in creating a systemd service for this. The issue is that it runs too early - the screen is written to but the sound does not play.
My guess is this would need an ‘After’ directive in the service setup but I have no idea what to schedule it ‘After’
Asking systemd for info yields a list of either 258 or 360 things its looking after - no help really.
I tried adding After=sound.target but that didn’t help
So, is there a generic ‘when-you-have-finished-all-your-stuff’ thing that I could use to trigger my ‘user’ needs after all the ‘system’ needs ?

[Unit]
After=sound.target
Description=Execute this on boot

[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/jc/jcCode/at_start_pyscript.py

[Install]
WantedBy=multi-user.target

Thanks
JC

hello jc5p,

what’s your expectation for running your script file, how about having it executed after PHS daemon?
please check /etc/systemd/system/nvphs.service, this service executed after pre-boot scripts complete.

Jerry,
Thanks for the response. I tried your suggestion re nvphs.service but it didn’t make a difference. There are wierd things with the sound. I am trying to use a USB sound dongle thingie (Unitek Y-247A) and I have found that sometimes it wont produce anything the 1st few times its called. At the moment it has a monitor so I changed to HDMI sound with no more success. The expectation is that there is some point in the boot process when all the drivers are loaded and ‘warmed up’ and I can go after that. The LCD screen seems to be written to whatever I schedule it after so I assume I2C start early. And to get the next question in too. I will want to clear the LCD screen when the unit is turned off; at the moment it just shows the last message for ever. So I will be looking for another trigger - a ‘Before’ I suspect.

hello jc5p,

is this USB sound dongle always connected to the target before booting-up, can linux kernel recognize this device?

you may also refer to the kernel messages, display driver will putting monitor power-down after a while.

[   19.593759] tegradc tegradc.0: unblank
[   19.593958] tegradc tegradc.1: blank - powerdown

Jerry,
Yes the USB thing is always connected. I am not sure what you mean by ’ linux kernel recognize this device’. Certainly once its booted the device is shown in the sound settings; it can play mp3 things etc. I only mentioned the HDMI monitor speakers as an attempt to isolate whether I had an issue with the USB device or the timing of my startup script so the monitor going to sleep will not be an issue. (As soon as all this stuff works it will become a headless mobile platform)

Jerry - more thanks
I learnt some more :) These are the entries in the log from dmesg which would say the usb sound device is known to the kernel

[    2.761569] usb 1-2.3: New USB device found, idVendor=0d8c, idProduct=0014
[    2.761576] usb 1-2.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[    2.761581] usb 1-2.3: Product: USB Audio Device
[    2.761585] usb 1-2.3: Manufacturer: C-Media Electronics Inc.
[    2.782752] input: C-Media Electronics Inc. USB Audio Device as /devices/70090000.xusb/usb1/1-2/1-2.3/1-2.3:1.3/0003:0D8C:0014.0004/input/input2
[    2.839417] hid-generic 0003:0D8C:0014.0004: input,hidraw0: USB HID v1.00 Device [C-Media Electronics Inc. USB Audio Device] on usb-70090000.xusb-2.3/input3

although the device has both Mic input socket and a Headphone output socket and I dont know how to tell those apart in this log.

Also the final lines in the dmesg log are

[   31.862144] vdd-fan: disabling
[   31.862149] vdd-usb-vbus: disabling
[   31.862151] vdd-usb-vbus2: disabling
[   31.862162] vddio-sdmmc3-ap: disabling
[   31.862234] avdd-io-edp-1v05: disabling
[   31.862237] vdd-usb-hub-en: disabling

I hope this doesn’t mean all these things are turned off at boot !

Thanks again
JC

Hello,

What is the current status? The systemd service is not able to run the script?

I don’t think you need to worry about kernel log here. They are always there no matter the existence of your system service.

Partially correct; The systemd service can run the script (as evidenced by text on the LCD screen) however no sound is produced. Many ‘After’ clauses have been tried.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.