Skip to content

Commit 56b8039

Browse files
committed
added check for dup thingstream channel ids
1 parent d2dd65d commit 56b8039

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/iot/iot_thingspeak/flxIoTThingSpeak.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class flxIoTThingSpeak : public flxMQTTESP32SecureCore<flxIoTThingSpeak>, public
5151
std::stringstream s_stream(theList); // create string stream from the string
5252
std::string keyvalue;
5353
std::string::size_type sz;
54+
std::string newValue;
5455

5556
while (s_stream.good())
5657
{
@@ -65,7 +66,18 @@ class flxIoTThingSpeak : public flxMQTTESP32SecureCore<flxIoTThingSpeak>, public
6566
flxLogM_W(kMsgErrValueError, name(), "Device=Channel ID");
6667
continue;
6768
}
68-
_deviceToChannel[flx_utils::strtrim(keyvalue.substr(0, sz))] = flx_utils::strtrim(keyvalue.substr(sz + 1));
69+
newValue = flx_utils::strtrim(keyvalue.substr(sz + 1));
70+
// no dups for values (channel ids)
71+
for (auto it = _deviceToChannel.begin(); it != _deviceToChannel.end(); it++)
72+
{
73+
if (it->second == newValue)
74+
{
75+
flxLogM_W(kMsgErrValueError, name(), "Duplicate ThingStream channel ID [%s], skipping",
76+
keyvalue.c_str());
77+
continue;
78+
}
79+
}
80+
_deviceToChannel[flx_utils::strtrim(keyvalue.substr(0, sz))] = newValue;
6981
}
7082
}
7183

0 commit comments

Comments
 (0)