mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
making message print only once
This commit is contained in:
@@ -36,9 +36,10 @@ int main()
|
|||||||
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
|
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
parseMQTT(readMQTT());
|
std::string message = readMQTT();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(10)));
|
if (!message.empty()){
|
||||||
|
parseMQTT(message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,10 +50,13 @@ int main()
|
|||||||
|
|
||||||
std::string readMQTT()
|
std::string readMQTT()
|
||||||
{
|
{
|
||||||
message = client.getLastMessage();
|
static std::string lastMessage;
|
||||||
if (!message.empty())
|
|
||||||
|
std::string message = client.getLastMessage();
|
||||||
|
if (!message.empty() && message != lastMessage)
|
||||||
{
|
{
|
||||||
std::cout << "MQTT Message: " << message << std::endl;
|
std::cout << "MQTT Message: " << message << std::endl;
|
||||||
|
lastMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a small delay to avoid busy-waiting
|
// Add a small delay to avoid busy-waiting
|
||||||
|
Reference in New Issue
Block a user