{"id":20915804,"url":"https://github.com/brainelectronics/python-modules","last_synced_at":"2026-05-15T12:32:28.445Z","repository":{"id":41343454,"uuid":"391336213","full_name":"brainelectronics/python-modules","owner":"brainelectronics","description":"Custom brainelectronics python modules and wrappers","archived":false,"fork":false,"pushed_at":"2022-10-23T17:09:04.000Z","size":244,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-07-25T07:33:21.920Z","etag":null,"topics":["git","helpers","modbus","module","python-script","python3","sqlite3","vcs"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brainelectronics.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-31T11:25:03.000Z","updated_at":"2022-11-12T17:38:01.000Z","dependencies_parsed_at":"2023-01-19T23:33:18.658Z","dependency_job_id":null,"html_url":"https://github.com/brainelectronics/python-modules","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/brainelectronics/python-modules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2Fpython-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2Fpython-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2Fpython-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2Fpython-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainelectronics","download_url":"https://codeload.github.com/brainelectronics/python-modules/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2Fpython-modules/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33067210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["git","helpers","modbus","module","python-script","python3","sqlite3","vcs"],"created_at":"2024-11-18T16:18:25.862Z","updated_at":"2026-05-15T12:32:28.428Z","avatar_url":"https://github.com/brainelectronics.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python modules\n\n\u003c!-- [![Downloads](https://pepy.tech/badge/be-helpers)](https://pepy.tech/project/be-helpers) --\u003e\n![Release](https://img.shields.io/github/v/release/brainelectronics/python-modules?include_prereleases\u0026color=success)\n![Python](https://img.shields.io/badge/python3-Ok-green.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\u003c!-- [![codecov](https://codecov.io/github/brainelectronics/be-helpers/branch/main/graph/badge.svg)](https://app.codecov.io/github/brainelectronics/be-helpers) --\u003e\n\nCustom brainelectronics python modules and wrappers\n\n---------------\n\n## About\n\nThis is a collection of python modules required for MyEVSE and other\nbrainelectronics projects.\n\n\u003c!-- MarkdownTOC --\u003e\n\n- [Available generators](#available-generators)\n- [Setup](#setup)\n\t- [Compilation info generator](#compilation-info-generator)\n\t- [DB wrapper](#db-wrapper)\n\t\t- [SQLite](#sqlite)\n\t\t- [MySQL](#mysql)\n\t\t- [Convert SQLite to MySQL dump](#convert-sqlite-to-mysql-dump)\n\t\t- [Install phpLiteAdmin \\(optional\\)](#install-phpliteadmin-optional)\n\t- [Git wrapper](#git-wrapper)\n\t- [Modbus JSON Generator](#modbus-json-generator)\n\t- [Modbus wrapper](#modbus-wrapper)\n\t\t- [Reading data](#reading-data)\n\t\t\t- [Modbus TCP](#modbus-tcp)\n\t\t\t- [Modbus RTU](#modbus-rtu)\n\t\t- [Writing data](#writing-data)\n\t\t\t- [Modbus TCP](#modbus-tcp-1)\n\t\t\t- [Modbus RTU](#modbus-rtu-1)\n\t- [Structure info generator](#structure-info-generator)\n\n\u003c!-- /MarkdownTOC --\u003e\n\n## Available generators\n\nFor the individual usage of a generator or wrapper read the brief description\nand usage instructions of each module.\n\n## Setup\n\nCreate a virtual environment and install the required modules of the\n[requirements.txt](requirements.txt) file.\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\n```\n\n### Compilation info generator\n\nCreate information file with content of the currently running CI/CD job.\n\nThis example call extracts informations about the file `README.md` of the git\nrepository at `./` and saves the result as `compilation-info.json` in human\nreadable, formatted and sorted style. An example output can be found at\n[example/compilation-info.json](example/compilation-info.json)\n\n```bash\npython generate_compilation_info.py \\\n--file=README.md \\\n--git=./ \\\n--print \\\n--pretty \\\n--save \\\n--output=compilation-info.json \\\n--debug \\\n--verbose=4\n```\n\n### DB wrapper\n\nRequest modbus data with the [Modbus wrapper](#modbus-wrapper) and save the\nresult to a database with optional backup to file.\n\n#### SQLite\n\nThis example requests the data of all registers defined in the file of\n[example/modbusRegisters-phoenix.json](example/modbusRegisters-phoenix.json)\nusing `tcp` as connection type from a device with the unit (address) `180`\nwith an interval of 10 sec for 10 times (iterations), total runtime is 100\nsec. A backup of the table `modbus_data` in the database `modbus_db` in RAM\nonly database is created every `minute` to the folder `backup_folder`. The\nresponse of each request is printed in human readable, formatted and sorted\nstyle to the console.\n\n```bash\npython log_modbus_to_database.py \\\n--file=example/modbusRegisters-phoenix.json \\\n--connection=tcp \\\n--address=192.168.178.188 \\\n--port=180 \\\n--iterations=10 \\\n--interval=10 \\\n--backup=minute \\\n--print \\\n--pretty \\\n--save \\\n--output=backup_folder \\\n--database_type=sqlite \\\n--database=modbus_db \\\n--table=modbus_data \\\n--debug \\\n--verbose=4\n```\n\n#### MySQL\n\nThis example requests the data of all registers defined in the file of\n[example/modbusRegisters-MyEVSE.json](example/modbusRegisters-MyEVSE.json)\nusing `rtu` as connection type from a device with the unit (address) `10` on\nthe bus at `9600` baud, with an interval of 5 sec for 20 times (iterations),\ntotal runtime is 100 sec. The data is inserted into the table `modbus_data` in the database `MyEVSE_DB` by the user `data_providing_user` authenticated by\nits password `superSecurePassword1` in a MySQL database at `127.0.0.1`. The\nresponse of each request is printed in human readable, formatted and sorted\nstyle to the console.\n\n```bash\npython log_modbus_to_database.py \\\n--file=example/modbusRegisters-MyEVSE.json \\\n--connection=rtu \\\n--address=/dev/tty.SLAB_USBtoUART \\\n--baudrate=9600 \\\n--unit=10 \\\n--iterations=5 \\\n--interval=20 \\\n--print \\\n--pretty \\\n--save \\\n--database_type=mysql \\\n--database=MyEVSE_DB \\\n--table=modbus_data \\\n--user=data_providing_user \\\n--password=superSecurePassword1 \\\n--url=127.0.0.1 \\\n--debug \\\n--verbose=4\n```\n\n#### Convert SQLite to MySQL dump\n\nTo get a quick convertion between the SQLite and the MySQL format use the\nfollowing command and may import it in a MySQL instance afterwards.\n\n*Some adjustments might be necessary on the converted SQL file before a\nsuccessful import into MySQL*\n\n```bash\nsqlite3 modbus_data-01-12-2022-191219.sqlite3 .dump \u003e modbus_data-01-12-2022-191219.sql\n```\n\n#### Install phpLiteAdmin (optional)\n\n```bash\n# install Apache2\nsudo apt-get install apache2 -y\n\n# install PHP and required modules\nsudo apt-get install php5 libapache2-mod-php5 php5-sqlite zip unzip -y\n\n# create database folder in web directory\ncd /var/www/html\nsudo mkdir database\ncd database\n\n# download phpLiteAdmin\nsudo wget https://bitbucket.org/phpliteadmin/public/downloads/phpLiteAdmin_v1-9-7-1.zip\nsudo unzip phpLiteAdmin_v1-9-7-1.zip\nsudo rm phpLiteAdmin_v1-9-7-1.zip\n\n# copy example config as real config\nsudo cp phpliteadmin.config.sample.php phpliteadmin.config.php\n\n# may adjust username or other configs now in phpliteadmin.config.php\n\ncd ..\n\n# change ownership, access and execution permissions of the database directory\nsudo chmod 757 database\nsudo chmod 644 database/*.php\nsudo chown root:root database\nsudo chown root:root database/*\n```\n\nTo copy all generated SQlite3 databases inside `database` to the phpLiteAdmin\ninstallation directory `/var/www/html/database`, call the following command\n\n```bash\nscp -r database/*.sqlite3 username@ip-address:/var/www/html/database\n```\n\nAt this point the copied/uploaded databases are only readable but not yet\nwritable/editable by phpLiteAdmin. To make them editable call this command on\nthe machine running phpLiteAdmin\n\n```bash\nsudo chmod 646 /var/www/html/database/*.sqlite3\n```\n\nFinally login to phpLiteAdmin with the default password `admin` at\n[http://ip-address/database/phpliteadmin.php](http://ip-address/database/phpliteadmin.php)\n\n### Git wrapper\n\nCreate a source code information file with the latest git informations.\n\nThis example call extracts informations of the git repository at `./` and\nsaves the result with the default name `vcsInfo.h` in `./`. The output file is\nbased on the [example/vcsInfo.h.template](example/vcsInfo.h.template) and\nfilled with the corresponding data. An example output can be found at\n[example/vcsInfo.h](example/vcsInfo.h)\n\n```bash\npython generate_vcs.py \\\n--directory=./ \\\n--print \\\n--save \\\n--output=./ \\\n--debug \\\n--verbose=4\n```\n\n### Modbus JSON Generator\n\nGenerate a JSON file for the [Modbus wrapper](#modbus-wrapper) based on a\nheader file.\n\nThe header file, which might be included in some C project, is converted into\na JSON file which is useable by the onwards described\n[Modbus wrapper](#modbus-wrapper).\n\nA range or a unit can be given as a comment inside of squared brackets before\nthe actual description of this register, refer to\n[example/modbusRegisters.h](example/modbusRegisters.h). The default output file name is set as `register.json` and located in the same folder as the input file if no output file is specified or a folder is given.\n\nThis example call converts the modbus register header file\n`example/modbusRegisters.h` and saves the result as `modbusRegisters.json` in\nhuman readable and formatted style. It is not sorted to keep the same order as\nthe input file. An example output can be found at\n[example/modbusRegisters.h](example/modbusRegisters.h)\n\n```bash\npython generate_modbus_json.py \\\n--input=example/modbusRegisters.h \\\n--print \\\n--pretty \\\n--save \\\n--output=modbusRegisters.json \\\n--debug \\\n--verbose=4\n```\n\n### Modbus wrapper\n\nPerform read/write requests of modbus registers on TCP or RTU devices.\n\nThe unit of the device might be different, e.g. some commercial charging\nstations use `180` while ESP devices use `255` by default for TCP. The MyEVSE\nis using the bus address (unit) `10` on RTU.\n\n#### Reading data\n\nThis example call requests the data of all registers defined in the file of\n`example/modbusRegisters-phoenix.json` using either `tcp` (network) or `rtu`\n(serial) from a device with the unit (address) `180` (tcp case) or `10` (rtu\ncase) and saves the result as `result-modbusRegisters-phoenix-info.json` (tcp)\nor `result-modbusRegisters-info.json` (rtu) in human readable, formatted and\nsorted style. An example output can be found in the [example/](example/)\nfolder.\n\n##### Modbus TCP\n\n```bash\npython read_device_info_registers.py \\\n--file=example/modbusRegisters-phoenix.json \\\n--connection=tcp \\\n--address=192.168.178.188 \\\n--port=180 \\\n--print \\\n--pretty \\\n--save \\\n--output=result-modbusRegisters-phoenix-info.json \\\n--debug \\\n--verbose=4\n```\n\n##### Modbus RTU\n\n```bash\npython read_device_info_registers.py \\\n--file=example/modbusRegisters.json \\\n--connection=rtu \\\n--address=/dev/tty.wchusbserial1420 \\\n--unit=10 \\\n--baudrate=19200 \\\n--print \\\n--pretty \\\n--save \\\n--output=result-modbusRegisters-info.json \\\n--debug \\\n--verbose=4\n```\n\n#### Writing data\n\nThis example call sets the data of all registers defined in the file of\n`example/set-modbusRegisters-MyEVSE.json` using either `tcp` (network) or `rtu`\n(serial) on a device with the unit (address) `180` (tcp case) or `10` (rtu\ncase) and prints the result in human readable, formatted and sorted style.\n\n##### Modbus TCP\n\n```bash\npython3 write_device_info_registers.py \\\n--file=example/set-modbusRegisters-MyEVSE.json \\\n--connection=tcp \\\n--address=192.168.0.8 \\\n--port=180 \\\n--print \\\n--pretty \\\n--debug \\\n--verbose=4\n```\n\n##### Modbus RTU\n\n```bash\npython3 write_device_info_registers.py \\\n--file=example/set-modbusRegisters-MyEVSE.json \\\n--connection=rtu \\\n--address=/dev/tty.wchusbserial1420 \\\n--unit=10 \\\n--baudrate=19200 \\\n--print \\\n--pretty \\\n--debug \\\n--verbose=4\n```\n\n### Structure info generator\n\nCreate information file with the available info and target files in all\nsubdirectories in a specified path.\n\nThis example call creates a info about the folder structure at `./` and saves\nthe result as `structure-info.json` in human readable, formatted and\nsorted style. An example output can be found at\n[example/structure-info.json](example/structure-info.json)\n\n```bash\npython generate_structure_info.py \\\n--root=./ \\\n--print \\\n--pretty \\\n--save \\\n--output=structure-info.json \\\n--debug \\\n--verbose=4\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainelectronics%2Fpython-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainelectronics%2Fpython-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainelectronics%2Fpython-modules/lists"}