{"id":15655030,"url":"https://github.com/yozik04/nextion","last_synced_at":"2025-03-04T10:11:32.448Z","repository":{"id":45176448,"uuid":"200283067","full_name":"yozik04/nextion","owner":"yozik04","description":"Nextion serial client","archived":false,"fork":false,"pushed_at":"2024-08-29T18:52:00.000Z","size":130,"stargazers_count":25,"open_issues_count":8,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-25T09:15:45.820Z","etag":null,"topics":["async","asyncio","nextion","python","serial"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yozik04.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":"2019-08-02T18:48:28.000Z","updated_at":"2024-07-28T19:28:21.000Z","dependencies_parsed_at":"2024-08-29T20:45:53.532Z","dependency_job_id":"e706c8cf-2cd0-4175-b97a-0ed3a0c83788","html_url":"https://github.com/yozik04/nextion","commit_stats":{"total_commits":95,"total_committers":2,"mean_commits":47.5,"dds":"0.010526315789473717","last_synced_commit":"3c0cde96a49066a9d0fb30a4ca97b77880c0b787"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yozik04%2Fnextion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yozik04%2Fnextion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yozik04%2Fnextion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yozik04%2Fnextion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yozik04","download_url":"https://codeload.github.com/yozik04/nextion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241827113,"owners_count":20026601,"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":["async","asyncio","nextion","python","serial"],"created_at":"2024-10-03T12:55:35.363Z","updated_at":"2025-03-04T10:11:31.854Z","avatar_url":"https://github.com/yozik04.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nextion serial client [![Build](https://github.com/yozik04/nextion/actions/workflows/python-package.yml/badge.svg)](https://github.com/yozik04/nextion/actions/workflows/python-package.yml)\nLightweight Python 3.8+ async library to control Nextion displays.\n\n## Installation\n### Pypi\n`pip3 install nextion`\n\n## Simple usage:\n```python\nimport asyncio\nimport logging\nimport random\n\nfrom nextion import Nextion, EventType\n\nclass App:\n    def __init__(self):\n        self.client = Nextion('/dev/ttyS1', 9600, self.event_handler)\n\n    # Note: async event_handler can be used only in versions 1.8.0+ (versions 1.8.0+ supports both sync and async versions)\n    async def event_handler(self, type_, data):\n        if type_ == EventType.STARTUP:\n            print('We have booted up!')\n        elif type_ == EventType.TOUCH:\n            print('A button (id: %d) was touched on page %d' % (data.component_id, data.page_id))\n\n        logging.info('Event %s data: %s', type, str(data))\n\n        print(await self.client.get('field1.txt'))\n\n    async def run(self):\n        await self.client.connect()\n\n        # await client.sleep()\n        # await client.wakeup()\n\n        # await client.command('sendxy=0')\n\n        print(await self.client.get('sleep'))\n        print(await self.client.get('field1.txt'))\n\n        await self.client.set('field1.txt', \"%.1f\" % (random.randint(0, 1000) / 10))\n        await self.client.set('field2.txt', \"%.1f\" % (random.randint(0, 1000) / 10))\n\n        await self.client.set('field3.txt', random.randint(0, 100))\n\n        print('finished')\n\nif __name__ == '__main__':\n    logging.basicConfig(\n        format='%(asctime)s - %(levelname)s - %(message)s',\n        level=logging.DEBUG,\n        handlers=[\n            logging.StreamHandler()\n        ])\n    loop = asyncio.get_event_loop()\n    app = App()\n    asyncio.ensure_future(app.run())\n    loop.run_forever()\n```\n\n### Nextion constructor parameters\n```\nurl: str # serial dev\nbaudrate: int # baud rate\nevent_handler: typing.Callable[[EventType, any], None] # Event handler function\nloop=asyncio.get_event_loop() # your own event loop\nreconnect_attempts: int = 3 # how many times to try to retry command in case of failure\nencoding: str = 'ascii' # Nextion encoding\n```\n\n### Nextion parameters\n#### Encoding\nYou can update encoding on fly (This changes encoding of serial communication only):\n\n`client.encoding = 'latin-1'`\n\nGet current set encoding (Not fetched from the device)\n\n`print(client.encoding)`\n\n## Event handling\n\n```event_handler``` method in the example above will be called on every event coming from the display.\n\n| EventType        | Data                       | Data attributes                    |\n|------------------|----------------------------|------------------------------------|\n| TOUCH            | TouchDataPayload           | page_id, component_id, touch_event |\n| TOUCH_COORDINATE | TouchCoordinateDataPayload | x, y, touch_event                  |\n| TOUCH_IN_SLEEP   | TouchCoordinateDataPayload | x, y, touch_event                  |\n| AUTO_SLEEP       | None                       | -                                  |\n| AUTO_WAKE        | None                       | -                                  |\n| STARTUP          | None                       | -                                  |\n| SD_CARD_UPGRADE  | None                       | -                                  |\n\nFor some components in the Nextion Editor you need to check `Send Component ID` for required event.\n\n# Firmware uploading\nIf you installed the library you should have `nextion-fw-upload` command in your PATH.\n```bash\nnextion-fw-upload -h\n```\n\nOtherwise use next command in the root of the project:\n```bash\npython -m nextion.console_scripts.upload_firmware -h\n```\n\nUsage (check with option `-h`)\n```\nusage: nextion-fw-upload [-h]\n                         [-b {2400,4800,9600,19200,38400,57600,115200,230400}]\n                         [-ub {2400,4800,9600,19200,38400,57600,115200,230400}]\n                         [-v]\n                         device file\n\npositional arguments:\n  device                device serial port\n  file                  firmware file *.tft\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -b {2400,4800,9600,19200,38400,57600,115200,230400}, --baud {2400,4800,9600,19200,38400,57600,115200,230400}\n                        baud rate\n  -ub {2400,4800,9600,19200,38400,57600,115200,230400}, --upload_baud {2400,4800,9600,19200,38400,57600,115200,230400}\n                        upload baud rate\n  -v, --verbose         output debug messages\n```\n\n# Additional resources:\n- https://nextion.tech/instruction-set/\n- [PyPI](https://pypi.org/project/nextion/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyozik04%2Fnextion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyozik04%2Fnextion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyozik04%2Fnextion/lists"}