8 sorties
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#undef timeout
|
||||
#include "mqtt/async_client.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
/* From Arduino.h */
|
||||
|
||||
#define HIGH 0x1
|
||||
@@ -74,8 +80,71 @@ void pinMode(unsigned char p, unsigned char mode)
|
||||
_digital[p].memory = 0;
|
||||
}
|
||||
|
||||
int b0, b1, b2, b3, b4, b5, b6, b7;
|
||||
int s0, s1, s2, s3, s4, s5, s6, s7;
|
||||
|
||||
/* ********************************************************
|
||||
* MQTT *
|
||||
* *
|
||||
******************************************************** */
|
||||
|
||||
/* Configuration MQTT */
|
||||
const std::string ADDRESS = "tcp://rabbitmq:1883";
|
||||
const std::string CLIENTID = "CppClientTP";
|
||||
const std::string TOPIC = "geii/in/#";
|
||||
const int QOS = 1;
|
||||
const int CYCLE_MS = 100;
|
||||
|
||||
void ProcessMQTT(mqtt::async_client* client)
|
||||
{
|
||||
json obj = {
|
||||
{"s0", s0 },
|
||||
{"s1", s1 },
|
||||
{"s2", s2 },
|
||||
{"s3", s3 },
|
||||
{"s4", s4 },
|
||||
{"s5", s5 },
|
||||
{"s6", s6 },
|
||||
{"s7", s7 },
|
||||
};
|
||||
|
||||
std::string payload = obj.dump();
|
||||
auto msg = mqtt::make_message("geii/out", payload);
|
||||
msg->set_qos(1);
|
||||
client->publish(msg);
|
||||
}
|
||||
|
||||
|
||||
// Réception des messages MQTT
|
||||
// ************************************************************
|
||||
class callback : public virtual mqtt::callback {
|
||||
public:
|
||||
void message_arrived(mqtt::const_message_ptr msg) override {
|
||||
std::string payload = msg->to_string();
|
||||
|
||||
try {
|
||||
json j = json::parse(payload);
|
||||
|
||||
// Ne rien faire si l'objet JSON est vide
|
||||
if (j.empty()) return;
|
||||
|
||||
if (j.contains("b0")) b0 = j["b0"].get<int>() != 0;
|
||||
if (j.contains("b1")) b1 = j["b1"].get<int>() != 0;
|
||||
if (j.contains("b2")) b2 = j["b2"].get<int>() != 0;
|
||||
if (j.contains("b3")) b3 = j["b3"].get<int>() != 0;
|
||||
if (j.contains("b4")) b4 = j["b4"].get<int>() != 0;
|
||||
if (j.contains("b5")) b5 = j["b5"].get<int>() != 0;
|
||||
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;
|
||||
}
|
||||
catch (const json::parse_error& e) {
|
||||
std::cerr << "Erreur JSON : " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
// ************************************************************
|
||||
|
||||
/* KEYBOARD */
|
||||
|
||||
@@ -165,7 +234,7 @@ class TemporisationRetardMontee
|
||||
};
|
||||
|
||||
/********************************************************
|
||||
* TEMPORISATION RETARD A LA DESCENTE *
|
||||
* TEMPORISATION RETARD A LA DESCENTE *
|
||||
* La sortie passe à 0 au bout de la tempo *
|
||||
*********************************************************/
|
||||
class TemporisationRetardDescente
|
||||
|
||||
Reference in New Issue
Block a user