Bari Tala
Bari Tala

Reputation: 57

Running Pi headless with boot-up script

I am trying to run a headless Raspberry Pi, working as a voice-activated servo-motor mover. I have a Python script that does everything I need (voice and GPIO control). All I need is to get it to run my .py on boot. I have a Raspberry Pi 3, running Raspbian Jessie.

Things I've tried so far:

edited /etc/rc.local as below:

/usr/bin/python /home/pi/myscript.py 

before the exit 0 line.

I've edited crontab with:

@reboot /usr/bin/python3 /home/pi/myscript.py & 

I have also tried

@reboot sh /home/launcher.sh 

where launcher.sh just launches the Python script.

Is there anything else I can do?

EDIT

I swapped the crontab line to look like this now:

@reboot sh /home/pi/launcher.sh > /home/pi/logs/cronlog 2>&1

and my cron log is getting errors that I've never seen before, that seem to center around my mic's hardware.

 Expression 'paInvalidSampleRate' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2048
 Expression 'PaAlsaStreamComponent_InitialConfigure( &self->capture, inParams, self->primeBuffers, hwParamsCapture, &realSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2719
 Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters,  sampleRate, framesPerBuffer, &inputLatency, &outputLatency,  &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line:   2843
Traceback (most recent call last):
   File "/home/pi/voice_pantilt.py", line 30, in <module>
    stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000,       input=True, frames_per_buffer=1024)
 File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 747, in open
   stream = Stream(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 442, in __init__
 self._stream = pa.open(**arguments)
IOError: [Errno Invalid sample rate] -9997`

Note that these aren't errors when I just do:

 python myscript.py

Upvotes: 0

Views: 794

Answers (1)

pmishev
pmishev

Reputation: 976

I had a very similar issue recently and after much debugging in the end it appeared to be a problem with PyAudio being denied access to PulseAudio when run via crontab.

The way I fixed it was by prefixing the command with export DISPLAY=:0 &&

export DISPLAY=:0 && /usr/bin/python /home/pi/myscript.py 

Upvotes: 1

Related Questions