0

I am using Raspberry Pi 2 to a telosB base station to collect data from other sensors. I receive (on the terminal) hex data and redirect these incoming data into a python script which will clean and upload to mysql.

Manually (steps i take to do the task:)

  1. source ~/.bashrc
  2. source ~/.tinyos.sh
  3. java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB:telosb | python data-manager.py

I want the raspberry pi2 (running on Rasbian) to do these steps on boot immediately.

I have tried using the update-rc.d method and the crontab method both of which do not work. I think it is because of the arguments in my command that are not going through.

Thanks!

1

Make one script that does it all (.sh) and setup cron job starting with @reboot instead of times. You probably have to do that on root user (sudo -s). I would rather use full path /home/pi (?) instead of ~ and . instead of source.

To make it persistant, use screen:

sudo apt-get install screen

and add to crontab something like this:

@reboot screen -d my_autorun /home/pi/autorun.sh <-- my_autorun is a name, can be whatever


Edit (2):

Look... you are doing it wrong, and I don't have enough space in comment...

You need to create new file, lets say autorun.sh:

Run cat > autorun.sh paste those lines to it:

cd /home/pi
./home/pi/.bashrc
./home/pi/.tinyos.sh
java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB:telosb | python data-manager.py

... and hit CTRL+C to save it.

Then run: chmod 777 autorun.sh

I think that to be able to listen on that serial port, you need root rights so... run: sudo -s

Next run: crontab -e

And finally add the line @reboot screen -d my_autorun /home/pi/autorun.sh, hit CTRL+X and press Y to save.

That should be it.

| improve this answer | |
  • forgot to mention it has to run persistently on the background as it keeps listening to the serial port. – Don Bhrayan Singh Feb 13 '16 at 19:11
  • edited, so it would act like daemon – Flash Thunder Feb 15 '16 at 10:17
  • Apologies, i tried: @reboot . /home/pi/.bashrc @reboot . /home/pi/.tinyos.sh @reboot screen -d testscr /home/pi/script.sh But as soon as I restart and do 'ps fax' or 'pgrep testscr' nothing comes up – Don Bhrayan Singh Feb 16 '16 at 15:36
  • you are doing it wrong... please check latest edit... if it won't work, I can't help you, as you need basic unix knowledge and this is wrong forum for it – Flash Thunder Feb 16 '16 at 17:52
  • I did exactly as you said it. When I run ps aux or pgrep 'my_autorun' process isn't there. Checked my db, no data insertions made. – Don Bhrayan Singh Feb 17 '16 at 4:10

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.