Skip to content

Instantly share code, notes, and snippets.

@barzik
Last active January 29, 2022 19:58
Show Gist options
  • Save barzik/93f152b553f313fb52dfdfe8fe65e8fe to your computer and use it in GitHub Desktop.
Save barzik/93f152b553f313fb52dfdfe8fe65e8fe to your computer and use it in GitHub Desktop.
Internet Monitor for Raspberry Pi and Sensor HAT
[
{
"id": "fee7a583aa5c9a4b",
"type": "tab",
"label": "Internet Monitor",
"disabled": false,
"info": "",
"env": []
},
{
"id": "19b7c0da8bdfe80b",
"type": "rpi-sensehat out",
"z": "fee7a583aa5c9a4b",
"name": "",
"x": 850,
"y": 340,
"wires": []
},
{
"id": "5268382b89d11563",
"type": "debug",
"z": "fee7a583aa5c9a4b",
"name": "",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 650,
"y": 200,
"wires": []
},
{
"id": "b7f29914d1fdbedb",
"type": "function",
"z": "fee7a583aa5c9a4b",
"name": "GraphCreator",
"func": "const values = msg.payload;\nconst color = msg.color || 'green';\n\n\nconst reducer = (previousValue, currentValue, currentIndex) => {\n const calculatedValue = Math.abs(7-currentValue); \n\n const newColoumnString = `${currentIndex},0-${calculatedValue-1},red,${currentIndex},${calculatedValue}-7,${color},`;\n return previousValue + newColoumnString;\n};\n\nlet payload = values.reduce(reducer, values[0]);\n\n\nif(payload) {\n payload = payload.slice(1,-1);\n} else {\n payload = '*,*,off';\n}\n\nmsg.payload = payload;\n\n\nreturn msg;\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 780,
"y": 60,
"wires": [
[
"19b7c0da8bdfe80b"
]
]
},
{
"id": "7c61f8f465a90c13",
"type": "function",
"z": "fee7a583aa5c9a4b",
"name": "Turn off",
"func": "msg.payload = '*,*,off';\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 340,
"wires": [
[
"19b7c0da8bdfe80b"
]
]
},
{
"id": "c4e02638dfe0be79",
"type": "ping",
"z": "fee7a583aa5c9a4b",
"protocol": "Automatic",
"mode": "timed",
"name": "",
"host": "8.8.8.8",
"timer": "2",
"inputs": 0,
"x": 170,
"y": 240,
"wires": [
[
"6751ae1e484f65e7",
"5268382b89d11563"
]
]
},
{
"id": "6751ae1e484f65e7",
"type": "function",
"z": "fee7a583aa5c9a4b",
"name": "Adjusted Service Grade Calculator",
"func": "const MSToPing = msg.payload;\n\nlet adjustedServiceGrade;\n\nswitch (true) {\n case (MSToPing < 70):\n adjustedServiceGrade = 6;\n break;\n case (MSToPing < 73):\n adjustedServiceGrade = 5;\n break;\n case (MSToPing < 74):\n adjustedServiceGrade = 4;\n break;\n case (MSToPing < 75):\n adjustedServiceGrade = 3;\n break;\n case (MSToPing < 76):\n adjustedServiceGrade = 2;\n break;\n case (MSToPing < 77):\n adjustedServiceGrade = 1;\n break;\n default: \n adjustedServiceGrade = 0;\n\n}\n\nmsg.payload = adjustedServiceGrade;\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 300,
"y": 80,
"wires": [
[
"a03134c025de7740"
]
]
},
{
"id": "a03134c025de7740",
"type": "function",
"z": "fee7a583aa5c9a4b",
"name": "Push to context",
"func": "let pingData = flow.get('pingData');\n\nif(!pingData || !Array.isArray(pingData)) {\n pingData = [0,0,0,0,0,0,0,0];\n}\n\npingData.unshift(msg.payload);\n\npingData = pingData.slice(0,8);\n\nflow.set('pingData', pingData);\n\nmsg.payload = pingData;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 560,
"y": 80,
"wires": [
[
"b7f29914d1fdbedb"
]
]
},
{
"id": "fb0da61a1ba1dffd",
"type": "inject",
"z": "fee7a583aa5c9a4b",
"name": "Turn off",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 70,
"y": 340,
"wires": [
[
"7c61f8f465a90c13"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment