diff --git a/can2mqtt.egg-info/PKG-INFO b/can2mqtt.egg-info/PKG-INFO new file mode 100644 index 0000000..5a4b6d8 --- /dev/null +++ b/can2mqtt.egg-info/PKG-INFO @@ -0,0 +1,60 @@ +Metadata-Version: 2.2 +Name: can2mqtt +Version: 0.0.1 +Summary: A python can to mqtt bridge +Home-page: https://github.com/tillsc/can2mqtt +Author: Till Schulte-Coerne +Author-email: till.schulte-coerne@innoq.com +Project-URL: Bug Reports, https://github.com/tillsc/can2mqtt/issues +Classifier: Development Status :: 3 - Alpha +Classifier: Intended Audience :: Developers +Classifier: Topic :: Software Development :: +Classifier: License :: OSI Approved :: MIT License +Classifier: Programming Language :: Python :: 3 +Requires-Python: !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4 +Description-Content-Type: text/markdown +Requires-Dist: python-can +Requires-Dist: cantools +Requires-Dist: paho-mqtt +Requires-Dist: pyyaml +Provides-Extra: dev +Provides-Extra: test +Requires-Dist: pytest; extra == "test" +Dynamic: author +Dynamic: author-email +Dynamic: classifier +Dynamic: description +Dynamic: description-content-type +Dynamic: home-page +Dynamic: keywords +Dynamic: project-url +Dynamic: provides-extra +Dynamic: requires-dist +Dynamic: requires-python +Dynamic: summary + +[DBC](http://socialledge.com/sjsu/index.php/DBC_Format) based CAN to MQTT brigde +=== + +This is a generic CAN 2 MQTT bridge build with Python 3 + +### Setup + +This package is based upon the following dependencies: + +* [python-can](https://python-can.readthedocs.io/en/master/) +* [cantools](https://github.com/eerimoq/cantools) +* [phao](http://www.eclipse.org/paho/) + +Install all required Python 3 dependencies on a raspberry: + + sudo apt-get install python3-pip python3-can + pip3 install paho-mqtt cantools + +### Usage + +Copy your DBC files into the root directory. + +Copy config.example.yaml to config.yaml and modify it. + +Run `./main.py` or `python3 main.py` diff --git a/can2mqtt.egg-info/SOURCES.txt b/can2mqtt.egg-info/SOURCES.txt new file mode 100644 index 0000000..3caab53 --- /dev/null +++ b/can2mqtt.egg-info/SOURCES.txt @@ -0,0 +1,16 @@ +README.md +setup.py +can2mqtt/__init__.py +can2mqtt/app.py +can2mqtt/can_listener.py +can2mqtt/converter.py +can2mqtt/mqtt_handler.py +can2mqtt.egg-info/PKG-INFO +can2mqtt.egg-info/SOURCES.txt +can2mqtt.egg-info/dependency_links.txt +can2mqtt.egg-info/entry_points.txt +can2mqtt.egg-info/requires.txt +can2mqtt.egg-info/top_level.txt +can2mqtt/test/__init__.py +can2mqtt/test/mqtt_dummy.py +can2mqtt/test/test_main.py \ No newline at end of file diff --git a/can2mqtt.egg-info/dependency_links.txt b/can2mqtt.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/can2mqtt.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/can2mqtt.egg-info/entry_points.txt b/can2mqtt.egg-info/entry_points.txt new file mode 100644 index 0000000..8d5f69d --- /dev/null +++ b/can2mqtt.egg-info/entry_points.txt @@ -0,0 +1,2 @@ +[console_scripts] +run = run:main diff --git a/can2mqtt.egg-info/requires.txt b/can2mqtt.egg-info/requires.txt new file mode 100644 index 0000000..b0d799c --- /dev/null +++ b/can2mqtt.egg-info/requires.txt @@ -0,0 +1,9 @@ +python-can +cantools +paho-mqtt +pyyaml + +[dev] + +[test] +pytest diff --git a/can2mqtt.egg-info/top_level.txt b/can2mqtt.egg-info/top_level.txt new file mode 100644 index 0000000..4344535 --- /dev/null +++ b/can2mqtt.egg-info/top_level.txt @@ -0,0 +1 @@ +can2mqtt diff --git a/can2mqtt/test/simple.dbc b/can2mqtt/test/simple.dbc index 1a31c31..8184178 100644 --- a/can2mqtt/test/simple.dbc +++ b/can2mqtt/test/simple.dbc @@ -1,2 +1,2 @@ -BO_ 500 IO_DEBUG: 4 IO - SG_ IO_DEBUG_test_unsigned : 0|8@1+ (1,0) [0|0] "" DBG +BO_ 500 IO_DEBUG_msg1: 4 IO + SG_ IO_DEBUG_msg1_sig1 : 0|8@1+ (1,0) [0|0] "" DBG diff --git a/can2mqtt/test/test_main.py b/can2mqtt/test/test_main.py index 08c1441..07b9747 100644 --- a/can2mqtt/test/test_main.py +++ b/can2mqtt/test/test_main.py @@ -6,6 +6,7 @@ from can2mqtt.test.mqtt_dummy import MqttDummy from can2mqtt.can_listener import CanListener +from can2mqtt.converter import Converter from can2mqtt.app import load_dbc_db class TestStringMethods(unittest.TestCase): @@ -14,16 +15,15 @@ def setUp(self): self.mqtt_dummy = MqttDummy() self.dbc_db = load_dbc_db(['can2mqtt/test/simple.dbc']) self.default_config = { - 'mqtt': { - 'topic_names': { - 'first_underscores_to_slash': 2 - } - } - } + 'name_conversion': { + 'first_underscores_to_slash': 2 + }, + 'only_one_signal_per_message': True + } + self.converter = Converter(self.dbc_db, self.default_config) - def build_can_listener(self, special_config = {}): - cnf = self.default_config | special_config - return CanListener(self.dbc_db, self.mqtt_dummy, cnf) + def build_can_listener(self, resend_unchanged_events_after): + return CanListener(self.mqtt_dummy, self.converter, resend_unchanged_events_after) def build_message(self, message_id, data_byte_1 = 0, timestamp=None): @@ -33,18 +33,18 @@ def build_message(self, message_id, data_byte_1 = 0, timestamp=None): data=struct.pack('4b', data_byte_1, 0, 0, 0)) def test_can_listener_converts_topic_names(self): - can_listener = self.build_can_listener() + can_listener = self.build_can_listener(30) msg = self.build_message(500, 50) can_listener.on_message_received(msg) - self.assertEqual(self.mqtt_dummy.last_topic, 'io/debug/test_unsigned') + self.assertEqual(self.mqtt_dummy.last_topic, 'io/debug/msg1') self.assertEqual(self.mqtt_dummy.last_data, 50) def test_no_resend_same_data(self): - can_listener = self.build_can_listener() + can_listener = self.build_can_listener(30) msg = self.build_message(500, 50) can_listener.on_message_received(msg) - self.assertEqual(self.mqtt_dummy.last_topic, 'io/debug/test_unsigned') + self.assertEqual(self.mqtt_dummy.last_topic, 'io/debug/msg1') self.assertEqual(self.mqtt_dummy.last_data, 50) self.mqtt_dummy.reset() @@ -59,15 +59,15 @@ def test_no_resend_same_data(self): self.mqtt_dummy.reset() msg3 = self.build_message(500, 50, msg.timestamp + 31) can_listener.on_message_received(msg3) - self.assertEqual(self.mqtt_dummy.last_topic, 'io/debug/test_unsigned') + self.assertEqual(self.mqtt_dummy.last_topic, 'io/debug/msg1') def test_force_resend_same_data(self): - can_listener = self.build_can_listener({'resend_unchanged_events_after': 0}) + can_listener = self.build_can_listener(0) msg = self.build_message(500, 50) for x in range(0, 3): can_listener.on_message_received(msg) - self.assertEqual(self.mqtt_dummy.last_topic, 'io/debug/test_unsigned') + self.assertEqual(self.mqtt_dummy.last_topic, 'io/debug/msg1') self.assertEqual(self.mqtt_dummy.last_data, 50) self.mqtt_dummy.reset()