Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions COPYING

This file was deleted.

8 changes: 4 additions & 4 deletions gpl.txt → LICENSE
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

Expand All @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
55 changes: 55 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# OTA Wifi Configuration

OTA Wifi Configuration is a program to headlessly configure a Raspberry Pi's WiFi
connection using using any other WiFi-enabled device (much like the way
a Chromecast or similar device can be configured).

### OTA Wifi Configuration has been tested with

- Raspberry Pi 4b Running Raspberry Pi Os Buster Lite

### OTA Wifi Configuration should work with

- Any rasberry Pi running Raspberry Pi Os Buster or Bullseye

## Installation Instructions:

- Navigate to the directory where you downloaded or cloned OTA Wifi Configuration

- Run: `sudo python3 setup.py`, **Must be run with sudo or as root**

- This script will install all necessary prerequisites and copy all necessary
config and library files, then reboot.
- Wait for it to finish booting then go back to the directory that you cloned or downloaded OTA Wifi Configuration and run `sudo python3 app.py`
- It should
present itself in _Configuration Mode_ as a WiFi access point with the
name **Device [xxxx]**. The Xs being replaced with the last four digits of your raspberry pi's serial number.

## Usage:

- Connect to the **Device [xxxx]** access point using any other WiFi enabled
device.

- Make an http request to [**192.168.50.10**] or [**setup.com**] on port 5000

## Api:

### **/connected** - Attempts to set the wifi on the device. It will set the credentials then restart the device. Will return a 200 status code if succeeded.

- **Params** - The params must be passed in as JSON data. Mimetype must indicate JSON (application/json).
- **SSID** - String - The ssid of the wifi you wish to connect to.
- **wifi_key** - String - The wpa key of the wifi you wish to connect to.
- **Returns** - **{"status": "success", "status_code": 200}** if succeeded or **{"status": "failed", "status_code": 500}** if failed

### **/save_credentials** - will return a 200 status code if succeeded.

- **Params** - None
- **Returns** - {"status_code": 200}

## Resetting the device:

### You can reset the device by running setup.py again as root or with sudo.

## Stopping access point

## You can disable the access point by running disable_access_point.py as root or with sudo.
142 changes: 0 additions & 142 deletions Readme.txt

This file was deleted.

62 changes: 62 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from flask import Flask, render_template, request
import subprocess
import os
import time
from threading import Thread
from disable_access_point import disable_access_point
import fileinput

app = Flask(__name__)
app.debug = True


def set_wifi_credentials(ssid, password):
try:
config_lines = [
"country=US", # Replace 'US' with the appropriate country code for your region
"ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev",
"update_config=1",
"",
"network={",
f'\tssid="{ssid}"',
"\tscan_ssid=1",
f'\tpsk="{password}"',
"\tkey_mgmt=WPA-PSK",
"}",
]

# Join the configuration lines into a single string
config_data = "\n".join(config_lines)

# Write the configuration to the wpa_supplicant file
with open("/etc/wpa_supplicant/wpa_supplicant.conf", "w") as wpafile:
wpafile.write(config_data)

t = Thread(target=disable_access_point)
t.start()

return True
except Exception as e:
print(e)
return False


@app.route("/save_credentials", methods=["GET", "POST"])
def save_credentials():
ssid = request.json["ssid"]
wifi_key = request.json["wifi_key"]

if set_wifi_credentials(ssid, wifi_key):
return {"status": "success", "status_code": 200}
else:
return {"status": "failed", "status_code": 500}


@app.route("/connected", methods=["GET", "POST"])
def conncected():
response = {"status_code": 200}
return response


def run_api():
app.run(host="0.0.0.0", port=5000)
11 changes: 11 additions & 0 deletions disable_access_point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os


def disable_access_point():
os.system("systemctl disable dnsmasq")
os.system("systemctl disableg hostapd")

os.system("sudo cp /etc/dnsmasq.conf.copy /etc/dnsmasq.conf")
os.system("sudo cp /etc/dhcpcd.conf.copy /etc/dhcpcd.conf")

os.system("reboot")
66 changes: 0 additions & 66 deletions initial_setup.py

This file was deleted.

Loading