Skip to content

Instantly share code, notes, and snippets.

@pradyumnac
Created November 22, 2017 13:45
Show Gist options
  • Save pradyumnac/66d5e980154b07bc3411b96fb3709e5b to your computer and use it in GitHub Desktop.
Save pradyumnac/66d5e980154b07bc3411b96fb3709e5b to your computer and use it in GitHub Desktop.
Node Red flow to reconnect IPACCT based Internet connection (Alliance - kolkata). Adjust your gateway ip , username and password before deploy. To use, import from nodered
[{
"id": "c0559cc8.1dad9",
"type": "tab",
"label": "Reconnect IPACCT",
"disabled": false,
"info": "Reconnects alliance internet on ipacct"
},
{
"id": "fd308698.8ce298",
"type": "debug",
"z": "c0559cc8.1dad9",
"name": "netping",
"active": true,
"console": "false",
"complete": "payload",
"x": 540,
"y": 60,
"wires": []
},
{
"id": "5a2164e2.30d97c",
"type": "ping",
"z": "c0559cc8.1dad9",
"name": "checkalive",
"host": "www.google.com",
"timer": "5",
"x": 141,
"y": 249,
"wires": [["28239459.e1c00c"]]
},
{
"id": "28239459.e1c00c",
"type": "switch",
"z": "c0559cc8.1dad9",
"name": "ifalive",
"property": "payload",
"propertyType": "msg",
"rules": [{
"t": "gt",
"v": "0",
"vt": "num"
},
{
"t": "else"
}],
"checkall": "true",
"outputs": 2,
"x": 340,
"y": 249,
"wires": [["fd308698.8ce298"],
["2075444b.c0abbc",
"252b9bf3.722eb4",
"e99e6078.54aeb"]]
},
{
"id": "2075444b.c0abbc",
"type": "mqtt out",
"z": "c0559cc8.1dad9",
"name": "No-Internet",
"topic": "nointernet",
"qos": "",
"retain": "",
"broker": "e8bac9ec.d09928",
"x": 557,
"y": 117,
"wires": []
},
{
"id": "6d0bcc10.8e6c04",
"type": "http request",
"z": "c0559cc8.1dad9",
"name": "connectnet",
"method": "POST",
"ret": "txt",
"url": "<GATEWAYIP>",
"tls": "",
"x": 490,
"y": 320,
"wires": [["539dae3e.d61f1"]],
"inputLabels": ["<form class=\"loginform\" method=\"post\"> \t\t<fieldset> \t\t\t<legend>Internet Access Log-in</legend> \t\t\t<div> \t\t\t\t<label for=\"username\">Username:</label> <input class=\"logininput\" type=\"text\" id=\"username\" name=\"user\"> \t\t\t</div> \t\t\t<div> \t\t\t\t<label for=\"password\">Password:</label> <input class=\"logininput\" type=\"password\" id=\"password\" name=\"pass\"> \t\t\t</div> \t\t</fieldset> \t<div><button type=\"submit\" name=\"login\" value=\"Login\" class=\"btnlink1\">Login </button></div> \t<br><br> </form>"]
},
{
"id": "3a0e9598.c7eefa",
"type": "mqtt out",
"z": "c0559cc8.1dad9",
"name": "netconnected",
"topic": "netconnected",
"qos": "",
"retain": "",
"broker": "e8bac9ec.d09928",
"x": 700,
"y": 340,
"wires": []
},
{
"id": "252b9bf3.722eb4",
"type": "function",
"z": "c0559cc8.1dad9",
"name": "genpostdata",
"func": "msg.payload={\n \"user\": \"<USERNAME>\",\n \"pass\": \"<PASSWORD>\",\n \"login\": \"login\"\n \n}\nmsg.headers = {\n \"Host\": \"10.254.254.64\",\n \"Connection\": \"keep-alive\",\n \"Content-Length\": 39,\n \"Cache-Control\": \"max-age=0\",\n \"Origin\": \"http://<GATEWAYIP>\",\n \"Upgrade-Insecure-Requests\": 1,\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36\",\n \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\",\n \"Referer\": \"http://10.254.254.64/0/up/\",\n \"Accept-Encoding\": \"gzip, deflate\",\n \"Accept-Language\": \"en-US,en;q=0.8\",\n\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 180,
"wires": [["6d0bcc10.8e6c04"]]
},
{
"id": "4c871882.ebc958",
"type": "debug",
"z": "c0559cc8.1dad9",
"name": "connestb",
"active": true,
"console": "false",
"complete": "payload",
"x": 680,
"y": 400,
"wires": []
},
{
"id": "e99e6078.54aeb",
"type": "debug",
"z": "c0559cc8.1dad9",
"name": "nointernet",
"active": true,
"console": "false",
"complete": "payload",
"x": 220,
"y": 340,
"wires": []
},
{
"id": "539dae3e.d61f1",
"type": "function",
"z": "c0559cc8.1dad9",
"name": "checkifsuccess",
"func": "response = msg.payload;\nif(response.includes(\"Your Internet connection is configured properly.\")){\n msg.payload = \"connected\";\n}\nelse {\n msg.payload = \"failed\";\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 480,
"y": 400,
"wires": [["4c871882.ebc958",
"3a0e9598.c7eefa"]]
},
{
"id": "e8bac9ec.d09928",
"type": "mqtt-broker",
"z": "",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"willTopic": "",
"willQos": "0",
"willPayload": "",
"birthTopic": "",
"birthQos": "0",
"birthPayload": ""
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment