1

(Currently using Raspbian Jessie latest)

So currently I am trying to start a script that reads from the rf receiver and gathers the data and sends it over to the cloud...

I am trying to start this script on every boot of the Raspberry Pi 2 B+, however, the problem I am running into is this...

serial.SerialException.../dev/ttyUSB0 cannot find file or directory (doesn't exist)... something along these lines is the error code.

I have tried to run the script on boot via the systemmd following this guide... http://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/

However it returns me an error in the log files like the one above...so I suspect that the script cannot run because a) the usb isn't ready yet (b) not enough power for usb ports? (cause I have also been getting this warning on boot recently saying usb current overcharge on port 0 or something..)

I have also tried crontab where the command I ran was..

@reboot python /home/pi/RFThingSpeak.py & 

to no success... (I suspect the same error)

So is there a specific way that ACTUALLY WORKS for my case on starting a script on boot for Raspberry Pi?

Or is there a way where after the boot is complete, the script THEN runs automatically everytime? (So once the raspberry pi is ready for use it THEN runs the script automatically)

I really need this script to work on boot/ after boot as I will have my raspberry pi out on the field without a screen nor any connection to it due to the fact that it will be connected to the internet via 3G USB Dongle.

Thanks in advance!

Ingo
  • 42,961
  • 20
  • 87
  • 207

1 Answers1

0

I suggest add a sleep 10 or sleep 20 in your crontab and then try rebooting the Pi

for instance,

 @reboot sleep 20; /usr/bin/python /home/pi/RFThingSpeak.py &

This took me more than 6 months to figure out. Most of the /dev/ may not be ready when you reboot. but adding a sleep should most definitely do your work.

I asked a similar problem on This Thread on Linux & Unix and have seen many similar boot related problems on StackOverflow which also suggest using sleep or wait before triggering your script viz. for SQL, Python related boot scripts.

Shan-Desai
  • 1,541
  • 2
  • 13
  • 28