node-red-utc-help-demo.json (3.8 KB)
Convert using function
utc hex to time in this format
2023-3-19 14:20:14
I am able to convert the code
after that in the defined format I am unable to do
[
{
"id": "f8a89ada4bd4d49b",
"type": "inject",
"z": "478d88efdb005c1e",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"msg\":\"dAck\",\"mac\":\"BC572900A05B\",\"rslt\":\"succ\",\"seq\":7716,\"cause\":0,\"rmn\":1,\"dType\":\"hex\",\"data\":\"0200F502000000F0632422491E8A31686324226D1F0D3139632422B020952D7C632422E020C22A6E63242452204B28F46324277020B7292363242EBE2045287563243D341FCC2907632442C61F4A28BD63244DE11ECC287A63245A1C1E4C2851632460591DCB2830632483931D4C26D663248A401CC92626632490351C4925A2632497291BCA25A96324A2981B4A25B96324B2311ACB259A6324D86C1A4B25BE6324E1D319CB25806324EFC8194C25826324F82219B327736324FD9C1A3627A0632501CE1ABA27D26325097A1B33277463250D611BB727CD632510561C412822632512D21CB42858632515C11D34288F63251A961CCB271A\",\"gmac\":\"94A408B0482C\"}",
"payloadType": "json",
"x": 170,
"y": 100,
"wires": [
[
"d6488bee8efe8fdc",
"55a47454709a309f"
]
]
},
{
"id": "d6488bee8efe8fdc",
"type": "function",
"z": "478d88efdb005c1e",
"name": "function 24",
"func": " \n var newMsg = {};\n \n \n \n\nvar data_time = msg.payload.data.substr(16, 8) ;\nvar Temp = Number(hexTo8p8(msg.payload.data.substr(16+8, 4)));\nvar Humidity = Number(hexTo8p8(msg.payload.data.substr(16 + 8+4, 4)));\nvar data = msg.payload.data.substr(16, 8);\n\n for(var i=1;i<=30;i++)\n {\n data_time = msg.payload.data.substr(16 * i, 8 );\n Temp = Number(hexTo8p8(msg.payload.data.substr(24 * i, 4 )));\n Humidity = Number(hexTo8p8(msg.payload.data.substr(28 * i, 4 )));\n data = msg.payload.data.substr(16 * i, 8 );\n \n var checktime = 1546337502;\n\n if(checktime>data_time)\n {\n\n }\n\n \n newMsg.payload = [{\n \n time: data_time,\n utc: Buffer.from(data_time, 'hex').toString(),\n \n temp: Temp,\n humidity: Humidity,\n \n },\n {\n\n history: 1 \n \n\n\n\n }];\n node.send(newMsg);\n\n \n } \n\n\n \n \n \n \n \n \n\n\nreturn null;\n\nfunction calculateDistance(rssi) {\n let P = -69; // @TODO This value should come from MQTT message\n let n = 3;\n let d = Math.pow(10, ((P - rssi) / (10 * n))); //(n ranges from 2 to 4)\n return d * 2;\n}\n\n\nfunction hexTo8p8(/** @type {string} */ value) {\n let intValue = parseInt(value, 16);\n let signed = (intValue & 0x8000) > 0 ? -1/10 : 1;\n return signed * intValue / Math.pow(2, 8);\n}\n\n\n\nfunction int2float( /** @type {string} */value_int) {\n // Create new Buffer based on array bytes\n const buf = Buffer.from(value_int);\n // swap the words\n const temp0 = buf[0];\n const temp1 = buf[1];\n buf[0] = buf[2];\n buf[1] = buf[3];\n buf[2] = temp0;\n buf[3] = temp1;\n\n // Represent these bytes as 32-bit unsigned int\n const value = buf.readInt32BE();\n\n // save the value\n msg.payload = value;\n\n return msg;\n}\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 410,
"y": 160,
"wires": [
[
"caf2f9fe83302084"
]
]
},
{
"id": "caf2f9fe83302084",
"type": "debug",
"z": "478d88efdb005c1e",
"name": "debug 336",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 610,
"y": 180,
"wires": []
}
]