├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.rst ├── osc2mqtt.ini ├── osc2mqtt ├── __init__.py ├── __main__.py ├── converter.py ├── lru_cache.py └── util.py ├── parse_requirements.py ├── requirements.txt ├── setup.cfg ├── setup.py └── start.sh /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | dist/ 3 | misc/ 4 | __pycache__/ 5 | *.egg-info/ 6 | *.py[cod] 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Christopher Arndt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.rst 2 | include CONTRIBUTING.rst 3 | include HISTORY.rst 4 | include LICENSE 5 | include README.rst 6 | include osc2mqtt.ini 7 | include parse_requirements.py 8 | include requirements.txt 9 | include start.sh 10 | 11 | recursive-include tests * 12 | recursive-exclude * __pycache__ 13 | recursive-exclude * *.py[co] 14 | 15 | recursive-include docs *.rst conf.py Makefile make.bat -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | osc2mqtt 2 | ######## 3 | 4 | An OSC_ to MQTT_ bridge based on pyliblo_ and `paho-mqtt`_. 5 | 6 | Quick Start 7 | ----------- 8 | 9 | 1. ``pip install cython osc2mqtt`` 10 | 2. Get osc2mqtt.ini_ and edit the ``options`` section and set your MQTT broker 11 | host and port and, optionally, an OSC host and port as a reveiver. 12 | 3. Run ``osc2mqtt -v`` and start publishing MQTT messages or sending OSC 13 | messages to ``udp://localhost:9001/``. 14 | 4. Watch debugging output for the MQTT topics, OSC addresses and the kind of 15 | MQTT message payload and OSC arguments the messages have. 16 | 5. Add conversion rules to ``osc2mqtt.ini`` as needed. The `DEFAULT` section 17 | has helpful comments. Also change the ``subscriptions`` option to only 18 | receive the MQTT messages you're interested in. 19 | 6. Quit ``osc2mqtt`` with Control-C and restart it to try out your new 20 | configuration. Repeat from step 4, if necessary. 21 | 22 | .. _osc: http://opensoundcontrol.org/ 23 | .. _mqtt: http://mqtt.org/ 24 | .. _paho-mqtt: https://www.eclipse.org/paho/clients/python/ 25 | .. _pyliblo: http://das.nasophon.de/pyliblo/ 26 | .. _osc2mqtt.ini: https://github.com/SpotlightKid/osc2mqtt/blob/master/osc2mqtt.ini 27 | -------------------------------------------------------------------------------- /osc2mqtt.ini: -------------------------------------------------------------------------------- 1 | [options] 2 | ; Comma-separated list of MQTT topic filters to subscribe to, e.g. 3 | # subscriptions = licht/+/+, schalter/+/+, +/xy/+ 4 | subscriptions = # 5 | osc_port = 9001 6 | ; OSC reveiver host[:port], supports UDP multicast too 7 | osc_receiver = 8 | ; MQTT broker host[:port] 9 | mqtt_broker = localhost:1883 10 | verbose = false 11 | 12 | ; Defaults for conversion rules sections below 13 | [DEFAULT] 14 | ; Plain string or regular expression matching MQTT topic or OSC address. 15 | ; If a regular expression, may contain named or unnamed substring groups. 16 | ; See the comments for the 'address_groups' and 'topic_groups' settings below. 17 | ; In the example here, everything after the optional slash prefix is group 1 18 | match = ^/?(.*) 19 | 20 | ; OSC address, a plain string, optionally with string formatting placeholders. 21 | ; Placeholders may reference groups from the regular expression set with 22 | ; 'match' above and will be replaced with what the respective group matched to. 23 | ; Matches by unnamed regular expression groups are passed as positional 24 | ; arguments to the formatting function and named groups as keyword arguments. 25 | ; Additionally, values decoded from the MQTT payload are passed as a tuple via 26 | ; the '_values' keyword argument and thus can be inserted in to the OSC address 27 | ; with e.g. '{_values[0]}'. 28 | ; See the conversion rules below for a usage example. 29 | ; The default value here in combination with 'match' regular expression above 30 | ; adds a slash prefix to the MQTT topic, if there wasn't one already. 31 | address = /{0} 32 | 33 | ; MQTT topic, a plain string, optionally with string formatting placeholders. 34 | ; Placeholders may reference groups from the regular expression set with 35 | ; 'match' above and will be replaced the what the respective group matched to. 36 | ; Matches by unnamed regular expression groups are passed as positional 37 | ; arguments to the formatting function and named groups as keyword arguments. 38 | ; Additionally, values from the OSC message are passed as a tuple via the 39 | ; '_values' keyword argument and thus can be inserted in to the MQTT topic with 40 | ; e.g. '{_values[0]}'. 41 | ; See the conversion rules below for a usage example. 42 | ; The default value here in combination with 'match' regular expression above 43 | ; removes the slash prefix from the OSC address. 44 | topic = {0} 45 | 46 | ; Comma-separated list of group names (unnamed groups are not supported). 47 | ; Values in the OSC message's address string matched by the named regex 48 | ; groups listed here will be appended to the OSC values of the message 49 | ; before encoding the values to the MQTT message payload. 50 | ; Only the values matched by the groups listed here will be appended 51 | ; and in the order given here. The value for groups with no matches will 52 | ; be None. 53 | address_groups = 54 | 55 | ; Comma-separated list of group names (unnamed groups are not supported). 56 | ; Values in the MQTT message's topic string matched by the named regex 57 | ; groups listed here will be appended to the values decoded from the 58 | ; the MQTT message payload before converting them to OSC values; 59 | ; Only the values matched by the groups listed here will be appended 60 | ; and in the order given here. The value for groups with no matches will 61 | ; be None. 62 | topic_groups = 63 | 64 | ; MQTT payload encoding type. 65 | ; One of: array, json, string, struct 66 | type = struct 67 | 68 | ; MQTT payload encoding format. 69 | ; 70 | ; When type = struct, must be a struct.unpack() format string, e.g.: 71 | # format = B ; one unsigned byte 72 | # format = \w+)/xy(?P/?\d+)? 122 | topic = {page}/xy{pad} 123 | address = /{page}/xy{pad} 124 | format = >ff 125 | 126 | [:button] 127 | ; An example for extracting values for the MQTT payload from the OSC address 128 | ; and setting the OSC address based on values from the MQTT payload: 129 | ; 130 | ; OSC address:/page1/button1/1 values:[] 131 | ; --> MQTT topicpage1/button payload:'\x01' 132 | ; OSC address:/page1/button1/2 values:[] 133 | ; --> MQTT topic:page1/button payload:'\x02' 134 | ; etc. 135 | match = ^/?(?P\w+)/(?P