rpi-networking


Namerpi-networking JSON
Version 0.1.9 PyPI version JSON
download
home_pagehttps://pypi.org/project/rpi-networking/
SummaryControl wifi, hotspot and hostname of Raspberry Pi
upload_time2023-11-21 18:26:50
maintainer
docs_urlNone
authorMark Parker
requires_python>=3.10,<4.0
licenseMIT
keywords raspberry-pi python python3 raspberry-pi rpi raspberrypi raspbian raspberry-pi-zero-w rpi-zero-w rpi4 linux debian
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.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

```python
# rpi_networking.hostname

def set_hostname(hostname: str):
    
def restart_interfaces():  # apply new hostname without reboot
```

### Hotspot

```python
# 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

```python
# 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

```python
# 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:
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/rpi-networking/",
    "name": "rpi-networking",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "raspberry-pi,python,python3,raspberry-pi,rpi,raspberrypi,raspbian,raspberry-pi-zero-w,rpi-zero-w,rpi4,linux,debian",
    "author": "Mark Parker",
    "author_email": "mark@parker-programs.com",
    "download_url": "https://files.pythonhosted.org/packages/f3/54/d8e0695d9763c82d3827bb279cde9c2e098b817f3b1d3d2597d0da08100a/rpi_networking-0.1.9.tar.gz",
    "platform": null,
    "description": "# rpi-networking\nControl wifi, hotspot and hostname of Raspberry Pi\n\n## Requirments \n\nPython3.10+\n\n## Installation\n\n### Using pip:\n\n```sh\npip3 install rpi-networking \n```\n\n### Using poetry\n\n```sh\npoetry add rpi-networking\n```\n\n## Prepare system\n\n### Automatically \n\nVia curl\n\n```sh\nsh -c \"$(curl -fsSL https://raw.githubusercontent.com/MarkParker5/rpi-networking/master/setup.sh)\"\n```\n\nOr via wget\n\n```sh\nsh -c \"$(wget https://raw.githubusercontent.com/MarkParker5/rpi-networking/master/setup.sh -O -)\"\n```\n\n### Manually\n\n#### Dependencies\n\n```sh\nsudo apt update ; \\\nsudo apt upgrade -y ; \\\nsudo apt install dnsmasq hostapd dhcpd -y\n```\n\n#### Give permissions to edit configuration files (optional)\n\nGive user permission to edit configuration files so python doesn't have to be run as root (sudo)\n\n```sh\nfiles=(\n  \"/etc/dnsmasq.conf\"\n  \"/etc/hosts\"\n  \"/etc/default/hostapd\"\n  \"/etc/hostapd/hostapd.conf\"\n  \"/etc/network/interfaces\"\n  \"/etc/network/interfaces.d\"\n  \"/etc/wpa_supplicant/wpa_supplicant.conf\"\n)\n\nfor file in \"${files[@]}\"; do\n  sudo chown \"$USER\" \"$file\"\n  sudo chmod 644 \"$file\"\ndone;\n```\n\n## Docs\n\n### Configuration\n\nThere are functions for initial configuration setup.\n\n```python\n# rpi_networking.configuraion\n\ndef write_interfaces():\n\ndef write_default_hostapd():\n\ndef write_hostapd_conf():\n\ndef write_dnsmasq_conf():\n\ndef write_wpa_supplicant(country: str = \"GB\"):\n\ndef write_hosts():\n\ndef write_all(): # calls all functions above\n```\n\n**In most cases you only need to call `write_all()` once to setup all configuration files.**\n\n### Hostname\n\n```python\n# rpi_networking.hostname\n\ndef set_hostname(hostname: str):\n    \ndef restart_interfaces():  # apply new hostname without reboot\n```\n\n### Hotspot\n\n```python\n# rpi_networking.hotspot\n\ndef is_hotspot_up() -> bool:\n\ndef start_hotspot() -> bool:\n    \ndef stop_hotspot() -> bool:\n```\n\nThe `bool` return value is `True` if function finished without errors (exit code 0), else `False`\n\n### Status\n\n```python\n# rpi_networking.status\n\ndef is_wlan_connected() -> bool:\n\ndef is_eth_connected() -> bool:\n\ndef is_wlan_global_connected() -> bool: # 'global' means internet access\n\ndef is_eth_global_connected() -> bool:\n\ndef is_wps_running() -> bool:\n```\n\n### WiFi\n\n```python\n# rpi_networking.wifi\n\ncountry: str = 'GB' # country code for wpa_supplicant\n\nclass InterfaceBusyException(Exception): \n    pass\n\nclass Cell:\n    ssid: str\n    quality: float\n    frequency: str\n    encrypted: bool\n\nclass Network:\n    ssid: str\n    psk: str\n    id_str: str\n\n# Functions\n\ndef read_networks() -> list[Network]:\n\ndef write_networks(networks: list[Network]):\n\ndef add_network(ssid: str, psk: str):\n\ndef reconnect() -> bool: # connect to the best available network\n\ndef scan() -> Generator[Cell, None, None]:\n\ndef start_wps() -> bool:\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Control wifi, hotspot and hostname of Raspberry Pi",
    "version": "0.1.9",
    "project_urls": {
        "Documentation": "https://github.com/MarkParker5/rpi-networking/blob/master/README.md",
        "Homepage": "https://pypi.org/project/rpi-networking/",
        "Repository": "https://github.com/MarkParker5/rpi-networking"
    },
    "split_keywords": [
        "raspberry-pi",
        "python",
        "python3",
        "raspberry-pi",
        "rpi",
        "raspberrypi",
        "raspbian",
        "raspberry-pi-zero-w",
        "rpi-zero-w",
        "rpi4",
        "linux",
        "debian"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "835641520b9c72713ed46f08630d29dccf66112c77f7561bc7107cb22695f8eb",
                "md5": "f71d1eed9060ad3832b3685f9f22c501",
                "sha256": "eba42301897d472a55fd8264f4b468aa4ac65f37ab960e58a03f55f94c6bbb6f"
            },
            "downloads": -1,
            "filename": "rpi_networking-0.1.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f71d1eed9060ad3832b3685f9f22c501",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 7533,
            "upload_time": "2023-11-21T18:26:49",
            "upload_time_iso_8601": "2023-11-21T18:26:49.003627Z",
            "url": "https://files.pythonhosted.org/packages/83/56/41520b9c72713ed46f08630d29dccf66112c77f7561bc7107cb22695f8eb/rpi_networking-0.1.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f354d8e0695d9763c82d3827bb279cde9c2e098b817f3b1d3d2597d0da08100a",
                "md5": "19484138a02c4e3db1ed5112dbc38aa4",
                "sha256": "0350a924a2e977b27b2bf46e93e6e4e5e0ded55d5d453099bef4c5d2dd6db621"
            },
            "downloads": -1,
            "filename": "rpi_networking-0.1.9.tar.gz",
            "has_sig": false,
            "md5_digest": "19484138a02c4e3db1ed5112dbc38aa4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 5457,
            "upload_time": "2023-11-21T18:26:50",
            "upload_time_iso_8601": "2023-11-21T18:26:50.885343Z",
            "url": "https://files.pythonhosted.org/packages/f3/54/d8e0695d9763c82d3827bb279cde9c2e098b817f3b1d3d2597d0da08100a/rpi_networking-0.1.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-21 18:26:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MarkParker5",
    "github_project": "rpi-networking",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "rpi-networking"
}
        
Elapsed time: 0.13744s