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
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 pcf8574_webapp-0.1.1.tar.gz.
File metadata
- Download URL: pcf8574_webapp-0.1.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5462eddcd04330c68c9abc9bfe425ab988f935842d9b342155c5bc39340dcd5
|
|
| MD5 |
e5956538b5f99ad31cbe5ba8d6dcbd40
|
|
| BLAKE2b-256 |
7f3b7428b5d48210ccc04856ae108aecc5b35b3d0c1772734733ddc1b7ba1472
|
File details
Details for the file pcf8574_webapp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pcf8574_webapp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2969b36c9d63e4b16a42906d59c48cbf7cfd77c627652da331a7196a5b9cc24f
|
|
| MD5 |
39eaf6aa7f5f5a57986a9fcb3da63886
|
|
| BLAKE2b-256 |
e27aa43b035e49fd2f630247e954a2da6b173a5ed0f1662fe223b4ddc073035e
|