I am using snmp at the moment. Now I want to output the runtime of the server via snmp per oid. This succeeds me also. But the format is in "timeticks" as output.
How can I convert this to dd:hh:mm:ss?
I have tried it with a function, this does not work so well because it displays the hours in total hours.
var timeticks = msg.payload[0].value;
var stunden = Math.floor(timeticks / 360000);
var tage = Math.floor(timeticks / 8640000);
var result = ("Tage: " + tage + " | Stunden: " + stunden);
msg.payload[0].value= result;
return msg;
Are these in milliseconds? If so then it should be 3600000. However a better way is something like const datetime = new Date(timeticks)
then you can format it how you like using the Date functions.
Please give us some clues about what that is showing. They appear to be all coming from the same debug node. We need to see the data going in to the function and the data coming out.
Also please just show us that data not the whole screen. It is almost impossible to see what you are posting. If fact if you hover over the value in the debug pane then some buttons will popup. Click on the Copy button and paste that here, for the data going in and the data coming out. See this canned text for how to do that:
There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.
Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
So, this is not a timestanp but rather an uptime from when the snmp device had started (ticking), right?
Look into Moment.js ...it has a duration and diff function.
Where: endTime = now() and startTime = endTime - your-snmp-ticks.
Then: duration = moment.duration(endTime.diff(startTime))
..currently on the road, so can't test it myself, but this is what it should liik like.
Assuming that the 87133392 shown in the panel above as a value is in Centi seconds (and given that you divide by 100 to get seconds)
const timeticks = msg.payload[0].value
const milliseconds = timeticks * 10 // Or whatever it takes to convert timeticks to milliseconds
const date = new Date(milliseconds)
const days = Math.floor(milliseconds / 86400000)
return `${days}T${date.toLocaleTimeString('de-DE', { timeZone: 'UTC' })}`
gives 1T02:02:13. The return string can be configured however you wish. I use this format because this is the format used by Tasmota. (So to get the same format as your output above use