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.3.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.3-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pcf8574_webapp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 24ef838c64475257414ac8d9aef4f790ce8208f41ac60f2db80daf36eb144de9
MD5 fb9c1f29f5a645099183b12ed7993b6c
BLAKE2b-256 09147d7c37f712a4470299f5c4250a4f33531ca8c5fe9f82289b900c6db6b4e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pcf8574_webapp-0.1.3-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.5

File hashes

Hashes for pcf8574_webapp-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 27a586599d1a066178ba709972022138ae33d11341e052d796359fc56ad117d8
MD5 0530a1edde78930b865bdcdb5026d9e3
BLAKE2b-256 a8d47a540d1153edd2746473b7eec212cd7f76257cba40251f1b8497eda9ee38

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