Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating MQTT protocol with artery #328

Open
Ambica2022 opened this issue Mar 11, 2024 · 13 comments
Open

Integrating MQTT protocol with artery #328

Ambica2022 opened this issue Mar 11, 2024 · 13 comments

Comments

@Ambica2022
Copy link

Hi,

How can I integrate MQTT protocol with artery to establish communication between artery and MQTT broker?Thanks in advance.

Regards,
Ambica.

@riebl
Copy link
Owner

riebl commented Mar 11, 2024

Your question cannot be answered properly without further information. Are you going to send data from Artery to a MQTT broker? Are you receiving data from the broker? Both directions? Which data shall be exchanged (positions? messages? full packets? …)

@Ambica2022
Copy link
Author

Hi,

Communication is required in both the directions.
Artery -> MQTT broker = payloads of ITS-G5 messages and also GNSS information
MQTT -> Artery = full packets

Thanks,
Ambica

@riebl
Copy link
Owner

riebl commented Mar 11, 2024

I would start with an "MQTT service" attached to those vehicles that shall publish their data via MQTT. You should be able to forge unique topic names for each vehicle based on the module path. Have a look at the ItsG5PromiscuousService for enabling a service to intercept messages on any BTP port instead of one fixed port number.
Vice versa, the service can subscribe to packets from the MQTT broker and pass them on to its link layer on behalf of the MQTT broker.

As a first step, every service may open its own connection to the broker, which probably becomes inefficient when many vehicles are equipped with your MQTT service. Then, you can introduce a "global" MQTT connection module which is shared among all services. But that is an optimization I would postpone until the basic implementation of the MQTT service is working.

@Ambica2022
Copy link
Author

Thank you for the information.
I need to mention that MQTT broker is running on v2x physical device i.e external to artery .

@Ambica2022
Copy link
Author

I would start with an "MQTT service" attached to those vehicles that shall publish their data via MQTT. You should be able to forge unique topic names for each vehicle based on the module path. Have a look at the ItsG5PromiscuousService for enabling a service to intercept messages on any BTP port instead of one fixed port number. Vice versa, the service can subscribe to packets from the MQTT broker and pass them on to its link layer on behalf of the MQTT broker.

As a first step, every service may open its own connection to the broker, which probably becomes inefficient when many vehicles are equipped with your MQTT service. Then, you can introduce a "global" MQTT connection module which is shared among all services. But that is an optimization I would postpone until the basic implementation of the MQTT service is working.

Hi,

