{ "info": { "author": "Takeyuki UEDA", "author_email": "gde00107@nifty.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Programming Language :: Python", "Topic :: Terminals" ], "description": "# pondslider\n\nMultipurpose sensor handler, read sensor & do somethings (send, save, trigger, ...) with the value.\n\n## What is pondslider\nThe pondslider is a python module to read sensor values by Sensor handler, and do somethins with the value by Value handler.\n\n\n\n### What is pondslider for?\nThe pondslider is for making sensor application quickly by ***reusing existing codes***. \n- Reusing existing ***Sensor reading*** code through ***unified interface*** provided by ***Sensor handler*** mention later.\n- Reusing existing ***Value handling*** code through ***unified interface*** provided by ***Value handler*** mention later.\n\n\n### How the pondslider work?\nFirst, the pondslider read a configration file to specify:\n\n- Which sensors shoul be read.\n- Which values are returned by specific sensor.\n- What shoud it do for each value.\n\nThen, pondslider get sensor values through specific ***sensor handlers***, and call ***value handlers*** which is related.\n\n### What is Sensor handler?\nThe Sensor handler is a python module which wrap existing sensor reading code having various interface, to provide unified interface as follows:\n\n- unified read() function:\n Sensor handler unifies various function call of sensor value reading on the existing codes as ***read()***\n\n- well-formed return value:\n The ***read()*** function return a python dictionally of ***name*** and ***value*** pairs as follow:\n\n``` {'humiditydeficit': 15.9, 'temp': 26.8, 'humidity': 37.6}```\n\n\n\nThankfully, there are huge open source code base written by capable and benign engineers on the github, pypi and other repositories. In my experience, it' very rare to face a situation of the necessity of writing a code to readi a sensor value myself, insted I can find reusable code of most sensors easily and use it gratefully. But also there are wide variety of the interface of these code and form of result, so I just need to make wrapper code to adapt interface.\nThe Sensor handler is just these code of wrapping these pre-existing valuable code to provide unified interface.\n\nTypically, a sensor handler is created as a wrapper module of exising python module with ***import*** and call there function to read sensor value as follow:\n\n```python:\n# import existing module\nimport SomethingExistingSensorModule\n\n#####################################\n#\n# unified read() interface\n#\n\ndef read():\n \n # prepare existing module\n a_sensor = SomethingExistingSensorModule.new()\n\n # call there function to read sensor value \n values = a_sensor.there_func_to_read_sensor()\n\n # re-format to name-value pair.\n return adjust_the_format(values)\n\ndef adjust_the_format(value)\n ''' adjst the format of value as a dictionaly of name & value pair. '''\n\n```\n\nIn other case, with external executable file,\n\n```python:\n# import python standard external executable handle module\nimport subprocess\n\ndef read():\n\n # call external executable and get return strings\n p = subprocess.Popen(\"./SomethingExistingExecutable2GetSensorValue\",\n stdout=subprocess.PIPE,\n stderr=subprocess.PIPE, \n shell=True)\n std_out, std_err = p.communicate(None, timeout=20)\n value = std_out.strip()\n\n # re-format to name-value pair.\n return adjust_the_format(value)\n\ndef adjust_the_format(value)\n ''' adjst the format of value as a dictionaly of name & value pair. '''\n\n```\n\nOf cource, It's OK to make Sensor handler as reading sensor value directory.\n\n```python:\nimport serial\n\ndef read():\n # mh-z19 CO2 sensor https://github.com/UedaTakeyuki/mh-z19\n try:\n ser = serial.Serial(serial_dev,\n baudrate=9600,\n bytesize=serial.EIGHTBITS,\n parity=serial.PARITY_NONE,\n stopbits=serial.STOPBITS_ONE,\n timeout=1.0)\n while 1:\n result=ser.write(\"\\xff\\x01\\x86\\x00\\x00\\x00\\x00\\x00\\x79\")\n s=ser.read(9)\n if len(s) >= 4 and s[0] == \"\\xff\" and s[1] == \"\\x86\":\n return {'co2': ord(s[2])*256 + ord(s[3])}\n break\n except:\n traceback.print_exc()\n\n```\n\n### What is Value handler?\nThe Value handler is a python module which recieve sensor value, and do something with it, for example, send to server, write to strage, and so on.\nThe purpose of valule handler is to provide a unified interface to handle acquired sensor value with following interface:\n\n```python:\ndef handle(sensor_hander, data_name, value):\n```\n\n\n## example handlers\nexample of handlers are available at https://github.com/UedaTakeyuki/handlers\n\n\n## install\n\n```bash:\npip install pondslider\n```\n\n## installs\n[![Downloads](https://pepy.tech/badge/pondslider)](https://pepy.tech/project/pondslider)\n[![Downloads](https://pepy.tech/badge/pondslider/month)](https://pepy.tech/project/pondslider)\n[![Downloads](https://pepy.tech/badge/pondslider/week)](https://pepy.tech/project/pondslider)\n\n## How to set Sensor and Value handlers\n\nThere are 2 way to set handers. One is to use command-line option, the other is [TOML](https://github.com/toml-lang/toml) formatted config file.\nIn case both config and command-line option is set, the pondslider handle also both in the order config file first, then command-line.\n\nFor the way to specify a various handlers in the various package & directory, please refer [\"How to specify a handler package in the various package & directory hierarchies\".](https://github.com/UedaTakeyuki/pondslider/wiki/How-to-specify-a-handler-package-in-the-various-package-&-directory-hierarchies.)\n\n### Set Sensor and Value handlers by command-line option\nThe Sensor handlers can be set by command-line option ***--sensor_handlers***.\nThis is list type command-line option, you can specify nesessary sensor handlers module like mh-z19 and dht22 as follows:\n\n```\n--sensor_handlers mh_z19 dht22\n```\n\nFor the value handlers also has similar command-line option ***--value_handlers***.\nFor example, spesify modules of ***sender.monitor.send*** and ***saver.strage.save*** as follows:\n\n```\n--value_handlers sender.monitor.send saver.strage.save\n```\n\nEach value handlers ***handle()*** functions is called with ***All*** value red from ***All*** Sensor handlers. In case you need to call corresponding value handler with ***ONLY*** corresponding value, you shoud check value name and value handler module which passed as function parameter of handle(), like as follow.\n\n```python:\ndef handle(data_source_name, data_name, value):\n if data_name is \"co2\":\n # do something\n else:\n # do nothing\n pass\n``` \n\nOr, use config file mention later, which can relate value and value handler one to one.\n\n\n### Set Sensor and Value handlers by [TOML](https://github.com/toml-lang/toml) formatted config file.\n\nYou can specify one to one relation with which sensor handler's which value and corresponding value handler, by config file. \nThe contents are expected as follows:\n\n```\n[[sensors]]\n handler = \"dht22\"\n [[sensors.values]]\n name = \"temp\"\n handlers = [\n \"send\",\n \"save\"\n ]\n [[sensors.values]]\n name = \"humidity\"\n handlers = [\n \"send\",\n \"save\"\n ]\n [[sensors.values]]\n name = \"humiditydeficit\"\n handlers = [\n \"send\",\n \"save\"\n ]\n\n\n[[sensors]]\n handler = \"mh-z19\"\n [[sensors.values]]\n name = \"co2\"\n handlers = [\n \"send\",\n \"save\"\n ]\n```\n\nThe config file of pondslider consist of an array of table ***[[sensors]]***.\nThe pondslider read this array, then read each sensor handler and call corresponding value handler.\n\nThe element of ***sensors*** have a couple of keys, the one is ***handler*** which indicate corresponding Sensor handler, the other is ***[[sensors.values]]*** which indicate corresponding Value handlers.\n\n***[[sensors.values]]*** have also a couple of kyes, the one is ***name*** which indicate correcponding red sensor value name, which is the key of the dictionally of Sensor handlers ***read()*** function's return. The others are ***handlers*** array which indicate value handler module. The ***handle()*** funcitons of these handler are called ***Only*** with the red sensor value which has same ***name***, unlike the valuehandlers specified by command-line option ***value_handlers*** is called with ***All*** value red from ***All*** Sensor handlers.\n\nThe config file is specified by command-line option ***--config***. With out --config option, the pondslider search the file named ***config.toml*** on the current working directory and use it if found.\n\n### Add python module search path\nIn case your handler module is not linked by standard python module search path, you can tell the pondslider to add search path by command-line option ***--imppaths*** as follows:\n\n```bash:\n --imppaths IMPPATHS [IMPPATHS ...]\n list of full path for python modules import path like\n as \"/home/pi/mh-z19 /tmp/handler\" .\n``` \n\nFor example, in case your mh-z19 sensor handler is in /home/pi/mh-z19 and your send handler is in /home/pi/handlers/send.py, you can read mh-z19 and send the value as follows:\n\n```\nsudo python -m pondslider --sensor_handlers mh_z19 --value_handlers sender.monitor.send --imppaths /home/pi/mh-z19 /home/pi/handlers\n```\n\nNote, mh-z19 need to read serial interface and it might be necessary of sudo.\n\n## How to use \n### as python program.\n\n```bash:\nusage: python -m pondslider [-h] [--config CONFIG] [--imppaths IMPPATHS [IMPPATHS ...]]\n [--interval INTERVAL]\n [--sensor_handlers SENSOR_HANDLERS [SENSOR_HANDLERS ...]]\n [--value_handlers VALUE_HANDLERS [VALUE_HANDLERS ...]]\n [--terminators TERMINATORS [TERMINATORS ...]]\n\noptional arguments:\n -h, --help show this help message and exit\n --config CONFIG config file for handler specification.\n --imppaths IMPPATHS [IMPPATHS ...]\n list of full path for python modules import path like\n as \"/home/pi/mh-z19 /tmp/handler\" .\n --interval INTERVAL minute of interval to repeat. no repeat in case not\n set.\" .\n --sensor_handlers SENSOR_HANDLERS [SENSOR_HANDLERS ...]\n list of sensor handler modules as \"sensor.mh-z19\n dht22\" .\n --value_handlers VALUE_HANDLERS [VALUE_HANDLERS ...]\n list of value handler modules as \"sender.monitor.send\n saver.strage.save\" .\n --terminators TERMINATORS [TERMINATORS ...]\n list of terminator modules.\n```\nThe path specified by --imppaths is used ad additional Python import library path.\nWith --interval option, pondslider repeat it in specified interval minutes. Without --interval, just run one time and quit.\n\n\n### as python library.\n\n```python:\nimport pondslider\n\nprint (pondslider.read(config_file_path))\n```\n## Q&A\nAny questions, suggestions, reports are welcome! Please make [issue](https://github.com/UedaTakeyuki/pondslider/issues) without hesitation! \n\n## history\n- 0.1.1 2018.11.03 first version self-forked from [sensorhandler](https://github.com/UedaTakeyuki/sensorhandler).\n- 0.2.1 2018.11.06 add --interval option.\n- 0.2.2 2018.11.06 minor fix: remove redundant print\n- 0.3.1 2018.11.07 add --sensor_handlers and --value_handlers\n- 0.3.7 2018.11.19 fix missing requires\n- 0.4.1 2018.12.02 add terminators\n- 0.4.2 2018.12.06 fix --interval option", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/UedaTakeyuki/pondslider", "keywords": "sensor,IoT", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pondslider", "package_url": "https://pypi.org/project/pondslider/", "platform": "", "project_url": "https://pypi.org/project/pondslider/", "project_urls": { "Homepage": "https://github.com/UedaTakeyuki/pondslider" }, "release_url": "https://pypi.org/project/pondslider/0.4.2/", "requires_dist": null, "requires_python": "", "summary": "Multipurpose sensor handler, read sensor & do somethings (send, save, trigger, ...) with the value.", "version": "0.4.2" }, "last_serial": 4567546, "releases": { "0.1.4": [ { "comment_text": "", "digests": { "md5": "1865d14b9c8d2676d2c905fdfef88be5", "sha256": "41f703eb2c77c041c3d10e90a5e55923851cf6cf46bc86a0ad217364c4932784" }, "downloads": -1, "filename": "pondslider-0.1.4.tar.gz", "has_sig": false, "md5_digest": "1865d14b9c8d2676d2c905fdfef88be5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4608, "upload_time": "2018-11-04T08:11:24", "url": "https://files.pythonhosted.org/packages/e2/aa/64503a45577efe6f9eb958f7e05100661678b93398952ce3adffd66c28c1/pondslider-0.1.4.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "368b3dec42e01c0848491b748c768289", "sha256": "d39bb59e57d6221549be04394b2fe2d64a3688bf3f74460a013ae70e1da2920f" }, "downloads": -1, "filename": "pondslider-0.2.2.tar.gz", "has_sig": false, "md5_digest": "368b3dec42e01c0848491b748c768289", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4916, "upload_time": "2018-11-06T11:26:26", "url": "https://files.pythonhosted.org/packages/de/60/abfc3f1df10240d72fc4a04f7b38ffae0cb768ad9247eb5a0f6e6d880735/pondslider-0.2.2.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "9a3f145dfdfaf6323ec27c79a7e71b03", "sha256": "646a5380070a3a09d2343fdf250a9cb2b48ba20937f9aef4423a61789cb30a29" }, "downloads": -1, "filename": "pondslider-0.3.1.tar.gz", "has_sig": false, "md5_digest": "9a3f145dfdfaf6323ec27c79a7e71b03", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6367, "upload_time": "2018-11-08T02:23:11", "url": "https://files.pythonhosted.org/packages/5a/b4/aa390d6c596b49136c50ded613a32b0313b481e2070986b780dc8d1629f4/pondslider-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "f50b80f0bb84d39a78ffc5d2ba1f6e7e", "sha256": "7bebc810def732f2703257fcb95ae9f3887335e1902b08cc890aabd170033b79" }, "downloads": -1, "filename": "pondslider-0.3.2.tar.gz", "has_sig": false, "md5_digest": "f50b80f0bb84d39a78ffc5d2ba1f6e7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5691, "upload_time": "2018-11-19T13:46:39", "url": "https://files.pythonhosted.org/packages/5c/69/4a334994c51326db8a74d5aba9cfe591a47b3de8500aaf9cd3654243fa29/pondslider-0.3.2.tar.gz" } ], "0.3.7": [ { "comment_text": "", "digests": { "md5": "b06008e3ef42d043146c3c413896e311", "sha256": "9004e568fd50e545b240c93b6a3ab156df714cd9e55b1c061e97eb0814f2ef51" }, "downloads": -1, "filename": "pondslider-0.3.7.tar.gz", "has_sig": false, "md5_digest": "b06008e3ef42d043146c3c413896e311", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6547, "upload_time": "2018-11-19T14:27:42", "url": "https://files.pythonhosted.org/packages/86/14/3363c781c7183a734feee018ecad4b727deed748dc4997db4e31c6f4683c/pondslider-0.3.7.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "cf7d90b444132f753e4b7675a9d8422c", "sha256": "416f3bc46eedf7d9bce201d3f928c04824463f910ba2ea6a60222d478051fedf" }, "downloads": -1, "filename": "pondslider-0.4.1.tar.gz", "has_sig": false, "md5_digest": "cf7d90b444132f753e4b7675a9d8422c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6926, "upload_time": "2018-12-02T09:04:02", "url": "https://files.pythonhosted.org/packages/1a/21/37ffd6b957eaf35c90b170f5e5d3c7efa82de0832054feb92fc67b85ed15/pondslider-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "a5922d0a13b5d57e20d51850fe086e1d", "sha256": "f1ceecdd7fc073e1b714f15ce600c1f2de185a7e1e484ec4743a5aaa2c57e763" }, "downloads": -1, "filename": "pondslider-0.4.2.tar.gz", "has_sig": false, "md5_digest": "a5922d0a13b5d57e20d51850fe086e1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6936, "upload_time": "2018-12-06T11:28:25", "url": "https://files.pythonhosted.org/packages/e3/08/1cab157d5477497f0c44afdd289ff3e77281c7fbe6437f0d050100c39702/pondslider-0.4.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a5922d0a13b5d57e20d51850fe086e1d", "sha256": "f1ceecdd7fc073e1b714f15ce600c1f2de185a7e1e484ec4743a5aaa2c57e763" }, "downloads": -1, "filename": "pondslider-0.4.2.tar.gz", "has_sig": false, "md5_digest": "a5922d0a13b5d57e20d51850fe086e1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6936, "upload_time": "2018-12-06T11:28:25", "url": "https://files.pythonhosted.org/packages/e3/08/1cab157d5477497f0c44afdd289ff3e77281c7fbe6437f0d050100c39702/pondslider-0.4.2.tar.gz" } ] }