Hello there,
I have a flow to read values from my Heating-Systems Web-UI an puts the data into an SQL-DB. The Flow is working quite well, but it looks somehow complex and not easy to maintain or extend.
The current Flow looks like:
[
{
"id": "7e55d0324dd88ad2",
"type": "tab",
"label": "LWZ8_demo",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c42ac73334295e3e",
"type": "http request",
"z": "7e55d0324dd88ad2",
"name": "LWZ",
"method": "GET",
"ret": "txt",
"paytoqs": "ignore",
"url": "1.2.3.5/?s=1,0",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 130,
"y": 140,
"wires": [
[
"98a4e947e9cb0deb"
]
]
},
{
"id": "19f75c83a6346f27",
"type": "inject",
"z": "7e55d0324dd88ad2",
"name": "60 sec",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "60",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 110,
"y": 80,
"wires": [
[
"c42ac73334295e3e"
]
]
},
{
"id": "8a2baf53a4617165",
"type": "debug",
"z": "7e55d0324dd88ad2",
"name": "debug 3",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 340,
"y": 260,
"wires": []
},
{
"id": "98a4e947e9cb0deb",
"type": "html",
"z": "7e55d0324dd88ad2",
"name": "",
"property": "payload",
"outproperty": "payload",
"tag": "form",
"ret": "html",
"as": "multi",
"x": 130,
"y": 200,
"wires": [
[
"a7b95e20be8a62bb"
]
]
},
{
"id": "a7b95e20be8a62bb",
"type": "html",
"z": "7e55d0324dd88ad2",
"name": "",
"property": "payload",
"outproperty": "payload",
"tag": "tr td",
"ret": "text",
"as": "single",
"x": 130,
"y": 260,
"wires": [
[
"8a2baf53a4617165",
"fa7e6986e291772e"
]
]
},
{
"id": "f89b766ced76cebf",
"type": "debug",
"z": "7e55d0324dd88ad2",
"name": "debug 4",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 540,
"y": 80,
"wires": []
},
{
"id": "fa7e6986e291772e",
"type": "function",
"z": "7e55d0324dd88ad2",
"name": "parse http",
"func": "\n\nvar raumIstTempHK1 = parseInt(msg.payload[1].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar raumSollTempHK1 = parseInt(msg.payload[3].replace(/([^A-Z0-9]+)/gi, '')) / 10;\nvar raumHumHK1 = parseInt(msg.payload[5].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar raumIstTempHK2 = parseInt(msg.payload[7].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar raumSollTempHK2 = parseInt(msg.payload[9].replace(/([^A-Z0-9]+)/gi, '')) / 10;\nvar raumHumHK2 = parseInt(msg.payload[11].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar aussenTemp = parseInt(msg.payload[13].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar istWertHK1 = parseInt(msg.payload[15].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar sollWertHK1 = parseInt(msg.payload[17].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar vorlaufTemp = parseInt(msg.payload[23].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar ruecklaufTemp = parseInt(msg.payload[25].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar druckHK = parseInt(msg.payload[27].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar volumenHK = parseInt(msg.payload[29].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar warmWasserIstTemp = parseInt(msg.payload[31].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar warmWasserSollTemp = parseInt(msg.payload[33].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar zuLuftIst = parseInt(msg.payload[35].replace(/([^a-z0-9]+)/gi, ''));\nvar zuLuftSoll = parseInt(msg.payload[37].replace(/([^a-z0-9]+)/gi, ''));\nvar abLuftIst = parseInt(msg.payload[39].replace(/([^a-z0-9]+)/gi, ''));\nvar abLuftSoll = parseInt(msg.payload[41].replace(/([^a-z0-9]+)/gi, ''));\nvar abLuftHum = parseInt(msg.payload[43].replace(/([^a-z0-9]+)/gi, ''));\nvar abLuftTemp = parseInt(msg.payload[45].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar abLuftDew = parseInt(msg.payload[47].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar diffDruck = parseInt(msg.payload[49].replace(/([^a-z0-9]+)/gi, ''));\nvar dewPointHK1 = parseInt(msg.payload[51].replace(/([^a-z0-9]+)/gi, '')) / 10;\nvar heizStufe = parseInt(msg.payload[55].replace(/([^a-z0-9]+)/gi, ''));\n\n\nif (Number.isNaN(raumIstTempHK1) === true) {\n raumIstTempHK1 = 0;\n}\nif (Number.isNaN(raumSollTempHK1) === true) {\n raumSollTempHK1 = 0;\n}\nif (Number.isNaN(raumHumHK1) === true) {\n raumHumHK1 = 0;\n}\nif (Number.isNaN(raumIstTempHK2) === true) {\n raumIstTempHK2 = 0;\n}\nif (Number.isNaN(raumSollTempHK2) === true) {\n raumSollTempHK2 = 0;\n}\nif (Number.isNaN(raumHumHK2) === true) {\n raumHumHK2 = 0;\n}\nif (Number.isNaN(aussenTemp) === true) {\n aussenTemp = 0;\n}\nif (Number.isNaN(istWertHK1) === true) {\n istWertHK1 = 0;\n}\nif (Number.isNaN(sollWertHK1) === true) {\n sollWertHK1 = 0;\n}\nif (Number.isNaN(vorlaufTemp) === true) {\n vorlaufTemp = 0;\n}\nif (Number.isNaN(ruecklaufTemp) === true) {\n ruecklaufTemp = 0;\n}\nif (Number.isNaN(druckHK) === true) {\n druckHK = 0;\n}\nif (Number.isNaN(volumenHK) === true) {\n volumenHK = 0;\n}\nif (Number.isNaN(warmWasserIstTemp) === true) {\n warmWasserIstTemp = 0;\n}\nif (Number.isNaN(warmWasserSollTemp) === true) {\n warmWasserSollTemp = 0;\n}\nif (Number.isNaN(zuLuftIst) === true) {\n zuLuftIst = 0;\n}\nif (Number.isNaN(zuLuftSoll) === true) {\n zuLuftSoll = 0;\n}\nif (Number.isNaN(abLuftIst) === true) {\n abLuftIst = 0;\n}\nif (Number.isNaN(abLuftHum) === true) {\n abLuftHum = 0;\n}\nif (Number.isNaN(abLuftTemp) === true) {\n abLuftTemp = 0;\n}\nif (Number.isNaN(diffDruck) === true) {\n diffDruck = 0;\n}\nif (Number.isNaN(dewPointHK1) === true) {\n dewPointHK1 = 0;\n}\nif (Number.isNaN(heizStufe) === true) {\n heizStufe = 0;\n}\n\n\nmsg.payload = {\n \"raumIstTempHK1\": raumIstTempHK1,\n \"raumSollTempHK1\": raumSollTempHK1,\n \"raumHumHK1\": raumHumHK1,\n \"raumIstTempHK2\": raumIstTempHK2,\n \"raumSollTempHK2\": raumSollTempHK2,\n \"raumHumHK2\": raumHumHK2,\n \"aussenTemp\": aussenTemp,\n \"istWertHK1\": istWertHK1,\n \"sollWertHK1\": sollWertHK1,\n \"vorlaufTemp\": vorlaufTemp,\n \"ruecklaufTemp\": ruecklaufTemp,\n \"druckHK\": druckHK,\n \"volumenHK\": volumenHK,\n \"warmWasserIstTemp\": warmWasserIstTemp,\n \"warmWasserSollTemp\": warmWasserSollTemp,\n \"zuLuftIst\": zuLuftIst,\n \"zuLuftSoll\": zuLuftSoll,\n \"abLuftIst\": abLuftIst,\n \"abLuftSoll\": abLuftSoll,\n \"abLuftHum\": abLuftHum,\n \"abLuftTemp\": abLuftTemp,\n \"diffDruck\": diffDruck,\n \"dewPointHK1\": dewPointHK1,\n \"heizStufe\": heizStufe\n}\n\nglobal.set(\"LWZ8\", msg.payload);\n\n//msg.topic = \"INSERT INTO \";\n//msg.topic += \"LWZ8data (`raumIstTempHK1`, `raumSollTempHK1`) \";\n//msg.topic += \"VALUES (:raumIstTempHK1, :raumSollTempHK1) ;\";\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 340,
"y": 80,
"wires": [
[
"f89b766ced76cebf",
"a907ae44178c34b5"
]
]
},
{
"id": "754cfb58fe23aa95",
"type": "mysql",
"z": "7e55d0324dd88ad2",
"mydb": "bad9129a2fbd0408",
"name": "",
"x": 370,
"y": 200,
"wires": [
[
"c50df9b4bb49c229"
]
]
},
{
"id": "c50df9b4bb49c229",
"type": "debug",
"z": "7e55d0324dd88ad2",
"name": "debug 7",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 540,
"y": 200,
"wires": []
},
{
"id": "a907ae44178c34b5",
"type": "function",
"z": "7e55d0324dd88ad2",
"name": "Add SQL-Query",
"func": "\n/* msg.payload = {\n \"raumIstTempHK1\": raumIstTempHK1,\n \"raumSollTempHK1\": raumSollTempHK1,\n \"raumHumHK1\": raumHumHK1,\n \"raumIstTempHK2\": raumIstTempHK2,\n \"raumSollTempHK2\": raumSollTempHK2,\n \"raumHumHK2\": raumHumHK2,\n \"aussenTemp\": aussenTemp,\n \"istWertHK1\": istWertHK1,\n \"sollWertHK1\": sollWertHK1,\n \"vorlaufTemp\": vorlaufTemp,\n \"ruecklaufTemp\": ruecklaufTemp,\n \"druckHK\": druckHK,\n \"volumenHK\": volumenHK,\n \"warmWasserIstTemp\": warmWasserIstTemp,\n \"warmWasserSollTemp\": warmWasserSollTemp,\n \"zuLuftIst\": zuLuftIst,\n \"zuLuftSoll\": zuLuftSoll,\n \"abLuftIst\": abLuftIst,\n \"abLuftSoll\": abLuftSoll,\n \"abLuftHum\": abLuftHum,\n \"abLuftTemp\": abLuftTemp,\n \"diffDruck\": diffDruck,\n \"dewPointHK1\": dewPointHK1,\n \"heizStufe\": heizStufe\n}*/\n\nmsg.topic = \"INSERT INTO \";\nmsg.topic += \"LWZ8data (`raumIstTempHK1`, `raumSollTempHK1`, `raumHumHK1`, `raumIstTempHK2`, `raumSollTempHK2`, `raumHumHK2`, `aussenTemp`, `istWertHK1`, `sollWertHK1`, `vorlaufTemp`, `ruecklaufTemp`, `druckHK`, `volumenHK`, `warmWasserIstTemp`, `warmWasserSollTemp`, `zuLuftIst`, `zuLuftSoll`, `abLuftIst`, `abLuftSoll`, `abLuftHum`, `abLuftTemp`, `diffDruck`, `dewPointHK1`, `heizStufe`) \";\nmsg.topic += \"VALUES (:raumIstTempHK1, :raumSollTempHK1, :raumHumHK1, :raumIstTempHK2, :raumSollTempHK2, :raumHumHK2, :aussenTemp, :istWertHK1, :sollWertHK1, :vorlaufTemp, :ruecklaufTemp, :druckHK, :volumenHK, :warmWasserIstTemp, :warmWasserSollTemp, :zuLuftIst, :zuLuftSoll, :abLuftIst, :abLuftSoll, :abLuftHum, :abLuftTemp, :diffDruck, :dewPointHK1, :heizStufe) ;\";\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 140,
"wires": [
[
"754cfb58fe23aa95"
]
]
},
{
"id": "13541ad04c954189",
"type": "debug",
"z": "7e55d0324dd88ad2",
"name": "debug 26",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1230,
"y": 740,
"wires": []
},
{
"id": "bad9129a2fbd0408",
"type": "MyDB",
"name": "",
"host": "1.2.3.4",
"port": "3306",
"db": "MyDB",
"tz": "",
"charset": "UTF8"
}
]
What I've implemented so far is mainly the first page of the WEB-UI several more left...
HTML-parcing is not the main issue, but extending the SQL-Query manually is quite annoying, as well as extending the DB.
If someone is willing to help me improve the concept any advice is highly appreciated.
Best Regards
Michael