Skip to main content

web API to control Raspberry Pi GPIO

Project description

API to access Raspberry Pi GPIO based on Python, Flask & Rpi.GPIO library. The software launches an web API that controls IO pins using the Rpi.GPIO library.

This was meant to be used to remotely control relays, thus, it only sets the outputs as high or low.

The pins are referenced through their number printed in the board. Further information about pins can be found here.

API

Route

Request

Description

/api/gpio/

GET

Returns a json object with the status of all pins

/api/gpio/power/<PIN>

GET

Returns a json object with the power pins position and description (5V, 3V3, GND)

/api/gpio/io/<PIN>

GET

Returns a json object with de description and status for a pin. If no pin number is given, returns the status of all io pins.

/api/gpio/io/<PIN>

POST

Sets up a particular pin. Receives a json object that must have the keys type and value. type must be a string with either input or output and value must be a boolean, with the status to write to the channel of the request.

Sample response

{
    "io": [
        {
            "pin": 3,
            "pin_function": "IO",
            "pin_state": 1
        },
       ...],

    "power_pins": [
        {
            "pin": 1,
            "pin_function": "3V3 Power"
        },
       ...]
}

Installation

Latest release through PyPI:

$ pip install pi_gpio_api

Development version:

$ git clone git@github.com:jcapona/pi-gpio-api.git
$ cd pi-gpio-api
$ pip install -e .

CLI

The api can be run as a daemon using the gpioapi command in the Raspberry Pi shell.

$ gpioapi -h
usage: gpioapi [-h] [-H HOST] [-p PORT] command

GPIO web API controller

positional arguments:
  command               Control process: start, stop, restart, status

optional arguments:
  -h, --help            show this help message and exit
  -H HOST, --host HOST  host where the web server will be listening
  -p PORT, --port PORT  port where the web server will be listening

This way, the API can be launched through gpioapi start and stopped through gpioapi stop.

Use as a library

In a python shell:

>>> import pi_gpio_api
>>> pi_gpio_api.app.run(host='0.0.0.0', port=5000)

This will launch a server that listens requests on the given host & port.

Contribution

Feel free to open issues, report bugs or open pull requests.

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

pi-gpio_api-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

pi_gpio_api-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pi-gpio_api-0.1.0.tar.gz.

File metadata

  • Download URL: pi-gpio_api-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

File hashes

Hashes for pi-gpio_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8686d1aff46a77b88b6a728cb61cee61ba9581da6774ff84695d4fa639dbc691
MD5 2aea0b5a17426f802a32ea5b2fb4cf5a
BLAKE2b-256 19167f99673d7dec40df5e7ec429ae752bf66185a0ea9ab902af442b54f8508b

See more details on using hashes here.

File details

Details for the file pi_gpio_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pi_gpio_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

File hashes

Hashes for pi_gpio_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5457e4ddd302e0e37579ce8dd0584d079183d463d19a484656f89ec7cbf91f9a
MD5 de8375ba285bbbfbc5ea4e08e811377d
BLAKE2b-256 f31375979e0e80fe139197609f9e96d4ba7997832588e3f582c0b817baaf663e

See more details on using hashes here.

Supported by

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