Control wifi, hotspot and hostname of Raspberry Pi
Project description
rpi-networking
Control wifi, hotspot and hostname of Raspberry Pi
Requirments
Python3.10+
Installation
Using pip:
pip3 install rpi-networking
Using poetry
poetry add rpi-networking
Prepare system
Automatically
Via curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/MarkParker5/rpi-networking/master/setup.sh)"
Or via wget
sh -c "$(wget https://raw.githubusercontent.com/MarkParker5/rpi-networking/master/setup.sh -O -)"
Manually
Dependencies
sudo apt update ; \
sudo apt upgrade -y ; \
sudo apt install dnsmasq hostapd dhcpd -y
Give permissions to edit configuration files (optional)
Give user permission to edit configuration files so python doesn't have to be run as root (sudo)
files=(
"/etc/dnsmasq.conf"
"/etc/hosts"
"/etc/default/hostapd"
"/etc/hostapd/hostapd.conf"
"/etc/network/interfaces"
"/etc/network/interfaces.d"
"/etc/wpa_supplicant/wpa_supplicant.conf"
)
for file in "${files[@]}"; do
sudo chown "$USER" "$file"
sudo chmod 644 "$file"
done;
Docs
Configuration
There are functions for initial configuration setup.
# rpi_networking.configuraion
def write_interfaces():
def write_default_hostapd():
def write_hostapd_conf():
def write_dnsmasq_conf():
def write_wpa_supplicant(country: str = "GB"):
def write_hosts():
def write_all(): # calls all functions above
In most cases you only need to call write_all() once to setup all configuration files.
Hostname
# rpi_networking.hostname
def set_hostname(hostname: str):
def restart_interfaces(): # apply new hostname without reboot
Hotspot
# rpi_networking.hotspot
def is_hotspot_up() -> bool:
def start_hotspot() -> bool:
def stop_hotspot() -> bool:
The bool return value is True if function finished without errors (exit code 0), else False
Status
# rpi_networking.status
def is_wlan_connected() -> bool:
def is_eth_connected() -> bool:
def is_wlan_global_connected() -> bool: # 'global' means internet access
def is_eth_global_connected() -> bool:
def is_wps_running() -> bool:
WiFi
# rpi_networking.wifi
country: str = 'GB' # country code for wpa_supplicant
class InterfaceBusyException(Exception):
pass
class Cell:
ssid: str
quality: float
frequency: str
encrypted: bool
class Network:
ssid: str
psk: str
id_str: str
# Functions
def read_networks() -> list[Network]:
def write_networks(networks: list[Network]):
def add_network(ssid: str, psk: str):
def reconnect() -> bool: # connect to the best available network
def scan() -> Generator[Cell, None, None]:
def start_wps() -> bool:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rpi_networking-0.1.9.tar.gz.
File metadata
- Download URL: rpi_networking-0.1.9.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0350a924a2e977b27b2bf46e93e6e4e5e0ded55d5d453099bef4c5d2dd6db621
|
|
| MD5 |
19484138a02c4e3db1ed5112dbc38aa4
|
|
| BLAKE2b-256 |
f354d8e0695d9763c82d3827bb279cde9c2e098b817f3b1d3d2597d0da08100a
|
File details
Details for the file rpi_networking-0.1.9-py3-none-any.whl.
File metadata
- Download URL: rpi_networking-0.1.9-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eba42301897d472a55fd8264f4b468aa4ac65f37ab960e58a03f55f94c6bbb6f
|
|
| MD5 |
f71d1eed9060ad3832b3685f9f22c501
|
|
| BLAKE2b-256 |
835641520b9c72713ed46f08630d29dccf66112c77f7561bc7107cb22695f8eb
|