Files
observability/tp3.md

50 lines
878 B
Markdown
Raw Normal View History

2025-12-08 07:49:26 +01:00
# TP3 : NodeRed
```shell
docker run --detach --name nodered ^
--network tp_net ^
-p "1880:1880" ^
-v nodered:/data ^
-e "TZ=Europe/Paris" ^
nodered/node-red:4.1
```
Ajouter la bibliothèque MQTT
```c
#include <curl/curl.h>
#include <string>
#include <iostream>
#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>
```
Dans la fonction ProcessMQTT créer un objet JSON avec les valeurs des différents capteurs.
```c
json obj = {
{"entree", _digital[IN_FLOW_IN].dvalue},
{"sortie", _digital[IN_FLOW_OUT].dvalue}
};
```
Envoyer le message
```c
std::string payload = obj.dump();
auto msg = mqtt::make_message("geii/telemetry", payload);
msg->set_qos(1);
client->publish(msg);
```