https://github.com/projectweekend/pi-celery-gpio
Examples combining Celery (http://www.celeryproject.org/) and Raspberry Pi GPIO
https://github.com/projectweekend/pi-celery-gpio
Last synced: 10 months ago
JSON representation
Examples combining Celery (http://www.celeryproject.org/) and Raspberry Pi GPIO
- Host: GitHub
- URL: https://github.com/projectweekend/pi-celery-gpio
- Owner: projectweekend
- License: mit
- Created: 2015-06-28T17:28:13.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-18T14:44:37.000Z (almost 11 years ago)
- Last Synced: 2025-02-01T19:29:52.854Z (over 1 year ago)
- Language: Python
- Size: 164 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pi-Celery-GPIO
An example combining Celery (http://www.celeryproject.org/) and [Raspberry Pi GPIO](https://www.raspberrypi.org/documentation/usage/gpio/)
## Service
* This directory (`/service`) contains a Celery worker meant to run on a Raspberry Pi.
* The `/service/requirements.txt` file tracks all the Python dependencies for the examples in this directory. To manually install: `sudo pip install -r requirements.txt`.
* The `/service/control` directory contains a Celery worker that receives tasks to control the Raspberry Pi's GPIO pins.
* Automated install with [Fabric](http://www.fabfile.org/): `fab install_celery_control`
* Automated update with [Fabric](http://www.fabfile.org/): `fab install_celery_update`
### Controlling GPIO
Export the following environment variables before starting the worker:
* `CONTROL_RABBIT_URL`: The [RabbitMQ](https://www.rabbitmq.com/) connection URL for the [Celery broker](http://celery.readthedocs.org/en/latest/getting-started/brokers/rabbitmq.html).
* `CONTROL_PIN_CONFIG`: The path to a [config file](https://github.com/projectweekend/Pi-Pin-Manager#configure-it) that defines the pins available to be controlled. **Note:** This worker only receives messages to flip or read GPIO pins so the config `mode` should always be set to `OUT`.
* `C_FORCE_ROOT`: Set this to `True` because the Raspberry Pi GPIO access requires root access.
Start the `control` Celery worker by running this command inside the `/service` directory:
```
sudo -E celery -A control worker
```
### Using the GPIO Client
In the `/client` package there is a class to use for interacting with the Raspberry Pi that is running the `control` Celery worker. You can run this from anywhere that can connect to the same RabbitMQ instance referenced in `CONTROL_RABBIT_URL`.
**Example:**
```python
from client.gpio import GPIOClient
# Set this to the same connection URL used in CONTROL_RABBIT_URL
CONTROL_RABBIT_URL = ''
# Create an instance of the class
client = GPIOClient(CONTROL_RABBIT_URL)
# Turn pin on (result will be 1)
result = client.on(18)
# Turn pin off (result will be 0)
result = client.off(18)
# Read pin state (result will be 0 or 1)
result = client.read(18)
```