I am doing a project for which I need to make an LED ON when a device connects with Raspberry Pi. Raspberry Pi will act as access point and will provide network to other devices. I found a example on Raspberry Pi forum but this is different. I tried it also (after making some changes) when Raspberry Pi connects with the access point but it didn't work. Please help!
EDIT: It worked now, I was doing wrong first. Now how can I change it to make it work when Raspberry Pi act as access point and turn ON an LED when a device connects with it? I followed this guide to make raspberry pi access point.
I have connected an LED with GPIO17. I wrote a simple Python script and name it wifiLED.py:
#!/bin/env python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, True)
I put this script into following bash script wifi_LED.sh. I found my gateway address by $route -n
:
#!/bin/bash
# ping the gateway address
/bin/ping -q -c 192.168.0.1 > /dev/null
if [ $? -eq 0 ]
then
echo "Network active"
sudo python /home/pi/wifiLED.py
else
echo "Network down"
fi
When I do sh wifi_LED.sh
, it turn ON LED connected with GPIO17.