0

I'm developing an application to simulate the vehicle HMI, which has the main functionality of interacting with the ECU module which basically sends and receives the raw CAN data. In the application, I'm using the "python-can" library to create a CAN bus instance on which it sends and receives the CAN data. The other flow is to parse the received raw CAN data and publish it to the MQTT broker. The application has to also subscribe to certain topics from the MQTT broker.

I tried creating a new thread for all different modules and wrote the CAN module with the help of asyncio library. It would be a great help if there is a good and ideal architecture for the above problem.

  • 1
    There is no question here, not even an implied one – hardillb Mar 24 '22 at 07:57
  • What would be a good architecture using multithreading or asyncio in python to develop the above problem? – Rajat Bansal Mar 24 '22 at 08:12
  • 1
    You've not explained why what you've tried doesn't work or what problems you are actually hitting. As it is there is no way to answer this. Please read the docs about what a good question needs: https://stackoverflow.com/help/how-to-ask – hardillb Mar 24 '22 at 08:39
  • What I did so far is, I have created a new thread in the main thread, and in the new thread I have created a new MQTT client with the loop_forever() method, so that it should be listening to all the subscribed topics. Now, on the main thread, I have created an event loop and put two async functions in this event loop. These functions are can_send() and can_receive(). The can_receive() will listen indefinitely on the CAN bus for the new messages coming on the bus. – Rajat Bansal Mar 24 '22 at 10:58
  • [Edit](https://stackoverflow.com/posts/71597818/edit) the question to add details and code. You also need to explain why what you've tried is not working. – hardillb Mar 24 '22 at 11:00
  • @hardillb It is working fine, but I'm looking for a more straightforward solution using the async MQTT. So I won't be handling multiple threads in the application and the complete thing is developed using asyncio. Could you please suggest something, it would be a great help? – Rajat Bansal Mar 24 '22 at 11:03
  • No, this is not how Stack Overflow works, you need to try to do it yourself and then you can ask specific questions when you get stuck, but we won't supply a solution for you. – hardillb Mar 24 '22 at 11:09

0 Answers0