{ "info": { "author": "Anja Kleebaum, Stefan Holzheu, Oliver Archner", "author_email": "Anja.Kleebaum@stmail.uni-bayreuth.de", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python" ], "description": "# bayeosgatewayclient\nA Python package to transfer client (sensor) data to a BayEOS Gateway.\n\n![basic concept](https://github.com/kleebaum/bayeosgatewayclient/blob/master/writer-sender.png)\n\n## Installation\nYou can either use the setup.py script, the Python Package Index (PIP) or a Linux binary to install the package.\n\n### Setup.py\nDo the following steps to install the package via the setup.py script:\n- git clone request ```git clone git://github.com/kleebaum/bayeosgatewayclient.git```\n- find the right directory ```cd bayeosgatewayclient```\n- run ```python setup.py install``` as root\n\n### PIP\n- run ```pip install bayeosgatewayclient```\n\n### Linux Binary (for Debian)\n- add the following repositories to /etc/apt/sources.list ```deb http://www.bayceer.uni-bayreuth.de/repos/apt/debian wheezy main```\n- install key ```wget -O - http://www.bayceer.uni-bayreuth.de/repos/apt/conf/bayceer_repo.gpg.key | apt-key add -```\n- ```apt-get update```\n- ```apt-get install python-bayeosgatewayclient```\n\nAlternatively:\n- run ```dpkg -i python-bayeosgatewayclient_*_all.deb``` as root\n\n## Example usage\nImport the package ```import bayeosgatewayclient```.\n\n### Writer\nA simple writer looks like this:\n```\nfrom time import sleep\nfrom bayeosgatewayclient import BayEOSWriter\n\nwriter = BayEOSWriter('/tmp/bayeos-device1/')\nwriter.save_msg('BayEOS Writer was started.')\n\nwhile True:\n print 'adding frame\\n'\n writer.save([2.1, 3, 20.5])\n sleep(1)\n```\n\nA BayEOSWriter constructor takes the following arguments:\n```\nPATH = '/tmp/bayeos-device1/'\t# directory to store .act and .rd files\nMAX_CHUNK = 2000\t\t\t\t# file size in bytes\nMAX_TIME = 60\t\t\t\t\t# time when a new file is started in seconds\nwriter = BayEOSWriter(path=PATH, max_chunk=MAX_CHUNK, max_time=MAX_TIME)\n```\n\nThe following methods could also be of interest:\n- save integer values: ```writer.save(values=[1,2,3], value_type=0x22)```\n- save with channel indices: ```writer.save([[1,2.1], [2,3], [3,20.5]], value_type=0x41)``` or\n ```writer.save({1: 2.1, 2: 3, 3: 20.5}, value_type=0x41)```\n- save with channel offset: ```writer.save([2.1, 3, 20.5], value_type=0x02, offset=2)```\n- save origin: ```writer.save([2.1, 3, 20.5], origin='Writer-Example')```\n- save error message: ```writer.save_msg('error message', error=True)```\n- close current .act file and start a new one: ```writer.flush()```\n\n### Sender\nA simple sender looks like this:\n```\nfrom time import sleep\nfrom bayeosgatewayclient import BayEOSSender\n\nsender = BayEOSSender('/tmp/bayeos-device1/', \n\t\t\t\t\t 'Test-Device', \n\t\t\t\t\t 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat')\n\nwhile True:\n res = sender.send()\n if res > 0:\n print 'Successfully sent ' + str(res) + ' frames.'\n sleep(5)\n```\n\nA BayEOSSender constructor takes the following arguments:\n```\nPATH = '/tmp/bayeos-device1/'\t# directory to look for .rd files\nNAME = 'Test-Device'\nURL = 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat'\nUSER = 'import'\t\t\t\t\t# user name to access the BayEOS Gateway\nPASSWORD = 'import'\t\t\t\t# password to access the BayEOS Gateway\nBACKUP_PATH = '/home/.../' \t\t# backup path to store file if a) sending does not work \n\t\t\t\t\t\t\t\t or b) sending was successful but files but files \n\t\t\t\t\t\t\t\t shall be kept (renamed from .rd to .bak extension)\n\nsender = BayEOSSender(path=PATH, \n\t\t\t\t\t name=NAME, \n\t\t\t\t\t url=URL, \n\t\t\t\t\t password=PASSWORD,\n\t\t\t\t\t user=USER,\n\t\t\t\t\t absolute_time=True, # if true writer, else sender time is used\n\t\t\t\t\t remove=True,\t\t # .rd files deleted after successfully sent\n\t\t\t\t\t backup_path=BACKUP_PATH)\n```\n\nThe following methods could also be of interest:\n- substitute the loop: ```sender.run(sleep_sec=5)```\n- start sender as a separate thread ```sender.start(sleep_sec=5)```\n- start sender as a separate process ```sender.start(sleep_sec=5, thread=False)```\n\n### Connect writer and sender\nUsually, the writer and sender are operating concurrently, although they are not\nlinked directly, i. e., they only share the same directory. \n\nA simple script to connect one writer-sender pair looks like this:\n```\nfrom bayeosgatewayclient import BayEOSWriter, BayEOSSender\n\nPATH = '/tmp/bayeos-device/'\nNAME = 'Writer-Sender-Example'\nURL = 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat'\n\nwriter = BayEOSWriter(PATH)\nwriter.save_msg('Writer was started.')\n\nsender = BayEOSSender(PATH, NAME, URL)\nsender.start() \t# sender runs in a concurrent thread\n\nwhile True:\n print 'adding frame'\n writer.save([2.1, 3, 20.5])\n sleep(5)\n```\n\nAnother way to combine writer-sender pairs is using the BayEOSGatewayClient class:\n```\nfrom bayeosgatewayclient import BayEOSGatewayClient\n\nOPTIONS = {'bayeosgateway_url' : 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat',\n 'bayeosgateway_password' : 'import',\n 'bayeosgateway_user' : 'import'}\n\nNAMES = ['PythonTestDevice1', 'PythonTestDevice2', 'PythonTestDevice3']\n\nclass PythonTestDevice(BayEOSGatewayClient):\n \"\"\"Creates both a writer and sender instance for every NAME in NAMES. Implements BayEOSGatewayClient.\"\"\"\n def read_data(self):\n \t\"\"\"Must be overwritten.\"\"\"\n if self.name == 'PythonTestDevice1':\n return (2.1, 3, 20.5)\n else:\n return (42)\n \n def save_data(self, data=0, origin=''):\n \t\"\"\"Can be overwritten.\"\"\"\n if self.name == 'PythonTestDevice1':\n self.writer.save(data, origin='origin')\n self.writer.save_msg('Overwritten method.')\n elif self.name == 'PythonTestDevice2':\n self.writer.save(data)\n\nclient = PythonTestDevice(NAMES, OPTIONS)\n\nclient.run()\n```\n\n### Parsing command line arguments\nConstructor arguments can be passed as command line arguments:\n\nlong option \t| short option\t| description\n----------------|---------------|-------------------------\n\u2212\u2212name\t\t\t|-n\t\t\t\t|name to appear in Gateway\n\u2212\u2212path\t\t\t|-p\t\t\t\t|path to store writer files before they are sent\n\u2212\u2212max-chunk\t\t|-m\t\t\t\t|maximal file size [bytes] before a new file is started\n\u2212\u2212writer-sleep\t|-ws\t\t\t|writer sleep time [seconds]\n\u2212\u2212sender-sleep\t|-ss\t\t\t|sender sleep time [seconds]\n\u2212\u2212password\t\t|-pw\t\t\t|password to access BayEOS Gateway\n\u2212\u2212user\t\t\t|-un\t\t\t|user name to BayEOS Gateway\n\u2212\u2212url \t\t\t|-u\t\t\t\t|URL to access BayEOS Gateway\n\n```\nfrom bayeosgatewayclient import BayEOSWriter, bayeos_argparser\nargs = bayeos_argparser('This text appears on the command line.')\n\nWRITER_SLEEP = float(args.writer_sleep)\nMAX_CHUNK = float(args.max_chunk)\nwriter = BayEOSWriter(max_chunk=MAX_CHUNK)\n\nwhile True:\n writer.save([42, 20.5], value_type=0x21)\n sleep(WRITER_SLEEP)\n```\n\nThat is what could appear on the command line:\n```python2.7 example_script.py -m 2560 -ws 5```\n\n### Parsing config files\nFirst, a config file has to be created, e.g.:\n```\n; Sample Config file for bayeosgatewayclient\n\n[Overall]\nname = Test-Device\npath = /tmp/bayeos-device\n\n[Writer]\nmax_time = 100\nmax_chunk = 2000\nwriter_sleep_time = 1\n\n[Sender]\nsender_sleep_time = 10\nurl = http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveMatrix\nbayeosgateway_user = import\nbayeosgateway_pw = import\nabsolute_time = True\nremove = False\nbackup_path = /home/pi/backup/\n```\n\nSecond, the Python script needs to invoke the ```bayeos_confparser(config_file)``` method.\n\n```\nfrom bayeosgatewayclient import BayEOSWriter, BayEOSSender, bayeos_confparser\nconfig = bayeos_confparser('config')\n\nwriter = BayEOSWriter(config['path'], config['max_chunk'])\nsender = BayEOSSender(config['path'])\n```\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "bayeos gateway client", "license": "GPL2", "maintainer": null, "maintainer_email": null, "name": "bayeosgatewayclient", "package_url": "https://pypi.org/project/bayeosgatewayclient/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/bayeosgatewayclient/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/bayeosgatewayclient/0.2.6/", "requires_dist": null, "requires_python": null, "summary": "Transfers client data to a BayEOS Gateway.", "version": "0.2.6" }, "last_serial": 1945591, "releases": { "0.2.6": [ { "comment_text": "", "digests": { "md5": "06dd7a8b6d47e696f0b68a9af65ff0af", "sha256": "e163c0c07fb5b0328cb91e94fe56abb09ae5bbbec7912eeaf315f5adc5e30095" }, "downloads": -1, "filename": "bayeosgatewayclient-0.2.6.tar.gz", "has_sig": false, "md5_digest": "06dd7a8b6d47e696f0b68a9af65ff0af", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18128, "upload_time": "2016-02-08T13:29:19", "url": "https://files.pythonhosted.org/packages/08/b6/195b9a8e0825227b3a05ea67ff1865ee0f58d13f0c2a1ce2c2940ce9091f/bayeosgatewayclient-0.2.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "06dd7a8b6d47e696f0b68a9af65ff0af", "sha256": "e163c0c07fb5b0328cb91e94fe56abb09ae5bbbec7912eeaf315f5adc5e30095" }, "downloads": -1, "filename": "bayeosgatewayclient-0.2.6.tar.gz", "has_sig": false, "md5_digest": "06dd7a8b6d47e696f0b68a9af65ff0af", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18128, "upload_time": "2016-02-08T13:29:19", "url": "https://files.pythonhosted.org/packages/08/b6/195b9a8e0825227b3a05ea67ff1865ee0f58d13f0c2a1ce2c2940ce9091f/bayeosgatewayclient-0.2.6.tar.gz" } ] }