Skip to main content

This is a Python library designed to be able to easily control your PCF8574 I/O expanders over a Web interface.

Project description

PCF8574 WebApp

This is a Python library designed to be able to easily control your PCF8574 I/O expanders over a Web interface. The Library is based on the pcf8574_interface library, which extends the functionality of the original pcf8574 library with some useful features.

Features

  • Display current I/O states: The web interface is able to display the current states of your PCF8574 I/O expanders.
  • Override I/O states: You can override the current I/O states of your PCF8574 I/O expanders to test your hardware and software without changing the actual states.
  • Default Web interface: The Default Web interface provides an overview of all connected PCF8574 I/O expanders and their current states.
  • Custom Routes: You can create custom routes with custom templates to display only specific I/O pins.

Installation

You can install the library with the following command:

pip install pcf8574_webapp

Usage

Default Web Interface

The default web interface is automatically available at http://0.0.0.0:5000/.

Starting the WebApp

To start the web application, you can use the following code snippet:

from pcf8574_interface import PCF8574Interface, IoPortType, PCF8574Pool
from pcf8574_webapp import PCF8574WebApp

from uvicorn import Config, Server

pool = PCF8574Pool()

# Create a few interface instances
pcf1 = PCF8574Interface(i2c_bus_no=1, address=0x20, io_type=IoPortType.OUT)
pcf2 = PCF8574Interface(i2c_bus_no=1, address=0x21, io_type=IoPortType.IN)

# Add them to the pool
pool.add_port(pcf1)
pool.add_port(pcf2)

fastapi_webapp = PCF8574WebApp(pool)
pool.set_api(fastapi_webapp.get_notifier())
config = Config(app=fastapi_webapp.get_app(), host="0.0.0.0", port=5000, log_level="info")
server = Server(config)
server.run()
# or if you want to run it asynchronously:
# try:
#     await server.serve()
# except KeyboardInterrupt:
#     print("WebApp server stopped.")

Custom Routes

You can create custom routes to display specific I/O pins or groups of pins. For example, to create a route that displays all input ports, you can use the following code snippet after the instantiation of PCF8574WebApp:

fastapi_webapp.add_route(
    "/inputs",
    "index.html",
    {
        "inputs": pool.get_ports_by_type(IoPortType.IN),
    }
)

Custom Templates

If you want to use custom templates, you need to register the directory containing your custom templates.

custom_pins.html

{% extends "base.html" %}
{% block title %}Custom Template{% endblock %}

{% block content %}
    ...
    {% with resource=custom_ports %}
        {% include '_table.html' %}
    {% endwith %}
    ...
{% endblock %}
from pathlib import Path

fastapi_webapp.add_template_directory(Path(__file__).resolve().parent / "custom_templates")
fastapi_webapp.add_route(
    "/custom_ports",
    "custom_ports.html",
    {
        "custom_ports": (pool.get_port(1, 0x20), pool.get_port(1, 0x21))
    }
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pcf8574_webapp-0.1.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pcf8574_webapp-0.1.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file pcf8574_webapp-0.1.2.tar.gz.

File metadata

  • Download URL: pcf8574_webapp-0.1.2.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for pcf8574_webapp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e94d6aa100576b1ce76cad251c7e73b92424065db94eacf65d327cb97cce78a6
MD5 71cdb2b982be77e40ca7fbb336c0bf06
BLAKE2b-256 c5819e0fb0859522b899a8d001485156fc9e4f86bd6d7da8842518487a8e61f9

See more details on using hashes here.

File details

Details for the file pcf8574_webapp-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pcf8574_webapp-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for pcf8574_webapp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e255f145e6d22edceb97ac6c4a4625c9a0496e9cecbff7d54b73b1b220a39b6a
MD5 0e6db245252356b228ebe8c12c240f60
BLAKE2b-256 d2abe1acfd10875f0b46e5c83775c10cf22d66bdb13fdfa8ebc0bd7e65b1d0b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page