Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/markparker5/rpi-networking
Control wifi, hotspot and hostname of Raspberry Pi
https://github.com/markparker5/rpi-networking
debian linux python python3 raspberry-pi raspberry-pi-zero-w raspberrypi raspbian rpi rpi-zero-w rpi4
Last synced: 15 days ago
JSON representation
Control wifi, hotspot and hostname of Raspberry Pi
- Host: GitHub
- URL: https://github.com/markparker5/rpi-networking
- Owner: MarkParker5
- License: mit
- Created: 2023-07-20T11:07:29.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-11-21T18:26:53.000Z (about 1 year ago)
- Last Synced: 2024-04-24T00:43:32.896Z (9 months ago)
- Topics: debian, linux, python, python3, raspberry-pi, raspberry-pi-zero-w, raspberrypi, raspbian, rpi, rpi-zero-w, rpi4
- Language: Python
- Homepage: https://pypi.org/project/rpi-networking
- Size: 34.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rpi-networking
Control wifi, hotspot and hostname of Raspberry Pi## Requirments
Python3.10+
## Installation
### Using pip:
```sh
pip3 install rpi-networking
```### Using poetry
```sh
poetry add rpi-networking
```## Prepare system
### Automatically
Via curl
```sh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/MarkParker5/rpi-networking/master/setup.sh)"
```Or via wget
```sh
sh -c "$(wget https://raw.githubusercontent.com/MarkParker5/rpi-networking/master/setup.sh -O -)"
```### Manually
#### Dependencies
```sh
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)
```sh
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.
```python
# rpi_networking.configuraiondef 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
```python
# rpi_networking.hostnamedef set_hostname(hostname: str):
def restart_interfaces(): # apply new hostname without reboot
```### Hotspot
```python
# rpi_networking.hotspotdef 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
```python
# rpi_networking.statusdef 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
```python
# rpi_networking.wificountry: str = 'GB' # country code for wpa_supplicant
class InterfaceBusyException(Exception):
passclass Cell:
ssid: str
quality: float
frequency: str
encrypted: boolclass 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:
```