tp3
This commit is contained in:
@@ -182,3 +182,4 @@ Un KPI doit être :
|
||||
- [TD 1](td1.md)
|
||||
- [TP 1](tp1.md)
|
||||
- [TP 2](tp2.md)
|
||||
- [TP 3](tp3.md)
|
||||
|
||||
BIN
grafcet.pdf
Executable file
BIN
grafcet.pdf
Executable file
Binary file not shown.
49
tp3.md
Normal file
49
tp3.md
Normal 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);
|
||||
```
|
||||
Reference in New Issue
Block a user