Buffer-Parser fails by using specification

Hi All,
I've got no answer for this behavior of the buffer-parser:

I've got some bytes pushing through the buffer-parser. As long as I do all the settings within the buffer-parser node itselve, all is like expected. But as soon as I start using the specification it does not give me the exponent. It gives me zero and not -1 or -2 like expected. I built an example flow for demonstration:

[{"id":"77035d12c456286b","type":"tab","label":"Flow 7","disabled":false,"info":"","env":[]},{"id":"d04905d94adb39d0","type":"debug","z":"77035d12c456286b","name":"debug 318","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":160,"wires":[]},{"id":"08e9bee652ad3412","type":"inject","z":"77035d12c456286b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[65024,5008,65280,2283]","payloadType":"json","x":230,"y":160,"wires":[["84b9ee52e5cdcf3f","d64e7654502d18a2"]]},{"id":"84b9ee52e5cdcf3f","type":"function","z":"77035d12c456286b","name":"dynamically set spec","func":"msg.spec = {\n    \"options\":\n    {\n        \"byteSwap\":false,\n        \"resultType\": \"keyvalue\",\n        \"setTopic\": true,\n        \"multipleResult\": false\n    },\n    \"items\":[\n        \n        {\n        \"name\": \"F\",\n        \"type\": \"uint32be\",\n        \"offset\": 0,\n        \"mask\": 0x00FFFFF\n        },\n        {\n        \"name\": \"F2\",\n        \"type\": \"int8\",\n        \"offset\": 0\n        },\n        {\n        \"name\": \"Ua\",\n        \"type\": \"uint32be\",\n        \"offset\": 4,\n        \"mask\": \"0x00fffff\"\n        },\n        {\n        \"name\": \"Ua_exp\",\n        \"type\": \"int8\",\n        \"offset\": 4\n        }\n    ]\n}\n\nreturn msg;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":120,"wires":[["01aa41b430f4a104"]]},{"id":"01aa41b430f4a104","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"msg","items":[{"type":"uint32be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"item2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":120,"wires":[["d04905d94adb39d0"]]},{"id":"d64e7654502d18a2","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32be","name":"F","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"F2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32be","name":"Ua","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"Ua_exp","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":610,"y":180,"wires":[["d04905d94adb39d0"]]}]

Can you see the difference between the settings inside the buffer-parser and the variation with specification?

Thank you very much!

BR
Chris

I havent looked closely but there is a handy trick: if you set the debug to output full msg, the buffer parser outputs the specification it used internally which you can capture from a working flow and re-use it as a template.

Here, I copied the specification from the statically set buffer-parser and re-used that as a dynamic spec in 3rd working flow.

[{"id":"08e9bee652ad3412","type":"inject","z":"77035d12c456286b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[65024,5008,65280,2283]","payloadType":"json","x":210,"y":120,"wires":[["84b9ee52e5cdcf3f"]]},{"id":"84b9ee52e5cdcf3f","type":"function","z":"77035d12c456286b","name":"dynamically set spec","func":"msg.spec = {\n    \"options\":\n    {\n        \"byteSwap\":false,\n        \"resultType\": \"keyvalue\",\n        \"setTopic\": true,\n        \"multipleResult\": false\n    },\n    \"items\":[        \n        {\n        \"name\": \"F\",\n        \"type\": \"uint32be\",\n        \"offset\": 0,\n        \"mask\": 0x00FFFFF\n        },\n        {\n        \"name\": \"F2\",\n        \"type\": \"int8\",\n        \"offset\": 0\n        },\n        {\n        \"name\": \"Ua\",\n        \"type\": \"uint32be\",\n        \"offset\": 4,\n        \"mask\": \"0x00fffff\"\n        },\n        {\n        \"name\": \"Ua_exp\",\n        \"type\": \"int8\",\n        \"offset\": 4\n        }\n    ]\n}\n\nreturn msg;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":120,"wires":[["01aa41b430f4a104"]]},{"id":"01aa41b430f4a104","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"msg","items":[{"type":"uint32be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"item2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":120,"wires":[["b3ab3f3e3b7fc006"]]},{"id":"d64e7654502d18a2","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32be","name":"F","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"F2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32be","name":"Ua","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"Ua_exp","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":160,"wires":[["2c3ee34c8e1d75f5","cdb202969869478f"]]},{"id":"de7c280899e6d34f","type":"inject","z":"77035d12c456286b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[65024,5008,65280,2283]","payloadType":"json","x":210,"y":160,"wires":[["d64e7654502d18a2"]]},{"id":"b3ab3f3e3b7fc006","type":"debug","z":"77035d12c456286b","name":"incorrect","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":120,"wires":[]},{"id":"2c3ee34c8e1d75f5","type":"debug","z":"77035d12c456286b","name":"reference","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":160,"wires":[]},{"id":"427512e02bfd1a10","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"msg","items":[{"type":"uint32be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"item2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":242,"wires":[["d207f73ff47c4da9"]]},{"id":"2f2af8b986e0ca79","type":"function","z":"77035d12c456286b","name":"dynamically set spec","func":"msg.spec = {\n    \"options\": {\n        \"byteSwap\": [],\n        \"resultType\": \"keyvalue\",\n        \"singleResult\": true,\n        \"msgProperty\": \"payload\",\n        \"setTopic\": true\n    },\n    \"items\": [\n        {\n            \"type\": \"uint32be\",\n            \"name\": \"F\",\n            \"offset\": 0,\n            \"length\": 1,\n            \"scale\": \"1\",\n            \"mask\": \"0x00fffff\"\n        },\n        {\n            \"type\": \"int8\",\n            \"name\": \"F2\",\n            \"offset\": 0,\n            \"length\": 1,\n            \"scale\": \"1\",\n            \"mask\": \"\"\n        },\n        {\n            \"type\": \"uint32be\",\n            \"name\": \"Ua\",\n            \"offset\": 4,\n            \"length\": 1,\n            \"scale\": \"1\",\n            \"mask\": \"0x00fffff\"\n        },\n        {\n            \"type\": \"int8\",\n            \"name\": \"Ua_exp\",\n            \"offset\": 4,\n            \"length\": 1,\n            \"scale\": \"1\",\n            \"mask\": \"\"\n        }\n    ]\n}\nreturn msg;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":242,"wires":[["427512e02bfd1a10"]]},{"id":"d207f73ff47c4da9","type":"debug","z":"77035d12c456286b","name":"working","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":242,"wires":[]},{"id":"7040afd1d9a16ada","type":"inject","z":"77035d12c456286b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[65024,5008,65280,2283]","payloadType":"json","x":210,"y":242,"wires":[["2f2af8b986e0ca79"]]},{"id":"cdb202969869478f","type":"debug","z":"77035d12c456286b","name":"specification from static config","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"specification","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":200,"wires":[]}]
2 Likes

Hi Steve-Mcl,
thank's a lot!!
That's a great trick. The problem seems, that it want's to have also a mask "" for the items without mask.

You made my day. It took me 3 hours without success but now I can continue :wink:

BR
Chris

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.