Slim
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#undef timeout
|
||||
#include "mqtt/async_client.h"
|
||||
@@ -95,7 +96,9 @@ const std::string TOPIC = "geii/in/#";
|
||||
const int QOS = 1;
|
||||
const int CYCLE_MS = 100;
|
||||
|
||||
void ProcessMQTT(mqtt::async_client* client)
|
||||
mqtt::async_client client(ADDRESS, CLIENTID);
|
||||
|
||||
void mqtt_process(mqtt::async_client* client)
|
||||
{
|
||||
json obj = {
|
||||
{"s0", s0 },
|
||||
@@ -112,6 +115,8 @@ void ProcessMQTT(mqtt::async_client* client)
|
||||
auto msg = mqtt::make_message("geii/out", payload);
|
||||
msg->set_qos(1);
|
||||
client->publish(msg);
|
||||
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
|
||||
@@ -137,13 +142,25 @@ public:
|
||||
if (j.contains("b6")) b6 = j["b6"].get<int>() != 0;
|
||||
if (j.contains("b7")) b7 = j["b7"].get<int>() != 0;
|
||||
|
||||
std::cout << "Pompes : " << b0 << " " << b1 << " " << b2 << " " << b3 << std::endl;
|
||||
std::cout << "Pompes : " << b0 << " " << b1 << " " << b2 << " " << b3 << " " << b4 << " " << b5 << " " << b6 << " " << b7 << std::endl;
|
||||
}
|
||||
catch (const json::parse_error& e) {
|
||||
std::cerr << "Erreur JSON : " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void mqtt_close() {
|
||||
try {
|
||||
client.unsubscribe(TOPIC)->wait();
|
||||
client.stop_consuming();
|
||||
client.disconnect()->wait();
|
||||
} catch(const mqtt::exception &exc){
|
||||
std::cerr << "Erreur déconnexion MQTT: " << exc.what() << std::endl;
|
||||
}
|
||||
}
|
||||
// ************************************************************
|
||||
|
||||
/* KEYBOARD */
|
||||
|
||||
Reference in New Issue
Block a user