mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14: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); });
|
||||
|
||||
while(true){
|
||||
parseMQTT(readMQTT());
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(10)));
|
||||
|
||||
std::string message = readMQTT();
|
||||
if (!message.empty()){
|
||||
parseMQTT(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,10 +50,13 @@ int main()
|
||||
|
||||
std::string readMQTT()
|
||||
{
|
||||
message = client.getLastMessage();
|
||||
if (!message.empty())
|
||||
static std::string lastMessage;
|
||||
|
||||
std::string message = client.getLastMessage();
|
||||
if (!message.empty() && message != lastMessage)
|
||||
{
|
||||
std::cout << "MQTT Message: " << message << std::endl;
|
||||
lastMessage = message;
|
||||
}
|
||||
|
||||
// Add a small delay to avoid busy-waiting
|
||||
|
Reference in New Issue
Block a user