2
0
This commit is contained in:
2026-01-14 21:03:56 +01:00
parent 15881b8500
commit 7204905bc4
3 changed files with 364 additions and 209 deletions

View File

@@ -221,17 +221,6 @@
"disabled": "false", "disabled": "false",
"groupType": "default" "groupType": "default"
}, },
{
"id": "34e2708f001f89c4",
"type": "ui-spacer",
"group": "6b44d4b22cd7b3dc",
"name": "spacer",
"tooltip": "",
"order": 11,
"width": 1,
"height": 1,
"className": ""
},
{ {
"id": "050148aff99031d4", "id": "050148aff99031d4",
"type": "ui-group", "type": "ui-group",
@@ -253,7 +242,7 @@
"group": "5fe915fcd26e78ae", "group": "5fe915fcd26e78ae",
"name": "", "name": "",
"label": "B0", "label": "B0",
"order": 1, "order": 8,
"width": 0, "width": 0,
"height": 0, "height": 0,
"emulateClick": false, "emulateClick": false,
@@ -292,7 +281,7 @@
"group": "5fe915fcd26e78ae", "group": "5fe915fcd26e78ae",
"name": "", "name": "",
"label": "B1", "label": "B1",
"order": 2, "order": 7,
"width": 0, "width": 0,
"height": 0, "height": 0,
"emulateClick": false, "emulateClick": false,
@@ -331,7 +320,7 @@
"group": "5fe915fcd26e78ae", "group": "5fe915fcd26e78ae",
"name": "", "name": "",
"label": "B2", "label": "B2",
"order": 3, "order": 6,
"width": 0, "width": 0,
"height": 0, "height": 0,
"emulateClick": false, "emulateClick": false,
@@ -370,7 +359,7 @@
"group": "5fe915fcd26e78ae", "group": "5fe915fcd26e78ae",
"name": "", "name": "",
"label": "B3", "label": "B3",
"order": 4, "order": 5,
"width": 0, "width": 0,
"height": 0, "height": 0,
"emulateClick": false, "emulateClick": false,
@@ -591,7 +580,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "c3dd11d0778f9e67", "group": "c3dd11d0778f9e67",
"order": 1, "order": 8,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@@ -615,7 +604,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "c3dd11d0778f9e67", "group": "c3dd11d0778f9e67",
"order": 2, "order": 7,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@@ -639,7 +628,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "c3dd11d0778f9e67", "group": "c3dd11d0778f9e67",
"order": 3, "order": 6,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@@ -723,7 +712,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "c3dd11d0778f9e67", "group": "c3dd11d0778f9e67",
"order": 4, "order": 5,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@@ -747,7 +736,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "c3dd11d0778f9e67", "group": "c3dd11d0778f9e67",
"order": 5, "order": 4,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@@ -771,7 +760,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "c3dd11d0778f9e67", "group": "c3dd11d0778f9e67",
"order": 6, "order": 3,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@@ -795,7 +784,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "c3dd11d0778f9e67", "group": "c3dd11d0778f9e67",
"order": 7, "order": 2,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@@ -819,7 +808,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "c3dd11d0778f9e67", "group": "c3dd11d0778f9e67",
"order": 8, "order": 1,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@@ -974,7 +963,7 @@
"group": "5fe915fcd26e78ae", "group": "5fe915fcd26e78ae",
"name": "", "name": "",
"label": "B4", "label": "B4",
"order": 5, "order": 4,
"width": 0, "width": 0,
"height": 0, "height": 0,
"emulateClick": false, "emulateClick": false,
@@ -1013,7 +1002,7 @@
"group": "5fe915fcd26e78ae", "group": "5fe915fcd26e78ae",
"name": "", "name": "",
"label": "B5", "label": "B5",
"order": 6, "order": 3,
"width": 0, "width": 0,
"height": 0, "height": 0,
"emulateClick": false, "emulateClick": false,
@@ -1052,7 +1041,7 @@
"group": "5fe915fcd26e78ae", "group": "5fe915fcd26e78ae",
"name": "", "name": "",
"label": "B6", "label": "B6",
"order": 7, "order": 2,
"width": 0, "width": 0,
"height": 0, "height": 0,
"emulateClick": false, "emulateClick": false,
@@ -1091,7 +1080,7 @@
"group": "5fe915fcd26e78ae", "group": "5fe915fcd26e78ae",
"name": "", "name": "",
"label": "B7", "label": "B7",
"order": 8, "order": 1,
"width": 0, "width": 0,
"height": 0, "height": 0,
"emulateClick": false, "emulateClick": false,
@@ -1210,7 +1199,7 @@
"name": "", "name": "",
"label": "I0", "label": "I0",
"group": "00ea85a0e0b38df3", "group": "00ea85a0e0b38df3",
"order": 1, "order": 8,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -1364,7 +1353,7 @@
"name": "", "name": "",
"label": "I1", "label": "I1",
"group": "00ea85a0e0b38df3", "group": "00ea85a0e0b38df3",
"order": 2, "order": 7,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -1418,7 +1407,7 @@
"name": "", "name": "",
"label": "I2", "label": "I2",
"group": "00ea85a0e0b38df3", "group": "00ea85a0e0b38df3",
"order": 3, "order": 6,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -1472,7 +1461,7 @@
"name": "", "name": "",
"label": "I3", "label": "I3",
"group": "00ea85a0e0b38df3", "group": "00ea85a0e0b38df3",
"order": 4, "order": 5,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -1526,7 +1515,7 @@
"name": "", "name": "",
"label": "I4", "label": "I4",
"group": "00ea85a0e0b38df3", "group": "00ea85a0e0b38df3",
"order": 5, "order": 4,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -1580,7 +1569,7 @@
"name": "", "name": "",
"label": "I5", "label": "I5",
"group": "00ea85a0e0b38df3", "group": "00ea85a0e0b38df3",
"order": 6, "order": 3,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -1634,7 +1623,7 @@
"name": "", "name": "",
"label": "I6", "label": "I6",
"group": "00ea85a0e0b38df3", "group": "00ea85a0e0b38df3",
"order": 7, "order": 2,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -1688,7 +1677,7 @@
"name": "", "name": "",
"label": "I7", "label": "I7",
"group": "00ea85a0e0b38df3", "group": "00ea85a0e0b38df3",
"order": 8, "order": 1,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -2035,7 +2024,7 @@
"id": "1cd3d290f7f7d539", "id": "1cd3d290f7f7d539",
"type": "function", "type": "function",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"name": "s8", "name": "s8 🟢",
"func": "msg.payload = Number(msg.payload.s8) == 1 ? \"<span style='font-weight:400'>🟢</span>\" : \"<span style='font-weight:400'>⚪</span>\";\n\nreturn msg;", "func": "msg.payload = Number(msg.payload.s8) == 1 ? \"<span style='font-weight:400'>🟢</span>\" : \"<span style='font-weight:400'>⚪</span>\";\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
@@ -2055,7 +2044,7 @@
"id": "88310a9e40d564fc", "id": "88310a9e40d564fc",
"type": "function", "type": "function",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"name": "s8", "name": "s8 🟠",
"func": "msg.payload = Number(msg.payload.s8) == 2 ? \"<span style='font-weight:400'>🟠</span>\" : \"<span style='font-weight:400'>⚪</span>\";\n\nreturn msg;", "func": "msg.payload = Number(msg.payload.s8) == 2 ? \"<span style='font-weight:400'>🟠</span>\" : \"<span style='font-weight:400'>⚪</span>\";\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
@@ -2075,7 +2064,7 @@
"id": "b543660f60319f21", "id": "b543660f60319f21",
"type": "function", "type": "function",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"name": "s8", "name": "s8 🔴",
"func": "msg.payload = Number(msg.payload.s8) == 3 ? \"<span style='font-weight:400'>🔴</span>\" : \"<span style='font-weight:400'>⚪</span>\";\n\nreturn msg;", "func": "msg.payload = Number(msg.payload.s8) == 3 ? \"<span style='font-weight:400'>🔴</span>\" : \"<span style='font-weight:400'>⚪</span>\";\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
@@ -2336,13 +2325,13 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "6b44d4b22cd7b3dc", "group": "6b44d4b22cd7b3dc",
"order": 8, "order": 7,
"width": "1", "width": "1",
"height": "1", "height": "1",
"name": "", "name": "",
"label": "c1", "label": "c1",
"format": "{{msg.payload}}", "format": "{{msg.payload}}",
"layout": "row-left", "layout": "row-right",
"style": false, "style": false,
"font": "", "font": "",
"fontSize": 16, "fontSize": 16,
@@ -2366,7 +2355,7 @@
"name": "", "name": "",
"label": "c2", "label": "c2",
"format": "{{msg.payload}}", "format": "{{msg.payload}}",
"layout": "row-right", "layout": "row-left",
"style": false, "style": false,
"font": "", "font": "",
"fontSize": 16, "fontSize": 16,
@@ -2444,7 +2433,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "6b44d4b22cd7b3dc", "group": "6b44d4b22cd7b3dc",
"order": 12, "order": 10,
"width": "1", "width": "1",
"height": "1", "height": "1",
"name": "", "name": "",
@@ -2468,7 +2457,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "6b44d4b22cd7b3dc", "group": "6b44d4b22cd7b3dc",
"order": 13, "order": 12,
"width": "1", "width": "1",
"height": "1", "height": "1",
"name": "", "name": "",
@@ -2492,13 +2481,13 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "6b44d4b22cd7b3dc", "group": "6b44d4b22cd7b3dc",
"order": 14, "order": 13,
"width": "1", "width": "1",
"height": "1", "height": "1",
"name": "", "name": "",
"label": "c5", "label": "c5",
"format": "{{msg.payload}}", "format": "{{msg.payload}}",
"layout": "row-left", "layout": "row-right",
"style": false, "style": false,
"font": "", "font": "",
"fontSize": 16, "fontSize": 16,
@@ -2516,7 +2505,7 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "6b44d4b22cd7b3dc", "group": "6b44d4b22cd7b3dc",
"order": 15, "order": 14,
"width": "1", "width": "1",
"height": "1", "height": "1",
"name": "", "name": "",
@@ -2540,13 +2529,13 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "6b44d4b22cd7b3dc", "group": "6b44d4b22cd7b3dc",
"order": 16, "order": 15,
"width": "1", "width": "1",
"height": "1", "height": "1",
"name": "", "name": "",
"label": "c7", "label": "c7",
"format": "{{msg.payload}}", "format": "{{msg.payload}}",
"layout": "row-right", "layout": "row-left",
"style": false, "style": false,
"font": "", "font": "",
"fontSize": 16, "fontSize": 16,
@@ -2670,17 +2659,17 @@
"name": "", "name": "",
"label": "Actionneur 0", "label": "Actionneur 0",
"format": "{{msg.payload}}", "format": "{{msg.payload}}",
"layout": "row-spread", "layout": "row-left",
"style": false, "style": false,
"font": "", "font": "",
"fontSize": 16, "fontSize": 16,
"color": "#717171", "color": "#717171",
"wrapText": false, "wrapText": false,
"className": "", "className": "",
"value": "payloads", "value": "payload",
"valueType": "msg", "valueType": "msg",
"x": 1870, "x": 890,
"y": 880, "y": 1920,
"wires": [] "wires": []
}, },
{ {
@@ -2688,23 +2677,23 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "6b44d4b22cd7b3dc", "group": "6b44d4b22cd7b3dc",
"order": 7, "order": 8,
"width": "2", "width": "2",
"height": "1", "height": "1",
"name": "", "name": "",
"label": "Actionneur 1", "label": "Actionneur 1",
"format": "{{msg.payload}}", "format": "{{msg.payload}}",
"layout": "row-spread", "layout": "row-left",
"style": false, "style": false,
"font": "", "font": "",
"fontSize": 16, "fontSize": 16,
"color": "#717171", "color": "#717171",
"wrapText": false, "wrapText": false,
"className": "", "className": "",
"value": "payloads", "value": "payload",
"valueType": "msg", "valueType": "msg",
"x": 1870, "x": 890,
"y": 920, "y": 1960,
"wires": [] "wires": []
}, },
{ {
@@ -2712,23 +2701,23 @@
"type": "ui-text", "type": "ui-text",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"group": "6b44d4b22cd7b3dc", "group": "6b44d4b22cd7b3dc",
"order": 10, "order": 11,
"width": "2", "width": "2",
"height": "1", "height": "1",
"name": "", "name": "",
"label": "Actionneur 2", "label": "Actionneur 2",
"format": "{{msg.payload}}", "format": "{{msg.payload}}",
"layout": "row-spread", "layout": "row-left",
"style": false, "style": false,
"font": "", "font": "",
"fontSize": 16, "fontSize": 16,
"color": "#717171", "color": "#717171",
"wrapText": false, "wrapText": false,
"className": "", "className": "",
"value": "payloads", "value": "payload",
"valueType": "msg", "valueType": "msg",
"x": 1870, "x": 890,
"y": 960, "y": 2000,
"wires": [] "wires": []
}, },
{ {
@@ -2788,8 +2777,8 @@
"links": [ "links": [
"e5da08ba69fe6fb8" "e5da08ba69fe6fb8"
], ],
"x": 655, "x": 665,
"y": 1940, "y": 2100,
"wires": [] "wires": []
}, },
{ {
@@ -2797,7 +2786,7 @@
"type": "function", "type": "function",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"name": "s9 🠙", "name": "s9 🠙",
"func": "msg.ui_update = msg.payload.s9 == 1 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\nglobal.set(\"s9\", msg.payload.s9);\nreturn msg;", "func": "msg.ui_update = msg.payload.s9 < 0 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\n\nif (msg.payload.s9 > 0)\n global.set(\"s9\", 1);\nelse if (msg.payload.s9 < 0)\n global.set(\"s9\", -1);\nelse \n global.set(\"s9\", 0);\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
"noerr": 0, "noerr": 0,
@@ -2817,7 +2806,7 @@
"type": "function", "type": "function",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"name": "s9 🠛", "name": "s9 🠛",
"func": "msg.ui_update = msg.payload.s9 == 1 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\nreturn msg;", "func": "msg.ui_update = msg.payload.s9 > 0 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\nreturn msg;",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
"noerr": 0, "noerr": 0,
@@ -2971,7 +2960,10 @@
"397735dd2560f7cf", "397735dd2560f7cf",
"963da6ffcbd90744", "963da6ffcbd90744",
"1f5adfcb29a89bb1", "1f5adfcb29a89bb1",
"100a58f1b621c53a" "100a58f1b621c53a",
"29d203e016b983f6",
"e41bd818da135c8c",
"e7b6444f18166784"
] ]
] ]
}, },
@@ -3030,7 +3022,7 @@
"id": "ffe1e88c3c60e495", "id": "ffe1e88c3c60e495",
"type": "function", "type": "function",
"z": "86a34ee77bf6db10", "z": "86a34ee77bf6db10",
"name": "function 3", "name": "x30",
"func": "msg.payload = msg.payload * 30;\nreturn msg;", "func": "msg.payload = msg.payload * 30;\nreturn msg;",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
@@ -3038,7 +3030,7 @@
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 1680, "x": 1670,
"y": 760, "y": 760,
"wires": [ "wires": [
[ [
@@ -3106,6 +3098,66 @@
[] []
] ]
}, },
{
"id": "29d203e016b983f6",
"type": "function",
"z": "86a34ee77bf6db10",
"name": "a0",
"func": "msg.payload = Number(msg.payload.a0) ? \"🟩\" : \"🟥\";\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 1920,
"wires": [
[
"c219b897538f7dfd"
]
]
},
{
"id": "e41bd818da135c8c",
"type": "function",
"z": "86a34ee77bf6db10",
"name": "a1",
"func": "msg.payload = Number(msg.payload.a1) ? \"🟩\" : \"🟥\";\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 1960,
"wires": [
[
"74204db55792e5ad"
]
]
},
{
"id": "e7b6444f18166784",
"type": "function",
"z": "86a34ee77bf6db10",
"name": "a2",
"func": "msg.payload = Number(msg.payload.a2) ? \"🟩\" : \"🟥\";\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 2000,
"wires": [
[
"8d5eb1827691bec4"
]
]
},
{ {
"id": "cefd0feeeaf4227c", "id": "cefd0feeeaf4227c",
"type": "function", "type": "function",
@@ -3937,7 +3989,6 @@
"id": "e5da08ba69fe6fb8", "id": "e5da08ba69fe6fb8",
"type": "link in", "type": "link in",
"z": "b5e17af18ea9731a", "z": "b5e17af18ea9731a",
"d": true,
"name": "link in 1", "name": "link in 1",
"links": [ "links": [
"397735dd2560f7cf" "397735dd2560f7cf"
@@ -4035,6 +4086,7 @@
"id": "978ded7ba3456f70", "id": "978ded7ba3456f70",
"type": "link in", "type": "link in",
"z": "93dc5b41180d0746", "z": "93dc5b41180d0746",
"d": true,
"name": "link in 2", "name": "link in 2",
"links": [ "links": [
"c613454bd48662e1" "c613454bd48662e1"

182
autom.cpp
View File

@@ -50,7 +50,8 @@ unsigned long millis()
int marche = 0; int marche = 0;
int arret = 1; int arret = 1;
int light = 0; int reset = 0;
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, s8, s9, s10, s11; int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
@@ -61,6 +62,16 @@ int p0;
int a0, a1, a2, a3, a4, a5, a6, a7; int a0, a1, a2, a3, a4, a5, a6, a7;
int c0, c1, c2, c3, c4, c5, c6, c7; int c0, c1, c2, c3, c4, c5, c6, c7;
int bouton[8];
int interrupteur[8];
int capteur[8];
int sortie[12];
int moteur[4];
int niveau[4];
int consigne[4];
int actionneur[8];
void process(); void process();
/* ******************************************************** /* ********************************************************
@@ -84,63 +95,97 @@ void mqtt_send(mqtt::async_client *client);
class callback : public virtual mqtt::callback class callback : public virtual mqtt::callback
{ {
public: public:
void message_arrived(mqtt::const_message_ptr msg) override { void message_arrived(mqtt::const_message_ptr msg) override
{
std::string payload = msg->to_string(); std::string payload = msg->to_string();
try { try
{
json j = json::parse(payload); json j = json::parse(payload);
marche = 0; arret = 1; marche = 0;
arret = 1;
b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = 0; b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = 0;
// Ne rien faire si l'objet JSON est vide // Ne rien faire si l'objet JSON est vide
if (j.empty()) return; if (j.empty())
return;
if (j.contains("marche")) marche = j["marche"].get<int>() != 0; if (j.contains("marche"))
if (j.contains("arret")) arret = j["arret"].get<int>() != 0; marche = j["marche"].get<int>() != 0;
if (j.contains("arret"))
arret = j["arret"].get<int>() != 0;
if (j.contains("reset"))
reset = j["reset"].get<int>() != 0;
if (j.contains("b0") && j["b0"].is_number()) if (j.contains("b0") && j["b0"].is_number())
b0 = j["b0"].get<int>(); {
bouton[0] = b0 = j["b0"].get<int>();
}
if (j.contains("b1") && j["b1"].is_number()) if (j.contains("b1") && j["b1"].is_number())
b1 = j["b1"].get<int>(); {
bouton[1] = b1 = j["b1"].get<int>();
}
if (j.contains("b2") && j["b2"].is_number()) if (j.contains("b2") && j["b2"].is_number())
b2 = j["b2"].get<int>(); {
bouton[2] = b2 = j["b2"].get<int>();
}
if (j.contains("b3") && j["b3"].is_number()) if (j.contains("b3") && j["b3"].is_number())
b3 = j["b3"].get<int>(); {
bouton[3] = b3 = j["b3"].get<int>();
}
if (j.contains("b4") && j["b4"].is_number()) if (j.contains("b4") && j["b4"].is_number())
b4 = j["b4"].get<int>(); {
bouton[4] = b4 = j["b4"].get<int>();
}
if (j.contains("b5") && j["b5"].is_number()) if (j.contains("b5") && j["b5"].is_number())
b5 = j["b5"].get<int>(); {
bouton[5] = b5 = j["b5"].get<int>();
}
if (j.contains("b6") && j["b6"].is_number()) if (j.contains("b6") && j["b6"].is_number())
b6 = j["b6"].get<int>(); {
bouton[6] = b6 = j["b6"].get<int>();
}
if (j.contains("b7") && j["b7"].is_number()) if (j.contains("b7") && j["b7"].is_number())
b7 = j["b7"].get<int>(); {
bouton[7] = b7 = j["b7"].get<int>();
}
if (j.contains("i0")) i0 = j["i0"].get<int>(); if (j.contains("i0"))
if (j.contains("i1")) i1 = j["i1"].get<int>(); interrupteur[0] = i0 = j["i0"].get<int>();
if (j.contains("i2")) i2 = j["i2"].get<int>(); if (j.contains("i1"))
if (j.contains("i3")) i3 = j["i3"].get<int>(); interrupteur[1] = i1 = j["i1"].get<int>();
if (j.contains("i4")) i4 = j["i4"].get<int>(); if (j.contains("i2"))
if (j.contains("i5")) i5 = j["i5"].get<int>(); interrupteur[2] = i2 = j["i2"].get<int>();
if (j.contains("i6")) i6 = j["i6"].get<int>(); if (j.contains("i3"))
if (j.contains("i7")) i7 = j["i7"].get<int>(); interrupteur[3] = i3 = j["i3"].get<int>();
if (j.contains("i4"))
interrupteur[4] = i4 = j["i4"].get<int>();
if (j.contains("i5"))
interrupteur[5] = i5 = j["i5"].get<int>();
if (j.contains("i6"))
interrupteur[6] = i6 = j["i6"].get<int>();
if (j.contains("i7"))
interrupteur[7] = i7 = j["i7"].get<int>();
if (j.contains("c0") && j["c0"].is_number()) if (j.contains("c0") && j["c0"].is_number())
c0 = j["c0"].get<int>(); capteur[0] = c0 = j["c0"].get<int>();
if (j.contains("c1") && j["c1"].is_number()) if (j.contains("c1") && j["c1"].is_number())
c1 = j["c1"].get<int>(); capteur[1] = c1 = j["c1"].get<int>();
if (j.contains("c2") && j["c2"].is_number()) if (j.contains("c2") && j["c2"].is_number())
c2 = j["c2"].get<int>(); capteur[2] = c2 = j["c2"].get<int>();
if (j.contains("c3") && j["c3"].is_number()) if (j.contains("c3") && j["c3"].is_number())
c3 = j["c3"].get<int>(); capteur[3] = c3 = j["c3"].get<int>();
if (j.contains("c4") && j["c4"].is_number()) if (j.contains("c4") && j["c4"].is_number())
c4 = j["c4"].get<int>(); capteur[4] = c4 = j["c4"].get<int>();
if (j.contains("c5") && j["c5"].is_number()) if (j.contains("c5") && j["c5"].is_number())
c5 = j["c5"].get<int>(); capteur[5] = c5 = j["c5"].get<int>();
if (j.contains("c6") && j["c6"].is_number()) if (j.contains("c6") && j["c6"].is_number())
c6 = j["c6"].get<int>(); capteur[6] = c6 = j["c6"].get<int>();
if (j.contains("c7") && j["c7"].is_number()) if (j.contains("c7") && j["c7"].is_number())
c7 = j["c7"].get<int>(); capteur[7] = c7 = j["c7"].get<int>();
if (j.contains("v0") && j["v0"].is_number()) if (j.contains("v0") && j["v0"].is_number())
v0 = j["v0"].get<int>(); v0 = j["v0"].get<int>();
@@ -151,7 +196,8 @@ public:
process(); process();
mqtt_send(&client); mqtt_send(&client);
} }
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";
} }
} }
@@ -159,21 +205,24 @@ public:
callback cb; callback cb;
void mqtt_open(mqtt::async_client* client) { void mqtt_open(mqtt::async_client *client)
{
client->set_callback(cb); client->set_callback(cb);
mqtt::connect_options connOpts; mqtt::connect_options connOpts;
connOpts.set_clean_session(true); connOpts.set_clean_session(true);
connOpts.set_user_name("admin"); connOpts.set_user_name("admin");
connOpts.set_password("geii2025"); connOpts.set_password("geii2025");
try { try
{
client->connect(connOpts)->wait(); client->connect(connOpts)->wait();
client->start_consuming(); client->start_consuming();
client->subscribe(TOPIC, QOS)->wait(); client->subscribe(TOPIC, QOS)->wait();
} catch (const mqtt::exception &exc) { }
catch (const mqtt::exception &exc)
{
std::cerr << "Erreur MQTT: " << exc.what() << "\n"; std::cerr << "Erreur MQTT: " << exc.what() << "\n";
} }
} }
void mqtt_send(mqtt::async_client *client) void mqtt_send(mqtt::async_client *client)
@@ -211,18 +260,21 @@ void mqtt_send(mqtt::async_client *client)
client->publish(msg); client->publish(msg);
} }
void mqtt_close() { void mqtt_close()
try { {
try
{
client.unsubscribe(TOPIC)->wait(); client.unsubscribe(TOPIC)->wait();
client.stop_consuming(); client.stop_consuming();
client.disconnect()->wait(); client.disconnect()->wait();
} catch(const mqtt::exception &exc){ }
catch (const mqtt::exception &exc)
{
std::cerr << "Erreur déconnexion MQTT: " << exc.what() << std::endl; std::cerr << "Erreur déconnexion MQTT: " << exc.what() << std::endl;
} }
} }
// ************************************************************ // ************************************************************
/* ******************************************************** /* ********************************************************
* TEMPORISATION RETARD A LA MONTEE * * TEMPORISATION RETARD A LA MONTEE *
* La sortie passe à 1 au bout de la tempo * * La sortie passe à 1 au bout de la tempo *
@@ -231,7 +283,7 @@ void mqtt_close() {
class TemporisationRetardMontee class TemporisationRetardMontee
{ {
// methodes // methodes
public : public:
// Contructeur qui prend la duree souhaitee de la temporisation // Contructeur qui prend la duree souhaitee de la temporisation
TemporisationRetardMontee(unsigned long duree) TemporisationRetardMontee(unsigned long duree)
{ {
@@ -243,7 +295,7 @@ class TemporisationRetardMontee
void activation() void activation()
{ {
// Capture du temps de reference // Capture du temps de reference
if(!captureTemps) if (!captureTemps)
{ {
debut = millis(); debut = millis();
captureTemps = true; captureTemps = true;
@@ -271,16 +323,16 @@ class TemporisationRetardMontee
// Interrogation du bit de fin de tempo // Interrogation du bit de fin de tempo
bool getSortie() bool getSortie()
{ {
return(sortie); return (sortie);
} }
// Recuperation du temps ecoule depuis le debut si necessaire // Recuperation du temps ecoule depuis le debut si necessaire
unsigned long getTempsEcoule() unsigned long getTempsEcoule()
{ {
return(tempsEcoule); return (tempsEcoule);
} }
// Attributs // Attributs
private: private:
unsigned long duree; unsigned long duree;
unsigned long debut; unsigned long debut;
unsigned long tempsEcoule; unsigned long tempsEcoule;
@@ -289,12 +341,12 @@ class TemporisationRetardMontee
}; };
/******************************************************** /********************************************************
* TEMPORISATION RETARD A LA DESCENTE * * TEMPORISATION RETARD A LA DESCENTE *
* La sortie passe à 0 au bout de la tempo * * La sortie passe à 0 au bout de la tempo *
*********************************************************/ *********************************************************/
class TemporisationRetardDescente class TemporisationRetardDescente
{ {
public : public:
// Contructeur qui prend la duree souhaitee de la temporisation // Contructeur qui prend la duree souhaitee de la temporisation
TemporisationRetardDescente(unsigned long duree) TemporisationRetardDescente(unsigned long duree)
{ {
@@ -306,7 +358,7 @@ class TemporisationRetardDescente
void activation() void activation()
{ {
// Capture du temps de reference // Capture du temps de reference
if(!captureTemps) if (!captureTemps)
{ {
debut = millis(); debut = millis();
captureTemps = true; captureTemps = true;
@@ -331,15 +383,15 @@ class TemporisationRetardDescente
// Interrogration du bit de fin de tempo // Interrogration du bit de fin de tempo
bool getSortie() bool getSortie()
{ {
return(sortie); return (sortie);
} }
// Recuperation du temps ecoule depuis le debut si necessaire // Recuperation du temps ecoule depuis le debut si necessaire
unsigned long getTempsEcoule() unsigned long getTempsEcoule()
{ {
return(tempsEcoule); return (tempsEcoule);
} }
private: private:
unsigned long duree; unsigned long duree;
unsigned long debut; unsigned long debut;
unsigned long tempsEcoule; unsigned long tempsEcoule;
@@ -353,7 +405,7 @@ class TemporisationRetardDescente
class Clignoteur class Clignoteur
{ {
// methodes // methodes
public : public:
// Construteur qui prend en parametre le temps haut ou bas souhaitee // Construteur qui prend en parametre le temps haut ou bas souhaitee
Clignoteur(int baseDeTemps) Clignoteur(int baseDeTemps)
{ {
@@ -366,7 +418,7 @@ class Clignoteur
} }
// Attributs // Attributs
private: private:
int baseDeTemps; int baseDeTemps;
}; };
@@ -377,7 +429,7 @@ class Clignoteur
class Compteur class Compteur
{ {
// methodes // methodes
public : public:
// Constructeur qui prend en parametre la valeur de preselection // Constructeur qui prend en parametre la valeur de preselection
Compteur(int valeurPreselection) Compteur(int valeurPreselection)
{ {
@@ -402,16 +454,16 @@ class Compteur
// recuperation de la valeur courante // recuperation de la valeur courante
int getValeurCourante() int getValeurCourante()
{ {
return(valeur); return (valeur);
} }
// est-ce que la preselection est atteinte (sortie Q compteur Siemens ou Schnieder) // est-ce que la preselection est atteinte (sortie Q compteur Siemens ou Schnieder)
bool getSortie() bool getSortie()
{ {
return(valeur == valeurPreselection); return (valeur == valeurPreselection);
} }
// Attributs // Attributs
private: private:
int valeur; int valeur;
int valeurPreselection; int valeurPreselection;
}; };
@@ -421,9 +473,9 @@ class Compteur
*********************************************************/ *********************************************************/
class MiseAEchelle class MiseAEchelle
{ {
public : public:
// Constructeur qui ne prend en parametre la plage d'entree et la plage de sortie // Constructeur qui ne prend en parametre la plage d'entree et la plage de sortie
MiseAEchelle(float minEntree,float maxEntree,float minSortie,float maxSortie) MiseAEchelle(float minEntree, float maxEntree, float minSortie, float maxSortie)
{ {
this->minEntree = minEntree; this->minEntree = minEntree;
this->maxEntree = maxEntree; this->maxEntree = maxEntree;
@@ -433,17 +485,17 @@ class MiseAEchelle
// fonction de conversion qui prend la valeur a convertir et renvoie la valeur convertie // fonction de conversion qui prend la valeur a convertir et renvoie la valeur convertie
float convertir(float valeurAConvertir) float convertir(float valeurAConvertir)
{ {
if(valeurAConvertir >= minEntree && valeurAConvertir <= maxEntree) if (valeurAConvertir >= minEntree && valeurAConvertir <= maxEntree)
{ {
float norm = (1 / (maxEntree - minEntree)) * (valeurAConvertir - minEntree); float norm = (1 / (maxEntree - minEntree)) * (valeurAConvertir - minEntree);
float scale = (maxSortie - minSortie) * norm + minSortie; float scale = (maxSortie - minSortie) * norm + minSortie;
return(scale); return (scale);
} }
return(-1000); return (-1000);
} }
// Attributs // Attributs
private: private:
float minEntree; float minEntree;
float minSortie; float minSortie;
float maxEntree; float maxEntree;

View File

@@ -9,6 +9,10 @@ int marche_frontmontant = 0;
int arret_precedent = 1; int arret_precedent = 1;
int arret_frontdescedant = 0; int arret_frontdescedant = 0;
int bouton_precedent[8];
int bouton_frontmontant[8];
int bouton_frontdescendant[8];
int b0_precedent = 0; int b0_precedent = 0;
int b0_frontmontant = 0; int b0_frontmontant = 0;
int b1_precedent = 0; int b1_precedent = 0;
@@ -33,11 +37,15 @@ int sens = 1;
int ci = 0; int ci = 0;
int mode_auto = 0; int mode_auto = 0;
int mode_manu = 0;
int etape = 0; int etape = 0;
int etape_2 = 0;
int c5_frontdescendant = 0; int c5_frontdescendant = 0;
int c5_precedent = 0; int c5_precedent = 0;
int main() int main()
{ {
mqtt_open(&client); mqtt_open(&client);
@@ -56,33 +64,76 @@ int main()
void process() { void process() {
// Détection du front montant (état courant supérieur à l'état précédent) // Détection du front montant (état courant supérieur à l'état précédent)
b0_frontmontant = b0 > b0_precedent; for(int i = 0; i < 8 ; i++) {
b1_frontmontant = b1 > b1_precedent; bouton_frontmontant[i] = bouton[i] > bouton_precedent[i];
b2_frontmontant = b2 > b2_precedent; bouton_frontdescendant[i] = bouton[i] < bouton_precedent[i];
b3_frontmontant = b3 > b3_precedent; }
b4_frontmontant = b4 > b4_precedent;
b5_frontmontant = b5 > b5_precedent;
b6_frontmontant = b6 > b6_precedent;
b7_frontmontant = b7 > b7_precedent;
marche_frontmontant = marche > marche_precedent; marche_frontmontant = marche > marche_precedent;
arret_frontdescedant = arret < arret_precedent; arret_frontdescedant = arret < arret_precedent;
c5_frontdescendant = c5 < c5_precedent;
m0 = i0; /*
m1 = i1; int etape_suivante = etape;
int etape_suivante2 = etape_2;
if (etape == 0 && b6_frontmontant == 1) {
etape_suivante = 1;
}
if (etape == 1 && b6_frontmontant == 1) {
etape_suivante = 0;
}
if (etape_2 == 0 && b7_frontmontant == 1)
{
etape_suivante2 = 1;
}
if (etape_2 == 1 && b7_frontmontant == 1)
{
etape_suivante2 = 0;
}
etape = etape_suivante;
etape_2 = etape_suivante2;
m0 = etape == 1;
m1 = etape_2 == 1;
*/
if (b6_frontmontant) {
m0 = !m0;
}
if (b7_frontmontant) {
m1 = !m1;
}
if (abs(p0 - v0) < 3) {
m0 = m1 = 0;
} else {
if (p0 < v0)
{
m0 = 1;
m1 = 0;
}
if (p0 > v0)
{
m0 = 0;
m1 = 1;
}
}
// Prêt pour un nouveau tour // Prêt pour un nouveau tour
// L'état courant devient l'état précédent // L'état courant devient l'état précédent
b0_precedent = b0; for (int i = 0; i < 8; i++) {
b1_precedent = b1; bouton_precedent[i] = bouton[i];
b2_precedent = b2; }
b3_precedent = b3;
b4_precedent = b4;
b5_precedent = b5;
b6_precedent = b6;
b7_precedent = b7;
marche_precedent = marche; marche_precedent = marche;
arret_precedent = arret; arret_precedent = arret;
c5_precedent = c5;
} }