GithubHelp home page GithubHelp logo

cec-api's Introduction

CEC REST API

REST API to control HDMI devices via the CEC protocol.

Installation

Execute the following commands on a Debian or Ubuntu system to install the required dependencies:

apt-get update
apt-get install -y python3-cec python3-pip
pip install -r requirements.txt

Usage

Server

Execute the following command to run the server locally:

./app/server.py

You may then go to http://127.0.0.1:8000 to browse the documentation and test the API.

The following arguments are available:

./app/server.py [-h] [-a ADDRESS] [-p PORT] [-l LOG_LEVEL]

Optional arguments:
  -h, --help                           Show help message and exit
  -a ADDRESS, --address ADDRESS        Address to bind to (default: 127.0.0.1)
  -p PORT, --port PORT                 Port to listen on (default: 8000)
  -l LOG_LEVEL, --log-level LOG_LEVEL  Log level: CRITICAL, ERROR, WARNING, INFO, DEBUG (default: INFO)

A Docker image is also available for amd64 and arm64 architectures:

docker run -it --rm --device /dev/aocec -p 8000:8000 ghcr.io/fcrespel/cec-api:master [-h] [-a ADDRESS] [-p PORT] [-l LOG_LEVEL]

You may want to run it in the background using commands such as the following:

# Create and start container
docker run -d --name cec-api --device /dev/aocec -p 127.0.0.1:8000:8000 ghcr.io/fcrespel/cec-api:master

# Stop server
docker stop cec-api

# Start server
docker start cec-api

# Show live logs
docker logs -f cec-api

NOTE: the API port is not secured, make sure to only expose it locally or to trusted clients.

Client

You may call the API with any HTTP client such as curl:

# Get TV status:
curl -sSf -XGET http://127.0.0.1:8000/device/0/status

# Power on TV:
curl -sSf -XPUT http://127.0.0.1:8000/device/0/status -d 1

# Power off TV:
curl -sSf -XPUT http://127.0.0.1:8000/device/0/status -d 0

Device numbers are based on the CEC protocol:

  • 0: TV
  • 1: Recording 1
  • 2: Recording 2
  • 3: Tuner 1
  • 4: Playback 1
  • 5: Audio system
  • 6: Tuner 2
  • 7: Tuner 3
  • 8: Playback 2
  • 9: Recording 3
  • 10: Tuner 4
  • 11: Playback 3

cec-api's People

Contributors

fcrespel avatar

Stargazers

 avatar  avatar

Watchers

 avatar Kostas Georgiou avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.