{"id":16626169,"url":"https://github.com/xlfe/pjon-cython","last_synced_at":"2025-07-07T13:39:30.174Z","repository":{"id":57453203,"uuid":"139936050","full_name":"xlfe/PJON-cython","owner":"xlfe","description":"Call the PJON C++ library directly from Python","archived":false,"fork":false,"pushed_at":"2020-12-28T10:39:58.000Z","size":363,"stargazers_count":9,"open_issues_count":2,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-02T05:51:15.438Z","etag":null,"topics":["communication-library","cython","iot","multi-master","onewire","pjon","pjon-library","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xlfe.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}},"created_at":"2018-07-06T05:12:02.000Z","updated_at":"2023-07-17T01:08:38.000Z","dependencies_parsed_at":"2022-08-29T10:41:40.799Z","dependency_job_id":null,"html_url":"https://github.com/xlfe/PJON-cython","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlfe%2FPJON-cython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlfe%2FPJON-cython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlfe%2FPJON-cython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlfe%2FPJON-cython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xlfe","download_url":"https://codeload.github.com/xlfe/PJON-cython/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238920874,"owners_count":19552674,"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":["communication-library","cython","iot","multi-master","onewire","pjon","pjon-library","python"],"created_at":"2024-10-12T04:08:57.701Z","updated_at":"2025-02-14T22:32:55.988Z","avatar_url":"https://github.com/xlfe.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PJON-cython\n\nCall the PJON C++ library directly from Python 2 or Python 3 (via [Cython](http://cython.org/))\n\nPJON (Github: [PJON](https://github.com/gioblu/PJON/) ) is an open-source, multi-master, multi-media (one-wire, two-wires, radio) communication protocol available for various platforms (Arduino/AVR, ESP8266, Teensy).\n\nPJON is one of very few open-source implementations of multi-master communication protocols for microcontrollers.\n\n\n## PJON-cython vs PJON-python\n\n**PJON-cython** allows you to use the C++ PJON library from Python via Cython (C++ wrappers for Python) while\n**PJON-python** is a re-implementation of the PJON protocol in Python\n\n## Current status:\n\nSupport for PJON 12 and the following strategies :-\n- LocalUDP\n- GlobalUDP\n- ThroughSerial\n- ThroughSerialAsync\n\nNote\n\n- PJON-cython versions are aligned with PJON versions to indicate compatibility with C implementation for uC platforms.\n\n#### Python support\n\nPython 2.7, 3.4, 3.5, 3.6 and 3.7 are tested and considered supported\n\n#### Platform support\n\nLinux and Mac OS X are considered supported. Windows is not supported (sorry!).\n\n## Install from pip\n\nCurrent version is 12.0.0\n\n```bash\npip install pjon-cython\n```\n\n## Testing\n\n```bash\n$(which python) setup.py nosetests --with-doctest --doctest-extension=md\n```\n\n## GlobalUDP example\n\n```python\n\u003e\u003e\u003e import pjon_cython as PJON\n\u003e\u003e\u003e class GlobalUDP(PJON.GlobalUDP):\n...     # you can overload __init__ if you want\n...     def __init__(self, device_id):\n...         PJON.GlobalUDP.__init__(self, device_id)\n...         self.packets_received = 0\n...     def receive(self, data, length, packet_info):\n...         print (\"Recv ({}): {}\".format(length, data))\n...         print (packet_info)\n...         self.packets_received += 1\n...         self.reply(b'P')\n\n\u003e\u003e\u003e g = GlobalUDP(44)\n\u003e\u003e\u003e idx = g.send(123, b'HELO')\n\u003e\u003e\u003e # calling loop calls the PJON bus.update() and bus.receive()\n\u003e\u003e\u003e # and the return is the results of those functions -\n\u003e\u003e\u003e packets_to_send, receive_status = g.loop()\n\u003e\u003e\u003e # packets_to_send is the Number of packets in the PJON buffer\n\u003e\u003e\u003e packets_to_send\n1\n\u003e\u003e\u003e #PJON constants are available too\n\u003e\u003e\u003e receive_status == PJON.PJON_FAIL\nTrue\n\u003e\u003e\u003e # When you're done with your PJON interface, you can cleanup the connection by deleting it\n\u003e\u003e\u003e del g\n\n```\n\n## Through Serial example\n\n```python\n\u003e\u003e\u003e import pjon_cython as PJON\n\u003e\u003e\u003e #ThroughSerial Example\n\u003e\u003e\u003e # Make sure you set self.bus.set_synchronous_acknowledge(false) on the other side\n\u003e\u003e\u003e \n\u003e\u003e\u003e class ThroughSerial(PJON.ThroughSerial):\n...\n...     def receive(self, data, length, packet_info):\n...        if data.startswith(b'H'):\n...            print (\"Recv ({}): {} - REPLYING\".format(length, data))\n...            self.reply(b'BONZA')\n...        else:\n...            print (\"Recv ({}): {}\".format(length, data))\n...        print ('')\n...\n\u003e\u003e\u003e # Put your actual serial device in here...\n\u003e\u003e\u003e ts = ThroughSerial(44, b\"/dev/null\", 115200)\n\u003e\u003e\u003e # Send returns the packet's index in the packet buffer\n\u003e\u003e\u003e ts.send(100, b'PING 1')\n0\n\u003e\u003e\u003e ts.send(100, b'PING 2')\n1\n\u003e\u003e\u003e # Error handling happens through exceptions such as PJON.PJON_Connection_Lost\n\u003e\u003e\u003e while True:\n...     packets_to_send, receive_status = ts.loop()\nTraceback (most recent call last):\n    ...\npjon_cython._pjon_cython.PJON_Connection_Lost\n\n```\n\n\n## Setting configurable properties\n\n```python\n\u003e\u003e\u003e import pjon_cython as PJON\n\u003e\u003e\u003e class GlobalUDP(PJON.GlobalUDP):\n...     def receive(self, data, length, packet_info):\n...         print (\"Recv ({}): {}\".format(length, data))\n\n\u003e\u003e\u003e # GlobalUDP and LocalUDP both support set_port to configure their UDP listening port\n\u003e\u003e\u003e g = GlobalUDP(99, 8821)\n\u003e\u003e\u003e del g\n\u003e\u003e\u003e #They return the class object, so you can \"chain them\"\n\u003e\u003e\u003e pjon = GlobalUDP(100,8821).set_autoregistration(False)\n\u003e\u003e\u003e pjon                                                            # doctest: +ELLIPSIS\n\u003cGlobalUDP object at 0x...\u003e\n\u003e\u003e\u003e\n\u003e\u003e\u003e # These options affect packet overhead (in bytes)\n\u003e\u003e\u003e pjon.packet_overhead()\n6\n\u003e\u003e\u003e pjon.set_crc_32(True).packet_overhead()\n9\n\u003e\u003e\u003e pjon.set_packet_id(True).packet_overhead()\n11\n\u003e\u003e\u003e pjon.set_synchronous_acknowledge(True).packet_overhead()\n11\n\u003e\u003e\u003e pjon.set_packet_id(False).set_asynchronous_acknowledge(False).packet_overhead()\n9\n\u003e\u003e\u003e pjon.set_crc_32(False).include_sender_info(False).packet_overhead()\n5\n\n```\n\n#### Use serial based strategies with [pyserial_Asyncio](https://github.com/pyserial/pyserial-asyncio)\n\nInstead of passing a serial port string, you can pass a file descriptor to the ThroughSerial and ThroughSerialAsync \nmethods which allows other libraries to poll the serial port.\n\nFor examples, see the [reticul8](https://github.com/xlfe/reticul8/blob/master/python/reticul8/pjon_strategies.py#L27)\nproject.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlfe%2Fpjon-cython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxlfe%2Fpjon-cython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlfe%2Fpjon-cython/lists"}