I am working on creating a python script to retrieve data from a server using the requests library, and then display it on an adafruit led matrix using a raspberry pi. I have a program that functions as expected when called from the terminal. However, I want the program to start running immediately whenever the pi boots up. So I added it to the crontab with @reboot
in front of it. However, when upon reboot, the program runs for only a split second, then stops. I have narrowed the issue down and I know which line causes it. Here is the method with the error-causing line:
#THIS IS THE PROBLEM
request = requests.get('http://jacob-t-graham.com/led-data') #make a request to the led data page of the site
#THIS IS THE PROBLEM
print(f'Request returned status code {request.status_code}.')
raw_string=request.text #get the raw text from the request
color_ls=raw_string.split(',') #split the string around commas
ls_of_lss=[color_ls[x:x+self.cols] for x in range(0, len(color_ls), self.cols)] #split the list into lists of the appropriate size
#print(ls_of_lss)
return ls_of_lss
The line that calls the requests.get method is what causes the problem. If I comment that line and reboot, the program runs as expected. However, the strange part is, when I try to capture error output from the program when that line is in, nothing about the error shows up in the log file. Again, this code runs fine with the error-causing line when run using a terminal. So, how can I get this program to run on boot via the crontab?
@reboot (sleep 30; your_command)
to see if a short delay helps.