Hello,
I try to measure time between to 2 Messages.
I use epoch for each timestamp and substract it to the difference .
So timestamp A - timestamp B = Steptime.
So far so good.
I send with 1200ms so i get a Steptime around 1200ms.
But after i calculate with Steptime the result gets back to epoch values.
I tried to get Steptime to a number Datatype to let it "Forget" its epoch origin with parseInt() and Number() but Nothing works.
in the latest test i am uing the node simpletime, before that i used Date.now() to get the epoch time.
Is there a better solution to do that or get the time difference to a clear number ?
the part of the Code:
[
{
"id": "f0e77489.9c5de8",
"type": "simpletime",
"z": "9e82b6f8.933568",
"name": "",
"x": 1660,
"y": 450,
"wires": [
[
"5c359cda.ff5734",
"1e05b3d8.60ea2c"
]
]
},
{
"id": "5c359cda.ff5734",
"type": "function",
"z": "9e82b6f8.933568",
"name": "Steptime Berechnung",
"func": "var Time = msg.myepoch; // Neu reinkommender Wert\nvar Merker = context.get('Merker')||0; // Zum Wert merken\nvar Steptime = 0; // Ergebnis\n\nSteptime = Number(Time) - Number(Merker);\n\ncontext.set('Merker',Time);\nmsg.payload.Steptime = parseInt(Steptime);\n\n\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1880,
"y": 450,
"wires": [
[
"efba4bd8.e07f18",
"9151d0bc.c6eb4"
]
]
},
{
"id": "a98f220b.11a92",
"type": "function",
"z": "9e82b6f8.933568",
"name": "Nur Bh",
"func": "var BhZeitSummems;// = context.get('BhZeitSummems');\n\n//var Bhschrieb = global.get(msg.payload.Item+\"Getriebe_Betriebsstunden\")\n//var doppelchecker = context.get('doppelchecker',doppelchecker);\n\n\n\n/*\nif(msg.payload.Aktiv == \"True\"){ \n var hms = global.get('W16Bhreaded'); \n //var hms = \"111:22:33\";\n var a = hms.split(':');\n if (a[2] >= 1){\n \n }else{\n a[2] = 30;\n }\n var ReadInMs = (parseInt((+a[0]) * 60 * 60 ) + parseInt((a[1]) * 60) + parseInt(a[2]));\n}\n*/\nvar ReadInMs;\n//if (isNaN(Number(global.get(msg.payload.Item+'Bhreaded')))){\nif (isNaN(Number(global.get('BhZeitSummems')))){\nReadInMs = 0;\n}else{\n//ReadInMs = global.get(msg.payload.Item+'Bhreaded'); \nReadInMs = global.get('BhZeitSummems'); \n}\n\n//Zeitumrechner von Sekunden zum Zeitformat HHMMSS\nString.prototype.toHHMMSS = function () {\n var sec_num = parseInt(this, 10); \n var hours = Math.floor(sec_num / 3600);\n var minutes = Math.floor((sec_num - (hours * 3600)) / 60);\n var seconds = sec_num - (hours * 3600) - (minutes * 60);\n\n if (hours < 10) {hours = \"0\"+hours;}\n if (minutes < 10) {minutes = \"0\"+minutes;}\n if (seconds < 10) {seconds = \"0\"+seconds;}\n return hours+':'+minutes+':'+seconds;\n}\n\n\n\n\nif (msg.payload.ZMessungaktiv == 1)\n {\n //BhZeitSummems = Number(ReadInMs) + Number(msg.payload.Steptime) ; // Warum ist hier der Präfix der Zeitmessungen drin ? Zeitmessknoten nehmen!!!!!????????\n BhZeitSummems = (Number(ReadInMs) + Number(msg.payload.Steptime)); // Warum ist hier der Präfix der Zeitmessungen drin ? Zeitmessknoten nehmen!!!!!????????\n msg.payload.Betriebsstunden = ((BhZeitSummems/1000).toString().toHHMMSS()); //Zeit umgewandelt\n }else{\n BhZeitSummems = Number(ReadInMs); \n }\n\n\n//if(msg.payload.Betriebsstunden == context.get('doppelchecker')){\n// msg.payload.doppelte = msg.payload.doppelte + 1;\n//}\n\n\n//context.set('doppelchecker',msg.payload.Betriebsstunden);\nmsg.payload.BhZeitSummems = BhZeitSummems;\n\n\nmsg.payload.ReadInMs = ReadInMs;\n\n//msg.payload.Bhschrieb = Bhschrieb;\n\nglobal.set('BhZeitSummems',BhZeitSummems);\n//global.set('BhZeitSummems',0);\n\n\n\nmsg.payload.BhZeitSummemsglobalalt = global.get('ReadInMs');\nmsg.payload.BhZeitSummemsglobalgesetzt = global.get('BhZeitSummems');\n//msg.payload.mymillis = msg.mymillis;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 2550,
"y": 450,
"wires": [
[
"a66c1b3c.2b8a4"
]
]
},
{
"id": "1e05b3d8.60ea2c",
"type": "debug",
"z": "9e82b6f8.933568",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 1820,
"y": 420,
"wires": []
},
{
"id": "efba4bd8.e07f18",
"type": "change",
"z": "9e82b6f8.933568",
"name": "",
"rules": [
{
"t": "set",
"p": "payload.Steptime",
"pt": "msg",
"to": "payload.Steptime",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 2230,
"y": 450,
"wires": [
[
"a98f220b.11a92",
"878712d5.17249"
]
]
},
{
"id": "a66c1b3c.2b8a4",
"type": "debug",
"z": "9e82b6f8.933568",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 2720,
"y": 450,
"wires": []
},
{
"id": "9151d0bc.c6eb4",
"type": "debug",
"z": "9e82b6f8.933568",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 2150,
"y": 420,
"wires": []
},
{
"id": "878712d5.17249",
"type": "debug",
"z": "9e82b6f8.933568",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 2540,
"y": 420,
"wires": []
}
]
Overview:
Greetings
Chorum