2
0
This commit is contained in:
2026-01-09 10:10:14 +01:00
parent 59c9d200b5
commit 8eacd6a636
3 changed files with 21 additions and 85 deletions

View File

@@ -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 */

View File

@@ -1,36 +1,12 @@
#include <iostream>
#include <iomanip>
#include <unistd.h>
#include <math.h>
#include <locale.h>
#include <array>
#include "main.hpp"
#include "AutomForArduino.cpp"
#include <curl/curl.h>
#include <string>
#include <thread>
#include <atomic>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <csignal>
#include <chrono>
#include <cstring>
#undef timeout
#include "mqtt/async_client.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
mqtt::async_client client(ADDRESS, CLIENTID);
callback cb;
client.set_callback(cb);
@@ -44,7 +20,6 @@ int main()
client.subscribe(TOPIC, QOS)->wait();
} catch (const mqtt::exception &exc) {
std::cerr << "Erreur MQTT: " << exc.what() << "\n";
return 1;
}
while (1)
@@ -58,19 +33,9 @@ int main()
s6 = b6;
s7 = b7;
ProcessMQTT(&client);
usleep(100000);
mqtt_process(&client);
}
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;
}
std::cout << "Fin du programme" << std::endl;
mqtt_close();
return 0;
}

View File

@@ -1,48 +1,2 @@
#undef timeout
#include "mqtt/async_client.h"
void ProcessMQTT(mqtt::async_client* client);
// DIGITAL INPUT
#define IN_SENSOR_MIN 10
#define IN_SENSOR_LOW 11
#define IN_SENSOR_HIGH 12
#define IN_SENSOR_MAX 13
// ANALOG INPUT
#define IN_TANK_LEVEL 14
#define IN_FLOW_OUT 15
#define IN_FLOW_IN 16
#define IN_FLOW_DIF 17
#define IN_TANK_MIN 18
#define IN_TANK_MAX 19
#define IN_FLOW_CAP 20
#define IN_FLOW_1 21
#define IN_FLOW_2 22
#define IN_FLOW_3 23
#define IN_FLOW_4 24
// DIGITAL OUTPUT
#define OUT_PUMP_1 25
#define OUT_PUMP_2 26
#define OUT_PUMP_3 27
#define OUT_PUMP_4 28
#define OUT_DISPLAY_MODE 29
#define OUT_DISPLAY_GRAFCET 30
// ANALOG OUTPUT
#define OUT_LEVEL_MIN 31
#define OUT_LEVEL_LOW 32
#define OUT_LEVEL_HIGH 33
#define OUT_LEVEL_MAX 34
#define OUT_FLOW_PER_PUMP 35
#define OUT_FLOW_OUT_AMPLITUDE 36
#define OUT_BEEP 254
#define OUT_END 255