{"id":22468487,"url":"https://github.com/projectweekend/pi-broadcast-service","last_synced_at":"2025-03-27T15:44:35.889Z","repository":{"id":27206105,"uuid":"30676844","full_name":"projectweekend/Pi-Broadcast-Service","owner":"projectweekend","description":"Broadcast data from a Raspberry Pi using RabbitMQ \u0026 Python","archived":false,"fork":false,"pushed_at":"2015-02-19T18:04:40.000Z","size":184,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T09:50:01.212Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/projectweekend.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-12T00:12:18.000Z","updated_at":"2015-02-19T18:04:40.000Z","dependencies_parsed_at":"2022-09-02T10:10:45.366Z","dependency_job_id":null,"html_url":"https://github.com/projectweekend/Pi-Broadcast-Service","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FPi-Broadcast-Service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FPi-Broadcast-Service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FPi-Broadcast-Service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FPi-Broadcast-Service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/projectweekend","download_url":"https://codeload.github.com/projectweekend/Pi-Broadcast-Service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245874178,"owners_count":20686716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T11:16:57.886Z","updated_at":"2025-03-27T15:44:35.840Z","avatar_url":"https://github.com/projectweekend.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Install it\n\n```\npip install Pi-Broadcast-Service\n```\n\n\n## GPIO basic broadcast service\n\nThe GPIO basic broadcast service (`pi_broadcast_service.GPIOBasicBroadcastService`) makes it easy to broadcast a message to RabbitMQ when pin events are detected.\n\n### Configuring the GPIO basic broadcast service\n\nA config file, written in [YAML](http://en.wikipedia.org/wiki/YAML), is used to define the initial pin setup. If a pin is not defined here it will not be used by **Pi-Broadcast-Service**. You can save this file anywhere since you will provide a path to it in your code. The following snippet shows an example configuration file:\n\n```yaml\n18:\n  mode: IN\n  event: RISING\n  handler: broadcast\n  bounce: 200\n22:\n  mode: IN\n  event: FALLING\n  handler: broadcast\n  bounce: 200\n24:\n  mode: IN\n  event: BOTH\n  handler: broadcast\n  bounce: 200\n```\n\n* Add a numbered element for each pin to enable\n* `mode` - This service only uses pins defined as `IN`. (Required)\n* `event` - The event you want to wait for on the pin. Accepted values are: `RISING`, `FALLING`, `BOTH`.\n* `handler` - This is used in combination with an `event` to designate the function to call when that `event` happens. With `pi_broadcast_service.GPIOBasicBroadcastService` this value must be set to `broadcast`.\n* `bounce` - This can be used when an `event` is defined to prevent multiple handler calls being fired accidentally. The value is the number of milliseconds to wait before detecting another `event`.\n\nFor more available options, like pull up/down resistors, see documentation for the [Pi-Pin-Manager configuration file](https://github.com/projectweekend/Pi-Pin-Manager#notes).\n\n### Starting the basic GPIO service\n\nThis part runs on your Raspberry Pi. It initializes the desired GPIO pins, connects to RabbitMQ, waits for the defined pin events, and then sends out a message when an event happens. The message is sent to the RabbitMQ broker on an exchange named `gpio_broadcast`, with a routing key that matches the `device_key` value used to crteate the service instance.\n\n```python\nfrom pi_broadcast_service import GPIOBasicBroadcastService\n\n\n# The RabbitMQ connection string\nRABBIT_URL='some_actual_connection_string'\n\n# A unique string you make up to identify a single Raspberry Pi\nDEVICE_KEY='my_awesome_raspberry_pi'\n\n# Path to the config file referenced in the section above\nPIN_CONFIG = '/path/to/config/file.yml'\n\ngpio_broadcast_service = GPIOBasicBroadcastService(\n    rabbit_url=RABBIT_URL,\n    device_key=DEVICE_KEY,\n    pin_config=PIN_CONFIG)\n\ngpio_broadcast_service.start()\n```\n\n\n## GPIO custom broadcast service\n\nThe GPIO custom broadcast service (`pi_broadcast_service.GPIOCustomBroadcastService`) functions in almost the same way as the basic version. The difference with this version is that it is up to you to implement your own event handler class. Your custom event handler will need to inherit from `pi_broadcast_service.GPIOCustomBroadcastEventHandler` for you to access to the `broadcast` method from inside you own custom handler methods.\n\n### Configuring the GPIO custom broadcast service\n\nThis is the same as the basic version, using the YAML file, except you will name your own `handler` for each pin. Each `handler` name must correspond to a method name in your custom event handler class.\n\n### Starting the custom GPIO service\n\nThis part runs on your Raspberry Pi. It initializes the desired GPIO pins, connects to RabbitMQ, waits for the defined pin events, and then executes one of your custom handler methods when an event happens. The message is sent to the RabbitMQ broker on an exchange named `gpio_broadcast`, with a routing key that matches the `device_key` value used to crteate the service instance.\n\n```python\nfrom pi_broadcast_service import GPIOCustomBroadcastService, GPIOCustomBroadcastEventHandler\n\n\n# The RabbitMQ connection string\nRABBIT_URL='some_actual_connection_string'\n\n# A unique string you make up to identify a single Raspberry Pi\nDEVICE_KEY='my_awesome_raspberry_pi'\n\n# Path to the config file referenced in the section above\nPIN_CONFIG = '/path/to/config/file.yml'\n\nclass MyEventHandler(GPIOCustomBroadcastEventHandler):\n\n    def do_something(self, pin_number):\n        # Build my_custom_message as a dictionary then use self.broadcast()\n        return self.broadcast(my_custom_message)\n\ngpio_broadcast_service = GPIOCustomBroadcastService(\n    rabbit_url=RABBIT_URL,\n    device_key=DEVICE_KEY,\n    pin_config=PIN_CONFIG,\n    event_handler=MyEventHandler)\n\ngpio_broadcast_service.start()\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Fpi-broadcast-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojectweekend%2Fpi-broadcast-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Fpi-broadcast-service/lists"}