Code: Select all
#!/bin/bash
# ping the gateway address
/bin/ping -q -c1 192.168.1.254 > /dev/null
if [ $? -eq 0 ]
then
echo "Network active"
# stuff to do when the network is active goes here ...
else
echo "Network down"
# stuff to do when the network is down goes here ...
fi
Code: Select all
#!/bin/sh -e
# Called when a new interface comes up
# don't bother doing anything when lo is configured.
if [ "$IFACE" = "lo" ]; then
exit 0
fi
# stuff to do when the network comes up active goes here ...
exit 0
Code: Select all
def getwpaclientstatus():
import subprocess
try:
writedatedlogmsg(networklog, 'Attempting WPA client status read. ', 4, networkloglevel)
result = subprocess.Popen(['/sbin/wpa_cli', 'status'], stdout=subprocess.PIPE)
except:
writedatedlogmsg(networklog, 'Error reading wpa client status. ', 0, networkloglevel)
else:
writedatedlogmsg(networklog, 'Completed WPA client status read. ', 4, networkloglevel)
# prune interface ID
resultdict = {}
for result in result.stdout:
if result.find('=') > 0:
split = result.split('=')
resultdict[split[0]] = split[1].strip()
return resultdict
In the above examples no GPIO outputs have been set up, so its down to you to set up your GPIO to work with which ever pins you wish.Bbuschke wrote:What pins on the gpio do I connect the led to after the script is set up
Code: Select all
#!/bin/bash
echo "18" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio18/direction
/bin/ping -q -c1 192.168.1.1 > /dev/null
if [ $? -eq 0 ]
then
echo "$? network up"
# Sets pin 18 to high
echo "1" > /sys/class/gpio/gpio18/value
else
echo "$? network down"
# Sets pin 18 to low
echo "0" > /sys/class/gpio/gpio18/value
fi
Code: Select all
*/5 * * * * /home/pi/cnw.sh >/home/pi/log.txt 2>&1
Code: Select all
*/5 * * * * /home/pi/cnw.sh >/dev/null 2>&1
Code: Select all
echo "18" > /sys/class/gpio/export
Code: Select all
[ -L /sys/class/gpio/gpio18 ] || echo "18" > /sys/class/gpio/export
Thanks always willing to learn some thing new..FM81 wrote:May be, you can change thisto thisCode: Select all
echo "18" > /sys/class/gpio/export
and you will get no error on second (or third ...) execution.Code: Select all
[ -L /sys/class/gpio/gpio18 ] || echo "18" > /sys/class/gpio/export
Greetings, FM_81
The formula for working out resistors for LEDs is fairly simple. There are even lots of calculators online for it.Bbuschke wrote:Ok. I think I have the coding down. Now if I find a 3v led but the gpio is sending 3.3v I need a resistor correct? What size resistor?
No need to find a 3v LED just use a regular LED red,green or yellow which have a forward voltage around 1.5 -2.0v and a 330ohm or 470ohm resistor and it will work just fine.Bbuschke wrote:Ok. I think I have the coding down. Now if I find a 3v led but the gpio is sending 3.3v I need a resistor correct? What size resistor?
This may or may not be the topic that is causing you to get lost, but I think it is bad advice to use "sudo crontab -e".Bbuschke wrote:i got up to the creating the script and im lost at the Cron thing
Bbuschke wrote:Yeah I'm lost. Think I need to find a step by step tutorial. I appreciate the help but I'm very new to all this. I don't have any knowledge in coding and stuff. I don't expect you guys to make a tutorial for me. I will try to research this some more
Wrong.if you start putting sudo in your cron entries you will have problems.
Hi.Bbuschke wrote:Script named wifi_led.py
Located in
/home/pi/scripts/wifi_led.py
I really appreciate the help
Ok no problem.Bbuschke wrote:Saved same place and file name but bash now.
/home/pi/scripts/wifi_led.sh
I just used your script example. I don't know if it self loops
I want it to stay on at all times when Connected to a network
Code: Select all
chmod +x /home/pi/scripts/wifi_led.sh
Code: Select all
sudo crontab -e
Code: Select all
*/3 * * * * /home/pi/scripts/wifi_led.sh >/dev/null 2>&1
Bbuschke wrote:i get this when making script excutable
chmod: changing permissions of ‘/home/pi/scripts/wifi_led.sh’: Operation not permitted
Code: Select all
cd scripts
Code: Select all
ls -l