Introduction: PiFi Controller - Pi Hotspot Control Using Cayenne App

During a community event, most of the time attendees want to have internet access. However it is useful to have internet access but it should be limited under some circumstances. Usually the speech sessions are very short and speaker wants the audience to listen to him. Switching off the WiFi access through a mobile app can be very much useful during the speech period and it can be switched-on as soon as the session is over.

Few days ago, I was working with setting up hostapd based AP (Access Point) on raspberry pi. Getting the idea of script based AP server control, I thought to control WiFi with one button interface. The idea is that one master user can switch-on and switch-off WiFi anytime through Cayenne UI and SSID will disappear from available list.

Step 1: Setup the WiFi Hotspot

First thing need to do is to setup the wifi hotspot.

Clear steps for setting up RPi3 WiFi access point is shows at following link. The steps will make internal WiFi (wlan0) as access point physical layer. However the external dongle generally connects to wlan1 (use ifconfig or iw command to check all WiFi related options). So, I made all modifications according to wlan1. However, my wlan1 (Tenda W311M) dongle doesn't support the mentioned driver in hostapd configuration and thus the script automatically switch the AP access MAC address to wlan0 as shown in figure.

Step 2: WiFi Switched-off in Default State

while True: # WiFi Hotstop turn-off condition if GPIO.input(inp)==0: subprocess.Popen('sudo service hostapd stop',shell=True) print "OFF" time.sleep(2)

Step 3: Switch-on WiFi With Click of a Button

# WiFi Hotstop turn-on condition if GPIO.input(inp)==1: subprocess.Popen('sudo service hostapd start',shell=True) print "ON" time.sleep(2)

Step 4: Source Code

import RPi.GPIO as GPIO import time import subprocess

# Pin declaration for input and output but = 20 inp = 21

# Configuration setup for input and output pins GPIO.setmode(GPIO.BCM) GPIO.setup(but, GPIO.OUT) GPIO.setup(inp, GPIO.IN)

try: while True: # WiFi Hotstop turn-off condition if GPIO.input(inp)==0: subprocess.Popen('sudo service hostapd stop',shell=True) print "OFF" time.sleep(2) # WiFi Hotstop turn-on condition if GPIO.input(inp)==1: subprocess.Popen('sudo service hostapd start',shell=True) print "ON" time.sleep(2)

except: print "WiFi control using Cayenne, BYE!!!" finally: GPIO.cleanup()

Comments

author
Swansong made it!(author)2016-10-29

There are a lot of professors that would love one of these :)

author
praju1 made it!(author)2016-10-30

Thanks :)

About This Instructable

2,815views

60favorites

License:

Bio: Rahman hira kab kahe lakh taka mo mol :)
More by praju1:PiFi Controller - Pi Hotspot Control Using Cayenne AppSitSat - my personal office chair sitting pattern monitor
Add instructable to: