flow: update IP detection to include Ethernet

This commit is contained in:
Romain Bazile 2021-10-29 15:54:46 +02:00
parent 24e28d88ff
commit e6ea8cc6af

View file

@ -733,24 +733,6 @@
"width": "6", "width": "6",
"collapse": false "collapse": false
}, },
{
"id": "bfec963a.5a4988",
"type": "ui_spacer",
"name": "spacer",
"group": "9e409235.73cd7",
"order": 4,
"width": 6,
"height": 1
},
{
"id": "91dfe8eb.658218",
"type": "ui_spacer",
"name": "spacer",
"group": "9e409235.73cd7",
"order": 5,
"width": 6,
"height": 1
},
{ {
"id": "fc5e4e6f.5b1c8", "id": "fc5e4e6f.5b1c8",
"type": "ui_group", "type": "ui_group",
@ -5169,7 +5151,7 @@
"tooltip": "", "tooltip": "",
"place": "Select a WIFI", "place": "Select a WIFI",
"group": "9e409235.73cd7", "group": "9e409235.73cd7",
"order": 2, "order": 1,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@ -5191,7 +5173,7 @@
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"name": "", "name": "",
"group": "9e409235.73cd7", "group": "9e409235.73cd7",
"order": 1, "order": 2,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@ -5242,18 +5224,19 @@
"id": "4c0400c.69a1e8", "id": "4c0400c.69a1e8",
"type": "exec", "type": "exec",
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"command": "ifconfig wlan0", "command": "ip -j addr show",
"addpay": false, "addpay": false,
"append": "", "append": "",
"useSpawn": "false", "useSpawn": "false",
"timer": "", "timer": "",
"winHide": false,
"oldrc": false, "oldrc": false,
"name": "getInfo", "name": "getInfo",
"x": 460, "x": 460,
"y": 180, "y": 180,
"wires": [ "wires": [
[ [
"bcb20e39.00cea8" "88e05f37a8745216"
], ],
[], [],
[] []
@ -5264,7 +5247,7 @@
"type": "function", "type": "function",
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"name": "parse IP Info", "name": "parse IP Info",
"func": "var ip = \"planktoscope.local\";\nvar mask = \"\";\nvar broadcast = \"\";\n\nif (msg.payload !== null){\n ip = msg.payload.match(/inet ([0-9\\.]+)/)[1];\n mask = msg.payload.match(/netmask ([0-9\\.]+)/)[1];\n broadcast = msg.payload.match(/broadcast ([0-9\\.]+)/)[1];\n}\n\nreturn [{topic: 'ip', payload: ip},{topic: 'mask', payload: mask},{topic: 'broadcast', payload: broadcast}]", "func": "var ip = \"\";\nvar broadcast = \"\";\nvar iface = \"\";\nvar iface_up = false;\n\nif (msg.rc.code === 0){\n payload = msg.payload\n for (let info in payload) {\n if (payload[info].operstate === \"UP\") {\n \tif (iface_up){\n \t// We have two concurrent interfaces up\n // We need to deactivate one\n ip = \"Remove Ethernet cable or disconnect wifi\"\n broadcast = \"Remove Ethernet cable or disconnect wifi\"\n iface = \"Remove Ethernet cable or disconnect wifi\"\n break\n }\n if (payload[info].ifname === \"eth0\") {\n iface = \"Ethernet\"\n } else if (payload[info].ifname === \"wifi0\") {\n iface = \"Wifi\"\n }\n ip = payload[info].addr_info[0].local;\n broadcast = payload[info].addr_info[0].broadcast;\n iface_up = true;\n }\n }\n}\n\nif (iface_up) {\n return([{\n topic: 'interface',\n payload: iface\n }, {\n topic: 'ip',\n payload: ip\n }, {\n topic: 'broadcast',\n payload: broadcast\n }])\n}\n",
"outputs": 3, "outputs": 3,
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
@ -5274,19 +5257,19 @@
"y": 180, "y": 180,
"wires": [ "wires": [
[ [
"d71c8185.800fd", "67d052ba.99ff24"
"49111a72f4e32740"
], ],
[ [
"67d052ba.99ff24" "d71c8185.800fd",
"49111a72f4e32740"
], ],
[ [
"dc305a26.b33fc" "dc305a26.b33fc"
] ]
], ],
"outputLabels": [ "outputLabels": [
"interface",
"ip", "ip",
"mask",
"broadcast" "broadcast"
] ]
}, },
@ -5303,7 +5286,7 @@
"format": "{{msg.payload || '---'}}", "format": "{{msg.payload || '---'}}",
"layout": "row-spread", "layout": "row-spread",
"x": 930, "x": 930,
"y": 140, "y": 180,
"wires": [] "wires": []
}, },
{ {
@ -5311,15 +5294,15 @@
"type": "ui_text", "type": "ui_text",
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"group": "919923a3.d10868", "group": "919923a3.d10868",
"order": 3, "order": 1,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
"label": "Netmask", "label": "Interface",
"format": "{{msg.payload || '---'}}", "format": "{{msg.payload || '---'}}",
"layout": "row-spread", "layout": "row-spread",
"x": 940, "x": 940,
"y": 180, "y": 140,
"wires": [] "wires": []
}, },
{ {
@ -5327,7 +5310,7 @@
"type": "ui_text", "type": "ui_text",
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"group": "919923a3.d10868", "group": "919923a3.d10868",
"order": 4, "order": 3,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@ -5424,7 +5407,7 @@
"type": "ui_text", "type": "ui_text",
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"group": "919923a3.d10868", "group": "919923a3.d10868",
"order": 1, "order": 4,
"width": 0, "width": 0,
"height": 0, "height": 0,
"name": "", "name": "",
@ -5440,11 +5423,12 @@
"type": "function", "type": "function",
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"name": "parse SSID", "name": "parse SSID",
"func": "if (msg.payload !== null){\n var ssid = msg.payload.match(/ESSID:\"([^\"]+)\"/)[1];\n}\nelse\n{\n var ssid = \"\";\n}\n\n\nnode.send({topic: 'ssid', payload: ssid})\n", "func": "var ssid = \"\"\n\nif (msg.rc.code === 0){\n ssid = msg.payload.match(/ESSID:\"([^\"]+)\"/)[1];\n return({topic: 'ssid', payload: ssid})\n}\n",
"outputs": 1, "outputs": 1,
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [],
"x": 730, "x": 730,
"y": 260, "y": 260,
"wires": [ "wires": [
@ -5510,7 +5494,7 @@
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"name": "", "name": "",
"group": "9e409235.73cd7", "group": "9e409235.73cd7",
"order": 7, "order": 5,
"width": 3, "width": 3,
"height": 1, "height": 1,
"passthru": false, "passthru": false,
@ -5538,7 +5522,7 @@
"label": "Country Code", "label": "Country Code",
"tooltip": "ISO/IEC alpha2 country code", "tooltip": "ISO/IEC alpha2 country code",
"group": "9e409235.73cd7", "group": "9e409235.73cd7",
"order": 6, "order": 4,
"width": 3, "width": 3,
"height": 1, "height": 1,
"passthru": true, "passthru": true,
@ -7629,7 +7613,7 @@
"z": "f21ba04.c26266", "z": "f21ba04.c26266",
"name": "", "name": "",
"group": "9e409235.73cd7", "group": "9e409235.73cd7",
"order": 8, "order": 6,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@ -10941,5 +10925,21 @@
"448b4c37.be50bc" "448b4c37.be50bc"
] ]
] ]
},
{
"id": "88e05f37a8745216",
"type": "json",
"z": "f21ba04.c26266",
"name": "",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 590,
"y": 180,
"wires": [
[
"bcb20e39.00cea8"
]
]
} }
] ]