Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8026

Beginners • Re: Running a program on start up and after connecting to the internet

$
0
0
I have a simple example I am trying to test it with, so I have the crontab calling a simple script that would blink an LED on and off when the raspberry pi connects to the internet after startup. However, it only works when I manually initiate the script not when I call it on the reboot in the crontab @reboot. However, my script does work on reboot with crontab if I don't ping the network first.
Here is the line of code in crontab

Code:

@reboot python3 /home/pi/Documents/MBTAtests/StartupTest.py @
Here is the "StartupTest.py" script it is calling

Code:

#!/usr/bin/env python3import requestsimport timeimport gpiozeroled = gpiozero.LED(4)while True:response = requests.get('http://google.com')value = response.status_codeprint(response.status_code)if value == 200:led.on()time.sleep(1)led.off()time.sleep(1)
What am I missing?

Statistics: Posted by deri9928 — Mon Sep 30, 2024 3:34 am



Viewing all articles
Browse latest Browse all 8026

Trending Articles