mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14:58 +00:00
Update MQTT address to use SSL and change broker address
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mqtt/async_client.h>
|
#include <mqtt/async_client.h>
|
||||||
|
#include <thread> // Voor std::this_thread::sleep_for
|
||||||
|
#include <chrono> // 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 CLIENT_ID("raspberry_pi_client");
|
||||||
const std::string TOPIC("home/commands");
|
const std::string TOPIC("home/commands");
|
||||||
|
|
||||||
@@ -11,6 +13,14 @@ class callback : public virtual mqtt::callback {
|
|||||||
<< "' : " << msg->to_string() << std::endl;
|
<< "' : " << msg->to_string() << std::endl;
|
||||||
// Doe iets met het bericht, bijvoorbeeld een GP.IO-activering
|
// 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() {
|
int main() {
|
||||||
@@ -32,11 +42,13 @@ int main() {
|
|||||||
std::cout << "Abonneren op topic: " << TOPIC << std::endl;
|
std::cout << "Abonneren op topic: " << TOPIC << std::endl;
|
||||||
client.subscribe(TOPIC, 1)->wait();
|
client.subscribe(TOPIC, 1)->wait();
|
||||||
|
|
||||||
while (true) {
|
|
||||||
// Houd de client draaiende om berichten te blijven ontvangen
|
// Houd de client draaiende om berichten te blijven ontvangen
|
||||||
|
while (true) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1)); // Wacht om CPU-gebruik te verminderen
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (const mqtt::exception &exc) {
|
} catch (const mqtt::exception &exc) {
|
||||||
std::cerr << exc.what() << std::endl;
|
std::cerr << "Fout: " << exc.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user