2
0
This commit is contained in:
2026-01-09 11:44:24 +01:00
parent 51d380043d
commit 8a4c0a501d
3 changed files with 144 additions and 13 deletions

View File

@@ -442,7 +442,11 @@
"51bb134ec07cdcef", "51bb134ec07cdcef",
"ae4e0b8f232fbdfc", "ae4e0b8f232fbdfc",
"f98062374cdfd8d1", "f98062374cdfd8d1",
"9dfe2d239a268225" "9dfe2d239a268225",
"be011ad2f6f6421d",
"99ccef7cde8a92e9",
"782e8b8cc5e195e4",
"9f7680a2a2de021a"
] ]
] ]
}, },
@@ -731,7 +735,7 @@
"type": "function", "type": "function",
"z": "41526b8c80d5a5f7", "z": "41526b8c80d5a5f7",
"name": "reset", "name": "reset",
"func": "flow.set(\"i0\", 0);\nflow.set(\"i1\", 0);\nflow.set(\"i2\", 0);\nflow.set(\"i3\", 0);\nflow.set(\"i4\", 0);\nflow.set(\"i5\", 0);\nflow.set(\"i6\", 0);\nflow.set(\"i7\", 0);\n\nreturn msg;", "func": "flow.set(\"i0\", 0);\nflow.set(\"i1\", 0);\nflow.set(\"i2\", 0);\nflow.set(\"i3\", 0);\nflow.set(\"i4\", 0);\nflow.set(\"i5\", 0);\nflow.set(\"i6\", 0);\nflow.set(\"i7\", 0);\n\nflow.set(\"m0\", 0);\nflow.set(\"m1\", 0);\nflow.set(\"m2\", 0);\nflow.set(\"m3\", 0);\n\nflow.set(\"p0\", 0);\nflow.set(\"v0\", 0);\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
"noerr": 0, "noerr": 0,
@@ -1080,7 +1084,7 @@
"type": "function", "type": "function",
"z": "41526b8c80d5a5f7", "z": "41526b8c80d5a5f7",
"name": "format mqtt", "name": "format mqtt",
"func": "let i0 = Number(flow.get(\"i0\")) || 0;\nlet i1 = Number(flow.get(\"i1\")) || 0;\nlet i2 = Number(flow.get(\"i2\")) || 0;\nlet i3 = Number(flow.get(\"i3\")) || 0;\nlet i4 = Number(flow.get(\"i4\")) || 0;\nlet i5 = Number(flow.get(\"i5\")) || 0;\nlet i6 = Number(flow.get(\"i6\")) || 0;\nlet i7 = Number(flow.get(\"i7\")) || 0;\n\nif (typeof msg.payload[\"arret\"] === 'undefined') msg.payload[\"arret\"] = 1;\nif (typeof msg.payload[\"marche\"] === 'undefined') msg.payload[\"marche\"] = 0;\n\nif (typeof msg.payload[\"b0\"] === 'undefined') msg.payload[\"b0\"] = 0;\nif (typeof msg.payload[\"b1\"] === 'undefined') msg.payload[\"b1\"] = 0;\nif (typeof msg.payload[\"b2\"] === 'undefined') msg.payload[\"b2\"] = 0;\nif (typeof msg.payload[\"b3\"] === 'undefined') msg.payload[\"b3\"] = 0;\nif (typeof msg.payload[\"b4\"] === 'undefined') msg.payload[\"b4\"] = 0;\nif (typeof msg.payload[\"b5\"] === 'undefined') msg.payload[\"b5\"] = 0;\nif (typeof msg.payload[\"b6\"] === 'undefined') msg.payload[\"b6\"] = 0;\nif (typeof msg.payload[\"b7\"] === 'undefined') msg.payload[\"b7\"] = 0;\n\nmsg.payload[\"i0\"] = i0;\nmsg.payload[\"i1\"] = i1;\nmsg.payload[\"i2\"] = i2;\nmsg.payload[\"i3\"] = i3;\nmsg.payload[\"i4\"] = i4;\nmsg.payload[\"i5\"] = i5;\nmsg.payload[\"i6\"] = i6;\nmsg.payload[\"i7\"] = i7;\n\nreturn msg;", "func": "let i0 = Number(flow.get(\"i0\")) || 0;\nlet i1 = Number(flow.get(\"i1\")) || 0;\nlet i2 = Number(flow.get(\"i2\")) || 0;\nlet i3 = Number(flow.get(\"i3\")) || 0;\nlet i4 = Number(flow.get(\"i4\")) || 0;\nlet i5 = Number(flow.get(\"i5\")) || 0;\nlet i6 = Number(flow.get(\"i6\")) || 0;\nlet i7 = Number(flow.get(\"i7\")) || 0;\n\nlet v0 = Number(flow.get(\"v0\")) || 0;\n\nif (typeof msg.payload[\"arret\"] === 'undefined') msg.payload[\"arret\"] = 1;\nif (typeof msg.payload[\"marche\"] === 'undefined') msg.payload[\"marche\"] = 0;\n\nif (typeof msg.payload[\"b0\"] === 'undefined') msg.payload[\"b0\"] = 0;\nif (typeof msg.payload[\"b1\"] === 'undefined') msg.payload[\"b1\"] = 0;\nif (typeof msg.payload[\"b2\"] === 'undefined') msg.payload[\"b2\"] = 0;\nif (typeof msg.payload[\"b3\"] === 'undefined') msg.payload[\"b3\"] = 0;\nif (typeof msg.payload[\"b4\"] === 'undefined') msg.payload[\"b4\"] = 0;\nif (typeof msg.payload[\"b5\"] === 'undefined') msg.payload[\"b5\"] = 0;\nif (typeof msg.payload[\"b6\"] === 'undefined') msg.payload[\"b6\"] = 0;\nif (typeof msg.payload[\"b7\"] === 'undefined') msg.payload[\"b7\"] = 0;\n\nmsg.payload[\"i0\"] = i0;\nmsg.payload[\"i1\"] = i1;\nmsg.payload[\"i2\"] = i2;\nmsg.payload[\"i3\"] = i3;\nmsg.payload[\"i4\"] = i4;\nmsg.payload[\"i5\"] = i5;\nmsg.payload[\"i6\"] = i6;\nmsg.payload[\"i7\"] = i7;\nmsg.payload[\"v0\"] = v0;\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
"noerr": 0, "noerr": 0,
@@ -1541,7 +1545,8 @@
"9a6dbd2385a1e118", "9a6dbd2385a1e118",
"3a440beb763d86fb", "3a440beb763d86fb",
"5e24007ebaf43929", "5e24007ebaf43929",
"787b142395f2812c" "787b142395f2812c",
"5281ea0425c23135"
] ]
] ]
}, },
@@ -1586,7 +1591,8 @@
"y": 240, "y": 240,
"wires": [ "wires": [
[ [
"bf55b8bf4a7aaf10" "bf55b8bf4a7aaf10",
"2e6f0eeba0865594"
] ]
] ]
}, },
@@ -1617,10 +1623,12 @@
"colorTrack": "", "colorTrack": "",
"colorThumb": "", "colorThumb": "",
"showTextField": false, "showTextField": false,
"x": 880, "x": 720,
"y": 1440, "y": 480,
"wires": [ "wires": [
[] [
"22dad6f80cc846bd"
]
] ]
}, },
{ {
@@ -1635,10 +1643,120 @@
"height": 0, "height": 0,
"color": "", "color": "",
"className": "", "className": "",
"x": 880, "x": 1740,
"y": 1500, "y": 240,
"wires": [] "wires": []
}, },
{
"id": "be011ad2f6f6421d",
"type": "function",
"z": "41526b8c80d5a5f7",
"name": "m0",
"func": "flow.set(\"m0\", Number(msg.payload.m0));\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 1440,
"wires": [
[]
]
},
{
"id": "99ccef7cde8a92e9",
"type": "function",
"z": "41526b8c80d5a5f7",
"name": "m1",
"func": "flow.set(\"m1\", Number(msg.payload.m1));\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 1480,
"wires": [
[]
]
},
{
"id": "782e8b8cc5e195e4",
"type": "function",
"z": "41526b8c80d5a5f7",
"name": "m2",
"func": "flow.set(\"m2\", Number(msg.payload.m2));\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 1520,
"wires": [
[]
]
},
{
"id": "9f7680a2a2de021a",
"type": "function",
"z": "41526b8c80d5a5f7",
"name": "m3",
"func": "flow.set(\"m3\", Number(msg.payload.m3));\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 1560,
"wires": [
[]
]
},
{
"id": "2e6f0eeba0865594",
"type": "function",
"z": "41526b8c80d5a5f7",
"name": "function 2",
"func": "let p0 = Number(flow.get(\"p0\")) || 0;\n\nif (flow.get(\"m0\")) {\n p0++;\n if (p0 > 100) p0 = 100;\n flow.set(\"p0\", p0);\n}\n\nif (flow.get(\"m1\")) {\n p0--;\n if (p0 < 0) p0 = 0;\n flow.set(\"p0\", p0);\n}\n\nmsg.payload = p0;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1460,
"y": 240,
"wires": [
[
"8c90e91ac1299743"
]
]
},
{
"id": "22dad6f80cc846bd",
"type": "function",
"z": "41526b8c80d5a5f7",
"name": "v0",
"func": "flow.set(\"v0\", Number(msg.payload));\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 870,
"y": 480,
"wires": [
[]
]
},
{ {
"id": "5fe915fcd26e78ae", "id": "5fe915fcd26e78ae",
"type": "ui-group", "type": "ui-group",
@@ -1731,7 +1849,7 @@
"type": "ui-group", "type": "ui-group",
"name": "Afficheur", "name": "Afficheur",
"page": "bb436fe040268d40", "page": "bb436fe040268d40",
"width": 6, "width": "8",
"height": 1, "height": 1,
"order": 5, "order": 5,
"showTitle": true, "showTitle": true,
@@ -1816,7 +1934,7 @@
} }
}, },
{ {
"id": "ca70d5f93a31281c", "id": "3dc18e328806e2f6",
"type": "global-config", "type": "global-config",
"env": [], "env": [],
"modules": { "modules": {

View File

@@ -53,6 +53,8 @@ int arret = 1;
int b0, b1, b2, b3, b4, b5, b6, b7; int b0, b1, b2, b3, b4, b5, b6, b7;
int i0, i1, i2, i3, i4, i5, i6, i7; int i0, i1, i2, i3, i4, i5, i6, i7;
int s0, s1, s2, s3, s4, s5, s6, s7; int s0, s1, s2, s3, s4, s5, s6, s7;
int m0, m1, m2, m3;
int v0;
/* ******************************************************** /* ********************************************************
* MQTT * * MQTT *
@@ -79,6 +81,10 @@ void mqtt_process(mqtt::async_client* client)
{"s5", s5 }, {"s5", s5 },
{"s6", s6 }, {"s6", s6 },
{"s7", s7 }, {"s7", s7 },
{"m0", m0 },
{"m1", m1 },
{"m2", m2 },
{"m3", m3 },
}; };
std::string payload = obj.dump(); std::string payload = obj.dump();
@@ -127,7 +133,9 @@ public:
if (j.contains("i6")) i6 = j["i6"].get<int>() != 0; if (j.contains("i6")) i6 = j["i6"].get<int>() != 0;
if (j.contains("i7")) i7 = j["i7"].get<int>() != 0; if (j.contains("i7")) i7 = j["i7"].get<int>() != 0;
std::cout << "Pompes : " << marche << " " << arret << " B " << b0 << " " << b1 << " " << b2 << " " << b3 << " " << b4 << " " << b5 << " " << b6 << " " << b7 << " I " << i0 << " " << i1 << " " << i2 << " " << i3 << " " << i4 << " " << i5 << " " << i6 << " " << i7 << std::endl; if (j.contains("v0") && j["v0"].is_number()) v0 = j["v0"].get<int>();
std::cout << "Pompes : " << marche << " " << arret << " B " << b0 << " " << b1 << " " << b2 << " " << b3 << " " << b4 << " " << b5 << " " << b6 << " " << b7 << " I " << i0 << " " << i1 << " " << i2 << " " << i3 << " " << i4 << " " << i5 << " " << i6 << " " << i7 << " " << v0 << std::endl;
} }
catch (const json::parse_error& e) { catch (const json::parse_error& e) {
std::cerr << "Erreur JSON : " << e.what() << "\n"; std::cerr << "Erreur JSON : " << e.what() << "\n";

View File

@@ -7,6 +7,11 @@ int main()
while (1) while (1)
{ {
// Début du code
// *****************************************************
// *****************************************************
// Fin du code
mqtt_process(&client); mqtt_process(&client);
} }