User avatar
Mettauk
Posts: 234
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Auto run a python script at boot inc BT connection

Wed Nov 09, 2016 4:28 pm

I followed the instructions at http://www.raspberrypi-spy.co.uk/2015/1 ... g-systemd/ and it starts at boot but seems to get stuck at the beginning.

It starts the python script at the end of booting which loads i2c connected hardware (motor controllers) but seems to stop at the point where the script searches for and waits for a Bluetooth connection to a remote control.

Code: Select all

[Unit]
Description=My Script Service
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/python /home/pi/MBORG/mower02.py > /home/pi/mower02.log 2>&1

[Install]
WantedBy=multi-user.target
the screen output shows the motors being found as

Code: Select all

Nov 09 16:16:57 Mower2 systemd[1]: Starting My Script Service...
Nov 09 16:16:57 Mower2 systemd[1]: Started My Script Service.
Nov 09 16:16:58 Mower2 python[867]: Loading PicoBorg Reverse on bus 1, address 0A
Nov 09 16:16:58 Mower2 python[867]: Found PicoBorg Reverse at 0A
Nov 09 16:16:58 Mower2 python[867]: PicoBorg Reverse loaded on bus 1
Nov 09 16:16:58 Mower2 python[867]: Loading PicoBorg Reverse on bus 1, address 0B
Nov 09 16:16:58 Mower2 python[867]: Found PicoBorg Reverse at 0B
Nov 09 16:16:58 Mower2 python[867]: PicoBorg Reverse loaded on bus 1
If I run the code manually I get

Code: Select all

$ sudo python mower02.py
Loading PicoBorg Reverse on bus 1, address 0A
Found PicoBorg Reverse at 0A
PicoBorg Reverse loaded on bus 1
Loading PicoBorg Reverse on bus 1, address 0B
Found PicoBorg Reverse at 0B
PicoBorg Reverse loaded on bus 1
Waiting for joystick... (press CTRL+C to abort)
Joystick found
Press CTRL+C to quit
and it runs just fine
Last edited by Mettauk on Fri Nov 11, 2016 9:37 am, edited 3 times in total.
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
Douglas6
Posts: 4710
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Auto run a python script at boot inc BT item

Wed Nov 09, 2016 4:43 pm

Your systemd unit looks odd to me; with both 'After=multi-user.target' and 'Wanted-by=multi-user.target'. I would try replacing the first 'After=' with

Code: Select all

After=bluetooth.service
Requires=bluetooth.service

User avatar
Mettauk
Posts: 234
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: Auto run a python script at boot inc BT item

Wed Nov 09, 2016 5:13 pm

Tried that...

Code: Select all

[Unit]
Description=My Script Service
#After=multi-user.target
After=bluetooth.service
Requires=bluetooth.service

[Service]
Type=idle
ExecStart=/usr/bin/python /home/pi/MBORG/mower02.py > /home/pi/mower02.log 2>&1

[Install]
WantedBy=multi-user.target
seems to make no difference? Does it need some sort of time delay for the Bluetooth connection to establish (I press a button on the BT remote to enable the remote control?
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
Douglas6
Posts: 4710
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Auto run a python script at boot inc BT item

Wed Nov 09, 2016 7:12 pm

Well. It was worth a shot. Perhaps your Python script is timing out before you're ready to connect. I'd check the results of

Code: Select all

systemctl status <yourscript>
and check the systemd journal. You may need to adjust your Python script so that it loops trying to connect until successful.

User avatar
Mettauk
Posts: 234
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: Auto run a python script at boot inc BT item

Wed Nov 09, 2016 7:51 pm

When run manually the python script loops waiting for the Bluetooth connection. but it does not seem to run at start up. But the BT remote connects to the Pi OK but not to the script?

This is the ssh output post boot after running sudo systemctl status myscript.service

Code: Select all

$ sudo systemctl status myscript.service
â myscript.service - My Script Service
   Loaded: loaded (/lib/systemd/system/myscript.service; enabled)
   Active: inactive (dead) since Wed 2016-11-09 20:06:32 GMT; 58s ago
  Process: 721 ExecStart=/usr/bin/python /home/pi/MBORG/mower02.py > /home/pi/mower02.log 2>&1 (code=killed, signal=HUP)
 Main PID: 721 (code=killed, signal=HUP)

Nov 09 20:06:26 Mower2 systemd[1]: Started My Script Service.
Nov 09 20:06:32 Mower2 python[721]: Loading PicoBorg Reverse on bus 1, address 0A
Nov 09 20:06:32 Mower2 python[721]: Found PicoBorg Reverse at 0A
Nov 09 20:06:32 Mower2 python[721]: PicoBorg Reverse loaded on bus 1
Nov 09 20:06:32 Mower2 python[721]: Loading PicoBorg Reverse on bus 1, address 0B
Nov 09 20:06:32 Mower2 python[721]: Found PicoBorg Reverse at 0B
Nov 09 20:06:32 Mower2 python[721]: PicoBorg Reverse loaded on bus 1
pi@Mower2:~ $
Last edited by Mettauk on Fri Nov 11, 2016 9:36 am, edited 1 time in total.
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
Mettauk
Posts: 234
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: Auto run a python script at boot inc BT item

Fri Nov 11, 2016 9:35 am

Bump?
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

Return to “Troubleshooting”