Made available header files of Eclipse paho c++ library under default location(where Boost is available) in my PC to be used in Artery service. But encountering the error when running the service.
...
....
....
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/PolygonCondition.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/SignalEffect.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/SignalEffectFactory.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/SpeedDifferenceCondition.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/SpeedEffect.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/SpeedEffectFactory.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/StopEffect.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/StopEffectFactory.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/Storyboard.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/Story.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/TimeCondition.cc.o
[ 99%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/TtcCondition.cc.o
[100%] Building CXX object src/artery/storyboard/CMakeFiles/storyboard.dir/Vehicle.cc.o
[100%] Linking CXX shared library libartery_storyboard.so
[100%] Built target storyboard
Scanning dependencies of target debug_svw
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/ambica/omnetpp-5.7/bin/opp_run_dbg...
(gdb)
(gdb) run
Starting program: /home/ambica/omnetpp-5.7/bin/opp_run_dbg -n /home/ambica/artery-PTW/src/artery:/home/ambica/artery-PTW/src/traci:/home/ambica/artery-PTW/extern/veins/examples/veins:/home/ambica/artery-PTW/extern/veins/src/veins:/home/ambica/artery-PTW/extern/inet/src:/home/ambica/artery-PTW/extern/inet/examples:/home/ambica/artery-PTW/extern/inet/tutorials:/home/ambica/artery-PTW/extern/inet/showcases -l /home/ambica/artery-PTW/build/src/artery/envmod/libartery_envmod.so -l /home/ambica/artery-PTW/build/scenarios/highway-police/libartery_police.so -l /home/ambica/artery-PTW/build/src/artery/envmod/libartery_envmod.so -l /home/ambica/artery-PTW/build/src/artery/storyboard/libartery_storyboard.so -l /home/ambica/artery-PTW/build/extern/libINET.so -l /home/ambica/artery-PTW/build/extern/libveins.so -l /home/ambica/artery-PTW/build/src/traci/libtraci.so -l /home/ambica/artery-PTW/build/src/artery/libartery_core.so omnetpp.ini
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
OMNeT++ Discrete Event Simulation (C) 1992-2021 Andras Varga, OpenSim Ltd.
Version: 5.7, build: 211004-1d27e5f35e, edition: Academic Public License -- NOT FOR COMMERCIAL USE
See the license for distribution terms and warranty disclaimer

<!> Error: Cannot load library '/.........../build/src/artery/envmod/libartery_envmod.so': /.........../build/src/artery/libartery_core.so: undefined symbol: MQTTClient_create

End.
[Inferior 1 (process 70615) exited with code 01]

Not able to identify the source of the error?Could you have any clue?Thanks in advance.

Regards,
Ambica

@riebl
Copy link
Owner

riebl commented Mar 18, 2024

I guess you have not linked your binaries to the Paho library. You may first want to create a minimal working program (without any OMNeT++ and Artery stuff) that uses the chosen MQTT library and can successfully communicate with your broker. If that is working, you can port your code to an Artery service without much hassle.

@Ambica2022
Copy link
Author

I guess you have not linked your binaries to the Paho library.
----- Could you please elaborate more here? Here are the steps I followed..........

  1. Builded Eclipse paho C and C++ client libraries from source by following the instructions given in https://github.com/eclipse/paho.mqtt.c and https://github.com/eclipse/paho.mqtt.cpp.
  2. Later,made available all the header(.h) files in the location (where Boost library is available) /usr/include and /usr/include/mqtt.
  3. Finally,included required header files in Artery service.
    Did I miss anything which results in the above mentioned error?

You may first want to create a minimal working program (without any OMNeT++ and Artery stuff) that uses the chosen MQTT library and can successfully communicate with your broker. If that is working, you can port your code to an Artery service without much hassle.
-------I have already tested sample programs outside of Artery and OMNet++ environments and able to communicate successfully with the broker.

Thanks.

Regards,
Ambica.

@riebl
Copy link
Owner

riebl commented Mar 19, 2024

As I have said, you have missed to link the Paho library. C/C++ libraries consist of headers and some binary, e.g. something like libsomething.a (static) or libsomething.so (shared). Linking is about adding the symbols in these binaries to your program.

This is nothing specific to Artery but the 101 of C++ software development. Please also study CMake how to add libraries, e.g. https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20a%20Library.html

@Ambica2022
Copy link
Author

Ambica2022 commented Mar 19, 2024

As I have said, you have missed to link the Paho library. C/C++ libraries consist of headers and some binary, e.g. something like libsomething.a (static) or libsomething.so (shared). Linking is about adding the symbols in these binaries to your program.
--------- yes,trying to link the Paho library to artery framework as follows
Added
find_package(eclipse-paho-mqtt-c REQUIRED)
find_package(PahoMqttCpp COMPONENTS mqtt REQUIRED) here
and also added
target_include_directories(core PUBLIC ${eclipse-paho-mqtt-c_INCLUDE_DIRS})
target_include_directories(core PUBLIC ${PahoMqttCpp_INCLUDE_DIRS})
target_link_libraries(core PUBLIC ${eclipse-paho-mqtt-c_LIBRARIES})
target_link_libraries(core PUBLIC ${PahoMqttCpp_LIBRARIES}) here .but still encountering the same above mentioned error.
Can you suggest if I miss anything here? -----------
This is nothing specific to Artery but the 101 of C++ software development. Please also study CMake how to add libraries, e.g. https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20a%20Library.html

Thanks
Ambica

@riebl
Copy link
Owner

riebl commented Mar 20, 2024

target_link_libraries(core PUBLIC PahoMqttCpp::paho-mqttpp3) should do the trick. I am not sure if any of the CMake variables you have used in your snippet is set at all. Using CMake targets is preferred over INCLUDE_DIRS and LIBRARIES variables in modern CMake.

@Ambica2022
Copy link
Author

Was trying with master branch of C++ library....but found out compilation errors.....worked well with v1.3.2. Thank you Raphael.

@Ambica2022
Copy link
Author

Thank you for the information. I need to mention that MQTT broker is running on v2x physical device i.e external to artery .

Hi @riebl ,

Can you please provide me some clue here?
I need to establish communication through Ethernet between my simulation scenario and external MQTT broker which is running on OBU. Here, within simulation the messages are generated but need to be exchanged through external MQTT broker which is running on OBU.
For example, vehicle1 in simulation has to send only payloads(currently only DENM payload) to external OBU1 through Ethernet. Later external OBU2 has to send the ETSI standard message to vehicle2 in simulation through Ethernet. Both OBUs are connected to single Ubuntu PC through Ethernet and USRP is not using.
For this to work ,found out that testbed with OtaInterfaceStub is the right one. Is this suitable one or any other alternative you suggest?

Thanks in advance.

Regards,
Ambica

@Ambica2022 Ambica2022 reopened this Apr 15, 2024
@riebl
Copy link
Owner

riebl commented Apr 15, 2024

OtaInterfaceStub is only a stub, i.e. it does nothing really useful except to fulfill an interface.
There is no plug-and-play solution available, you will need to write a considerable amount of software on your own to exchange the desired messages with external entities. Both, the testbed code and also the TransfusionService give you an idea of how you can align the simulation domain with the real-world environment. Neither is exactly doing what you are trying to achieve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants