0

(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!

  • Are we supposed to guess what is in the files you created? – Milliways Aug 4 '16 at 12:10
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.

  • BTW there is no need for the & with any reasonable implementation of crond. – Ghanima Aug 4 '16 at 12:11
  • that is if the script wouldn't print anything on the stdout buffer, isn't it? – Shan-Desai Aug 4 '16 at 12:13
  • I have tried sleep 10 before I think, maybe it wasn't long enough? I'll try sleep 20. Thanks for the answer! – FuriousPudding Aug 4 '16 at 12:15
  • 1
    No it got nothing to do with stdout but this: stackoverflow.com/q/10503433/3984613 – Ghanima Aug 4 '16 at 12:46
  • 1
    @Shan-Desai well then it seems that one of Goldilock's rampages is in order. – Ghanima Aug 4 '16 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.