diff --git a/src/C++/Socket/main.cpp b/src/C++/Socket/main.cpp index 6a70d41..0ffb7c7 100644 --- a/src/C++/Socket/main.cpp +++ b/src/C++/Socket/main.cpp @@ -1,7 +1,9 @@ #include #include +#include // Voor std::this_thread::sleep_for +#include // Voor std::chrono::seconds -const std::string ADDRESS("tcp://localhost:1883"); +const std::string ADDRESS("tcp://ishakpi.ddns.net:1883"); // Aanpassen indien nodig const std::string CLIENT_ID("raspberry_pi_client"); const std::string TOPIC("home/commands"); @@ -11,6 +13,14 @@ class callback : public virtual mqtt::callback { << "' : " << msg->to_string() << std::endl; // Doe iets met het bericht, bijvoorbeeld een GP.IO-activering } + + void connection_lost(const std::string& cause) override { + std::cerr << "Verbinding verloren. Oorzaak: " << cause << std::endl; + } + + void delivery_complete(mqtt::delivery_token_ptr token) override { + std::cout << "Bericht afgeleverd!" << std::endl; + } }; int main() { @@ -32,13 +42,15 @@ int main() { std::cout << "Abonneren op topic: " << TOPIC << std::endl; client.subscribe(TOPIC, 1)->wait(); + // Houd de client draaiende om berichten te blijven ontvangen while (true) { - // Houd de client draaiende om berichten te blijven ontvangen + std::this_thread::sleep_for(std::chrono::seconds(1)); // Wacht om CPU-gebruik te verminderen } + } catch (const mqtt::exception &exc) { - std::cerr << exc.what() << std::endl; + std::cerr << "Fout: " << exc.what() << std::endl; return 1; } return 0; -} \ No newline at end of file +}