Skip to content

Instantly share code, notes, and snippets.

@johnty
Created June 7, 2017 21:13
Show Gist options
  • Select an option

  • Save johnty/6aa1ceea0f28c027a0f67904d5b9d16c to your computer and use it in GitHub Desktop.

Select an option

Save johnty/6aa1ceea0f28c027a0f67904d5b9d16c to your computer and use it in GitHub Desktop.
node-red MQTT roundtrip latency calculator
[
{
"id": "e0241b25.e1c018",
"type": "mqtt in",
"z": "eeecba5a.679b68",
"name": "",
"topic": "/pishield/pingtest2",
"qos": "1",
"broker": "858b78cb.00a038",
"x": 194,
"y": 225,
"wires": [
[
"f3b4dc48.7a2b2"
]
]
},
{
"id": "fa833e4a.530df",
"type": "mqtt out",
"z": "eeecba5a.679b68",
"name": "",
"topic": "/pishield/pingtest2",
"qos": "1",
"retain": "",
"broker": "858b78cb.00a038",
"x": 502,
"y": 97,
"wires": []
},
{
"id": "e98937ae.598f98",
"type": "inject",
"z": "eeecba5a.679b68",
"name": "",
"topic": "timestamp",
"payload": "",
"payloadType": "date",
"repeat": ".1",
"crontab": "",
"once": false,
"x": 258.5,
"y": 97,
"wires": [
[
"fa833e4a.530df",
"f3b4dc48.7a2b2"
]
]
},
{
"id": "faaa021b.feef4",
"type": "debug",
"z": "eeecba5a.679b68",
"name": "",
"active": false,
"console": "false",
"complete": "false",
"x": 572.5,
"y": 203,
"wires": []
},
{
"id": "f3b4dc48.7a2b2",
"type": "function",
"z": "eeecba5a.679b68",
"name": "deltaT",
"func": "\nvar prev = flow.get('prev')||0;\n\nvar d = new Date();\nvar n = d.getMilliseconds();\n\nif (msg.topic == \"timestamp\"){\n flow.set('prev', n);\n}\n \nelse {\n if (n<prev) {\n console.log(\"OVERFLOW!\");\n n=n+1000;\n }\n console.log(\"tDiff = \",n,\"-\",prev,\"=\",n-prev);\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 386.5,
"y": 226,
"wires": [
[
"faaa021b.feef4"
]
]
},
{
"id": "858b78cb.00a038",
"type": "mqtt-broker",
"z": "",
"broker": "raspberrypi.local",
"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