please choosego to mobile | Continue to access the PC version
View: 10799|Reply: 4

[solved]launch script at startup

[Copy link]

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
Published in 2017-2-16 00:44:55 | Show all floors |Read mode
Edited by wwwlu at 2017-2-24 17:54

I use an arduino to shutdown (and start) my Orange Pi pc plus (on Lubuntu) by sending "stop" via the serial port
The following python script works fine when I launch it manually  (sudo python off.py)
#!/usr/bin/env python
# -*- coding: latin-1 -*-
import serial
import os
ser = serial.Serial('/dev/ttyS0', 9600)
while True :
        data = ser.readline()
        if "stop" in data:
                os.system('sudo shutdown -h now')


Now I try to execute this script automatically at startup

I entered the following line:
sudo python off.py
at the end of:
sudo nano /etc/profile

result:
Error found when loading /etc/profile:
sudo: no tty present and no askpass program specified
as a result the session will not be configured correctly
you should fix the problem as soon as feasible

It seems the serial port is not yet open when the script is executed

So I tried to launch the script via "default applications for LXSession" but the shutdown instruction requires to be super user (so it cannot be automatic)

In conclusion: before opening the session the serial port is closed, and after the script cannot shutdown the OPI

Anyone has a solution please ?

16

threads

104

posts

989

credits

Senior member

Rank: 4

credits
989
Published in 2017-2-16 03:00:01 | Show all floors
Hi, try to add the command to /etc/rc.local instead /etc/profile:

  1. exec python off.py
Copy code


than go in system -> preference -> personal -> startup applications and add the command

  1. sudo /etc/rc.local start
Copy code


This should works (i hope); in case, point the rc.local command to /path/to/off.py

Good luck
OrangePi A20, with Qbee-X_testing

Still waiting for refund/replacement of no working op+2e bought on 11/11 >_<...really serious company

10

threads

218

posts

2040

credits

Gold member

Rank: 6Rank: 6

credits
2040
Published in 2017-2-16 19:15:45 | Show all floors
You can make all programs a demon using Supervisor.

https://www.digitalocean.com/com ... untu-and-debian-vps

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
 Author| Published in 2017-2-16 19:43:49 | Show all floors
it works fine !!! excellent ! thanks a lot tokka

16

threads

104

posts

989

credits

Senior member

Rank: 4

credits
989
Published in 2017-2-16 21:59:46 | Show all floors
You'r welcome
OrangePi A20, with Qbee-X_testing

Still waiting for refund/replacement of no working op+2e bought on 11/11 >_<...really serious company
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list