Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ option(ENABLE_SAMPLES "Parameter to enable samples building" ON)
message("ENABLE_PAHO_INSTALLATION=${ENABLE_PAHO_INSTALLATION}")
if(${ENABLE_PAHO_INSTALLATION})
find_library(MQTT paho-mqtt3c)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPAHO_INC" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPAHO_INC" )
endif()

message("ENABLE_RDKAFKA_INSTALLATION=${ENABLE_RDKAFKA_INSTALLATION}")
Expand Down
4 changes: 2 additions & 2 deletions gst/elements/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ PRIVATE
gvametapublish
)
if (MQTT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPAHO_INC ")
target_link_libraries(${TARGET_NAME} PRIVATE paho-mqtt3a uuid)
target_link_libraries(${TARGET_NAME} PRIVATE ${MQTT}/../paho-mqtt3a.lib uuid)
target_include_directories(${TARGET_NAME} PRIVATE ${MQTT}/../../include)
message("MQTT support will be available in metapublish element")
else()
message("MQTT support will not be available. Ensure required libraries (Paho MQTT) are installed, and rebuild plugin with -DMQTT=1 before attempting to use MQTT")
Expand Down
14 changes: 12 additions & 2 deletions gst/elements/gvametapublish/c_metapublish_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
******************************************************************************/
#include "c_metapublish_mqtt.h"
#ifdef PAHO_INC
#include <uuid/uuid.h>

#ifndef WIN32
#include<uuid / uuid.h>
#include <sys/random.h>
#endif

GST_DEBUG_CATEGORY_STATIC(gst_gva_meta_publish_debug_category);
#define GST_CAT_DEFAULT gst_gva_meta_publish_debug_category
Expand Down Expand Up @@ -36,10 +40,15 @@ static gboolean metapublish_mqtt_method_start(MetapublishMethod *self, GstGvaMet
mp_mqtt->connection_attempt = 1;
mp_mqtt->sleep_time = 1;
if (!gvametapublish->mqtt_client_id) {
char *uuid = g_malloc(37 * sizeof(char)); // 36 character UUID string plus terminating character
#ifdef WIN32
uuid = "my_client ";
#else
uuid_t binuuid;
uuid_generate_random(binuuid);
char *uuid = g_malloc(37 * sizeof(char)); // 36 character UUID string plus terminating character
uuid_unparse(binuuid, uuid);
#endif // WIN32
printf("** MQTT Client ID is : %s ** \n", uuid);
gvametapublish->mqtt_client_id = uuid;
}
MQTTAsync_create(mp_mqtt->client, gvametapublish->address, gvametapublish->mqtt_client_id,
Expand Down Expand Up @@ -76,6 +85,7 @@ static gboolean metapublish_mqtt_method_publish(MetapublishMethod *self, GstGvaM
message.payload = json_message;
message.payloadlen = (gint)strlen(message.payload);
message.retained = FALSE;
message.qos = 2;
gint c;
// TODO Validate message is JSON
MQTTAsync_responseOptions ro = MQTTAsync_responseOptions_initializer;
Expand Down