Skip to content

Commit

Permalink
Fixes #270
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Apr 7, 2024
1 parent d0b017c commit 1f63a85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion debug/linux/vscpd.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"user" : "vscp",
"password": "secret",
"clientid" : "fluorine vscpd",
"clientid" : "fluorine vscpd {{rnd}}",
"publish-format" : "json",
"subscribe-format" : "auto",
"qos" : 1,
Expand Down
23 changes: 20 additions & 3 deletions src/vscp/common/vscp_client_mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,23 @@ vscpClientMqtt::init(void)
int rv = 0;

if (m_clientid.length()) {

/*
if clientid if contains {{rd}} replace
with 16 random hex characters
*/
{
std::string clientid_template = m_clientid;
mustache subtemplate{ clientid_template };
data data;

std::string strsalt;
vscp_getSaltHex(strsalt, 8);

data.set("rnd", strsalt);
m_clientid = subtemplate.render(data);
}

m_mosq = mosquitto_new(m_clientid.c_str(), m_bCleanSession, this);
}
else {
Expand Down Expand Up @@ -2344,9 +2361,9 @@ vscpClientMqtt::send(vscpEvent &ev)
ppublish->getRetain());

spdlog::trace("MQTT send; len=%d QOS=%d retain=%s\n",
(int) lenPayload,
ppublish->getQos(),
(ppublish->getRetain() ? "true" : "false"));
(int) lenPayload,
ppublish->getQos(),
(ppublish->getRetain() ? "true" : "false"));

if (MOSQ_ERR_SUCCESS != (rv = mosquitto_publish(m_mosq,
NULL, // msg id
Expand Down

0 comments on commit 1f63a85

Please sign in to comment.