This commit is contained in:
2025-12-08 07:49:26 +01:00
parent fd13318ca8
commit cdeaaab0fb
3 changed files with 50 additions and 0 deletions

View File

@@ -182,3 +182,4 @@ Un KPI doit être :
- [TD 1](td1.md) - [TD 1](td1.md)
- [TP 1](tp1.md) - [TP 1](tp1.md)
- [TP 2](tp2.md) - [TP 2](tp2.md)
- [TP 3](tp3.md)

BIN
grafcet.pdf Executable file

Binary file not shown.

49
tp3.md Normal file
View File

@@ -0,0 +1,49 @@
# 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);
```