{"id":24015176,"url":"https://github.com/umer0586/droidpad-python-examples","last_synced_at":"2025-05-06T22:21:55.110Z","repository":{"id":270822701,"uuid":"911551446","full_name":"umer0586/droidpad-python-examples","owner":"umer0586","description":"Python examples for DroidPad Android Application","archived":false,"fork":false,"pushed_at":"2025-03-13T10:03:15.000Z","size":77,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T03:32:07.117Z","etag":null,"topics":["bluetooth-low-energy","connection","controller","internet-of-things","iot","mqtt","python","python-android","python-bluetooth","python-controller","python-iot","tcp","udp","websocket"],"latest_commit_sha":null,"homepage":"https://github.com/umer0586/DroidPad","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/umer0586.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-03T09:33:04.000Z","updated_at":"2025-03-26T06:43:33.000Z","dependencies_parsed_at":"2025-01-03T11:22:04.408Z","dependency_job_id":"1b030d77-f564-4b5f-9ce7-38fd01014662","html_url":"https://github.com/umer0586/droidpad-python-examples","commit_stats":null,"previous_names":["umer0586/droidpad-python-examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umer0586%2Fdroidpad-python-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umer0586%2Fdroidpad-python-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umer0586%2Fdroidpad-python-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umer0586%2Fdroidpad-python-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/umer0586","download_url":"https://codeload.github.com/umer0586/droidpad-python-examples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252777359,"owners_count":21802590,"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":["bluetooth-low-energy","connection","controller","internet-of-things","iot","mqtt","python","python-android","python-bluetooth","python-controller","python-iot","tcp","udp","websocket"],"created_at":"2025-01-08T07:54:06.505Z","updated_at":"2025-05-06T22:21:55.094Z","avatar_url":"https://github.com/umer0586.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## This Repository contains Python examples for [DroidPad](https://github.com/umer0586/DroidPad) Android app\n\n1. ### Clone this Repo\n```bash\ngit clone https://github.com/umer0586/droidpad-python-examples\n```\n2. ### Install requirements\n```bash\npip install -r requirements.txt\n```\n\n3. ### Move to servers directory\n```bash\ncd droidpad-python-examples/servers\n```\n-  #### To Start a websocket server\n    ```bash\n     python websocket-server.py 8080\n    ```\n-  #### To Start a TCP server\n    ```bash\n     python tcp-server.py 8081\n    ```\n-  #### To Start a UDP server\n    ```bash\n     python udp-server.py 8082\n    ```\n### To find your machines's IP address:\n  - On Windows, use the `ipconfig` command.\n  - On Linux, use the `ifconfig` command.\n\n\nCreate a new controller in [DroidPad](https://github.com/umer0586/DroidPad). Then, navigate to the connection settings and specify the IP address and port number. Once connected, and you should see JSON messages being printed in the console.\n\n---\n\n### Bluetooth Low Energy (BLE) in DroidPad\n\nDroidPad functions as a **BLE peripheral** and sends notifications containing `CSV` strings to connected client through the characteristic UUID: `dc3f5274-33ba-48de-8246-43bf8985b323`.\n\n#### Steps to Connect:\n1. **Start the GATT Server on DroidPad**:\n   - Open a control pad with BLE connection and tap the **Play** button to initialize the GATT server and start advertising.\n\n2. **Subscribe Using the Python Client**:\n   - Navigate to the `BLEClient` directory in the DroidPad Python examples repository.\n   - Run the `subscribe.py` script:\n\n     ```bash\n     python subscribe.py\n     ```\n   - This script performs the following:\n     - Scans for nearby BLE devices advertising the service UUID: `4fbfc1d7-f509-44ab-afe1-62ea40a4b111`.\n     - Subscribes to notifications from the characteristic UUID: `dc3f5274-33ba-48de-8246-43bf8985b323`.\n\n3. **View Notifications**:\n   - Once the script connects to DroidPad, it displays `CSV` strings in the console.\n   - These notifications are triggered by interactions with items on the control pad.\n\n\n---\n\n### Configurable Server (by [imsamuka](https://github.com/imsamuka))\n\nThis server is configured with a [TOML](https://toml.io) file, and supports multiple TCP/UDP droidpad servers simultaneosly. Theres's a documented [default config file](configServer/default.toml) to use as a reference. There are other examples in the [configServer folder](configServer/).\n\n### Usage\n\n\n```bash\n# Enter configServer directory\ncd configServer\n```\n\n## Running Servers\n\n```bash\npython config-server.py [--qr] [CONFIG_FILE]\n\n# Examples:\n\npython config-server.py default.toml\n\npython config-server.py linux/mouse-x11.toml\n```\n\n### Generating QR Code\n\nYou can use the `--qr` flag to display a QRCode to import the pads in the app.\nThis auto generated import is intended for development use only. The server will\nalso try to load a file `pad_name.json` adjacent to the `CONFIG_FILE` and use that\nas a template to generate the QR Code, preserving element positions, scaling, colors,\nand most other properties.\n\n\n## Writing Server Configuration\n\nThe configuration is always composed of a `[pad_name]` and `[pad_name.rules]`. You can have more than one *pad* per file, but each one has to have these 2 sections.\n\n## Pad configuration\nIn `[pad_name]` you declare the global configuration for this particular *pad*:\n\n```toml\n[example]\n\nhost = \"0.0.0.0\"\nport = 8080\ntype = \"UDP\"\ndefault_eval = \"sh\"\ncall_sync = \"threaded_async\"\nfstring_sim = true\nformat_map = true\n```\n\n**The meaning of each field is explained in the [default configuration file](configServer/default.toml).** It's recommended for Windows users to change `default_eval` to `py`, `cmd` or `powershell`.\n\n### Rules configuration\n\nIn `[pad_name.rules]` you declare all rules about the pad elements themselves.\n\n```toml\n[example.rules]\n\nctl_id-dp_press = \"echo {id} {button} pressed\"\nctl_id-dp_release = \"echo {id} {button} released\"\nctl_id-dp_click = \"echo {id} {button} clicked\"\n```\n\nEach rule field is composed of three parts separated by a `-` character, and a command or list of commands:\n\n```toml\nELEMENTID-RULETYPE-EVALTYPE = \"COMMAND\"\n\nELEMENTID-RULETYPE-EVALTYPE = [\"COMMAND_1\", \"COMMAND_2\"]\n\nELEMENTID-RULETYPE-EVALTYPE = \"\"\"\n    MULTILINE_COMMAND\n\"\"\"\n```\n\n- `ELEMENTID`: Is the ID you configure in the DroidPad App for a control element.\n- `RULETYPE`: Determines the *type* of element and *when* the rule will activate. The possible choices for this part can be found in the [default configuration file](configServer/default.toml).\n- `EVALTYPE`: Determines which program will be used to execute `COMMAND`. For example:\n\n  - `-bash` will run `bash -c \"COMMAND\"`\n  - `-py` will run `python -c \"COMMAND\"`\n\n  If `-EVALTYPE` is missing, then the eval type declared in the `default_eval` configuration field is used instead.\n\n- `COMMAND`: How it will be interpreted depends on the eval type.\n  - If `format_map = true`, substrings like `{id} {type} {state} {button}` will be substituited by their values in the event received. For example, if a dpad left button was pressed, `{button}` will be substituited by `LEFT` and `{state}` by `PRESS`. Normal python formatting works, for example in a slider with value `0.9`, `{value:%}` will be `90%`.\n  - If `fstring_sim = true`, substrings inside `__{ }__` will be interpreted like a python [f-string](https://docs.python.org/3/reference/lexical_analysis.html#f-strings). This means you can run python code BEFORE the actual command runs. All event fields are in scope, and a dictionary `memo` may be used to store other variables.\n  - In the case of eval type `exec`, it expects a list of arguments instead of a single string, for example `[\"echo\", \"Element {id} sent a event\"]`. If you want multiple commands, you need to use a list inside a list.\n\n### Examples:\n\n```toml\n\n# After tapping a button with id 'turnoff'\n# run the command: sh -c shutdown\nturnoff-click-sh = \"shutdown\"\n\n# After pressing/release button with id `mousebtn1`\n# run the program 'xdotool' with default_eval\n# to press/release the mouse left button\nmousebtn1-press = \"xdotool mousedown 1\"\nmousebtn1-release = \"xdotool mouseup 1\"\n\n# The same as above, using __{}__ substitution\n# uses `fstring_sim = true`\nmousebtn1-button = \"xdotool mouse__{'down' if state == 'PRESS' else 'up'}__ 1\"\n\n# When a joystick with id 'radius' sends a event\n# Run a python script to print the calculated radius in degrees\nradius-joy-py = \"\"\"\nimport math\n\nx = {x} # \u003c-- uses `format_map = true` here\ny = {y}\nprint('Radius: ', math.atan2(y, x) * 180.0 / math.pi)\n\"\"\"\n\n# Change the volume of the current media using a slider with id 'volume'\n# Echo the current volume as a percentage\n# uses `format_map = true`\nvolume-slider-sh = 'playerctl volume {value}; echo \"Volume at {value:%}\"'\n\n\n# Convert every button press on a dpad with id 'arrows' to keyboard arrows\n# __{button.title()}__ converts \"RIGHT\" to \"Right\"\narrows-dp_button = \"xdotool key__{'down' if state == 'PRESS' else 'up'}__ __{button.title()}__\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumer0586%2Fdroidpad-python-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumer0586%2Fdroidpad-python-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumer0586%2Fdroidpad-python-examples/lists"}