PiFi Controller - Pi Hotspot Control Using Cayenne App

3,217

63

2

Introduction: PiFi Controller - Pi Hotspot Control Using Cayenne App

About: Rahman hira kab kahe lakh taka mo mol :)

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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()

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    2 Discussions

    0
    Swansong
    Swansong

    3 years ago

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

    0
    praju1
    praju1

    Reply 3 years ago

    Thanks :)