The best way to implement device database

Hi JayDikson, thanks a lot for your assistance!!!
Sorry for not understanding.
I follow the steps that you said me. But I think that my problem precedes the object formation, at the moment of definition payload on the function that i call "JSON Parameters persistance"

payload={"uniqueIdentifier":I3EAdd, "prop1":ModelID,"prop2":nwkaddr,"prop3":ep1};
 msg.payload=payload;
 return msg;

As you see my object was created, but all the properties values are empty.
image

Please, can you advise me how to solve it?

Best Regards,
Alex

Alex, at this point it would be a good idea for you to supply your flow with a test case that shows the issue. Then others could look over exactly what you have done.

Those don't look empty to me... That payload is a great starting point to work with.
The data from I3Add is landing in your msg.payload.uniqueIdentifier, the data from nwkaddr is in your msg.payload.prop3, and so on. You should re-label those fields with something meaningful to you (and expand on them as needed.)

Zenofmud, as you requested me, could you can see bellow my flow:

Important information: My payload, sent to another node, is formed at line 153 else if (msg.payload[1]==129, in the node JSON Parameters Persistence.

[{"id":"a43b8354.0564b","type":"function","z":"cdca0da2.0cafe8","name":"JSON Parameters Persistence","func":"/**************************************************************************************************\n  Filename:       JSON Parameters Persistence  - Storaging Parameters - Node-Red\n  Revised:        $Date: 2019-20-01 (Sun, 20 Jan 2019) $\n  Revision:       $Revision: 01 $\n  Description:    Zigbee Network Management - Device Announcement - Zigbee Gatehay AZH0001.\n  Write Nwk_short Addr, Nwk_IEEE Addr, EP and ZCL Device Model Attribute\n  Copyright 2018-2019 AZ Tecnologia e inovação Incorporated. All rights reserved.\n**************************************************************************************************/\n/* tratamento das respostas aos comandos do gateway*/\n\n/* Debug mode para explorar o NWK Short Address*/\nlet debug = 0;\n\nfor (i= 0; i < msg.payload.length; i++) {\n    \n        if(msg.payload[1]==2) {\n        \n            switch (msg.payload[2]){\n            \n            /* Analyze xxx */\n\n                case 77:{\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length ==1){\n        \n                        } else if (msg.sliced.length ==4){\n\n                            \n                        } else if(msg.add.length >=3){\n                            \n                            \n                        } else{\n                            msg.payload=\"Nwk_EndPoint_ERROR: Ne \";\n                        }\n                \n                }\n                break;\n                case 72:{ //new\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length ==1){\n                         \n                        } else if (msg.sliced.length ==4){\n                           \n                            \n                        } else if(msg.add.length >=3){\n                            \n                            \n                        } else{\n                            msg.payload=\"Nwk_EndPoint_ERROR: Ne \";\n                        }\n                \n                }\n                break;\n            }\n            break;\n                      \n   \n        }else if (msg.payload[1]==128) {\n                      switch (msg.payload[2]){\n            \n            /* Analyze xxx */\n\n                case 70:{\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length ==1){\n                            let nwkaddrs1 = global.get('NWKAdS1');\n                            let nwkaddrs2 = global.get('NWKAdS2');\n                            let nwkaddr1 = global.get('NWKAd1');\n                            let nwkaddr2 = global.get('NWKAd2');\n                            let ep1s = global.get('EP1s');\n                            let I3E1=global.get('IEEE1');\n\t\t\t\t\t\t\tlet I3E2=global.get('IEEE2');\n\t\t\t\t\t\t\tlet I3E3=global.get('IEEE3');\n\t\t\t\t\t\t\tlet I3E4=global.get('IEEE4');\n\t\t\t\t\t\t\tlet I3E5=global.get('IEEE5');\n\t\t\t\t\t\t\tlet I3E6=global.get('IEEE6');\n\t\t\t\t\t\t\tlet I3E7=global.get('IEEE7');\n\t\t\t\t\t\t\tlet I3E8=global.get('IEEE8');\n\t\t\t\t\t\t\tlet I3Eb1=global.get('IEEEb1');\n\t\t\t\t\t\t\tlet I3Eb2=global.get('IEEEb2');\n\t\t\t\t\t\t\tlet I3Eb3=global.get('IEEEb3');\n\t\t\t\t\t\t\tlet I3Eb4=global.get('IEEEb4');\n\t\t\t\t\t\t\tlet I3Eb5=global.get('IEEEb5');\n\t\t\t\t\t\t\tlet I3Eb6=global.get('IEEEb6');\n\t\t\t\t\t\t\tlet I3Eb7=global.get('IEEEb7');\n\t\t\t\t\t\t\tlet I3Eb8=global.get('IEEEb8');\n\t\t\t\t\t\t\tlet I3EAdd = +I3E1+I3E2+I3E3+I3E4+I3E5+I3E6+I3E7+I3E8\n\t\t\t\t\t\t\tlet I3EAdds = +I3Eb1+I3Eb2+I3Eb3+I3Eb4+I3Eb5+I3Eb6+I3Eb7+I3Eb8;\n\t\t\t\t\t\t\tlet nwkEP1 = msg.add;\n\t\t\t\t\t\t\n                            msg.payload=\"Nwk_IEEEAddrS  \" +I3EAdds;\n                            return msg;\n                        } else if (msg.sliced.length ==4){\n                            let nwkaddrs1 = global.get('NWKAdS1');\n                            let nwkaddrs2 = global.get('NWKAdS2');\n                            let ep1s = global.get('EP1s');\n                            let ep2s = global.get('EP2s');\n                            let I3E1=global.get('IEEE1');\n\t\t\t\t\t\t\tlet I3E2=global.get('IEEE2');\n\t\t\t\t\t\t\tlet I3E3=global.get('IEEE3');\n\t\t\t\t\t\t\tlet I3E4=global.get('IEEE4');\n\t\t\t\t\t\t\tlet I3E5=global.get('IEEE5');\n\t\t\t\t\t\t\tlet I3E6=global.get('IEEE6');\n\t\t\t\t\t\t\tlet I3E7=global.get('IEEE7');\n\t\t\t\t\t\t\tlet I3E8=global.get('IEEE8');\n\t\t\t\t\t\t    let I3Eb1=global.get('IEEEb1');\n\t\t\t\t\t\t\tlet I3Eb2=global.get('IEEEb2');\n\t\t\t\t\t\t\tlet I3Eb3=global.get('IEEEb3');\n\t\t\t\t\t\t\tlet I3Eb4=global.get('IEEEb4');\n\t\t\t\t\t\t\tlet I3Eb5=global.get('IEEEb5');\n\t\t\t\t\t\t\tlet I3Eb6=global.get('IEEEb6');\n\t\t\t\t\t\t\tlet I3Eb7=global.get('IEEEb7');\n\t\t\t\t\t\t\tlet I3Eb8=global.get('IEEEb8');\n\t\t\t\t\t\t\tlet I3EAdd = +I3E1+I3E2+I3E3+I3E4+I3E5+I3E6+I3E7+I3E8\n\t\t\t\t\t\t\tlet I3EAdds = +I3Eb1+I3Eb2+I3Eb3+I3Eb4+I3Eb5+I3Eb6+I3Eb7+I3Eb8;\n                            let nwkEP1 = msg.add;\n                            msg.payload=\"Nwk_IEEEAddrS  \" +I3EAdds;\n                            return msg;\n                            \n                        } else if(msg.add.length >=3){\n                            \n                            \n                        } else{\n                            msg.payload=\"Get Nwk_EndPoint_ERROR: Ne \";\n                        }\n                \n                }\n                break;\n                case 80:{ //new\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length ==1){\n                         \n                        } else if (msg.sliced.length ==4){\n                           \n                            \n                        } else if(msg.add.length >=3){\n                            \n                            \n                        } else{\n                            msg.payload=\"Get Nwk_EndPoint_ERROR: Ne \";\n                        }\n                \n                }\n                break;\n            }\n            break;\n                      \n        \n        }else if (msg.payload[1]==129){\n            \n            switch (msg.payload[2]){\n                 case 2:{\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length >=1){\n                            let nwkaddrs1 = global.get('NWKAdS1');\n                            let nwkaddrs2 = global.get('NWKAdS2');\n                            let nwkaddr1 = global.get('NWKAd1');\n                            let nwkaddr2 = global.get('NWKAd2');\n                            let ep1s = global.get('EP1s');\n                            let ep2s = global.get('EP2s');\n                            let ep1 = global.get('EP1');\n                            let ep2 = global.get('EP2');\n                            let I3E1=global.get('IEEE1');\n\t\t\t\t\t\t\tlet I3E2=global.get('IEEE2');\n\t\t\t\t\t\t\tlet I3E3=global.get('IEEE3');\n\t\t\t\t\t\t\tlet I3E4=global.get('IEEE4');\n\t\t\t\t\t\t\tlet I3E5=global.get('IEEE5');\n\t\t\t\t\t\t\tlet I3E6=global.get('IEEE6');\n\t\t\t\t\t\t\tlet I3E7=global.get('IEEE7');\n\t\t\t\t\t\t\tlet I3E8=global.get('IEEE8');\n\t\t\t\t\t\t\tlet I3EAdd = +I3E1+I3E2+I3E3+I3E4+I3E5+I3E6+I3E7+I3E8;\n\t\t\t\t\t\t\tlet I3Eb1=global.get('IEEEb1');\n\t\t\t\t\t\t\tlet I3Eb2=global.get('IEEEb2');\n\t\t\t\t\t\t\tlet I3Eb3=global.get('IEEEb3');\n\t\t\t\t\t\t\tlet I3Eb4=global.get('IEEEb4');\n\t\t\t\t\t\t\tlet I3Eb5=global.get('IEEEb5');\n\t\t\t\t\t\t\tlet I3Eb6=global.get('IEEEb6');\n\t\t\t\t\t\t\tlet I3Eb7=global.get('IEEEb7');\n\t\t\t\t\t\t\tlet I3Eb8=global.get('IEEEb8');\n\t\t\t\t\t\t\tlet I3EAdds = +I3Eb1+I3Eb2+I3Eb3+I3Eb4+I3Eb5+I3Eb6+I3Eb7+I3Eb8;\n                            let ModelID = msg.sliced;\n                            let nwkaddr = global.get('NWKAddr');\n                            global.set('ZCLModelID',ModelID);\n                            \tif (debug==1){\n                                                let data={\"ModelID\":ModelID,\"IEEEAdd\":I3EAdd,\"NetworkAdd\":nwkaddr1+nwkaddr2,\"EP1\":ep1,\"IEEEAddS\":I3EAdds,\"NetworkAdd1S\":nwkaddrs1,\"NetworkAdd2S\":nwkaddrs2,\"EP1S\":ep1s};\n                                                node.log(typeof data);\n                                                msg.payload=JSON.stringify(data);\n                                                return msg;\n\t\t\t\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\t\t\t\t\t\t\t\t\t    payload={\"uniqueIdentifier\":I3EAdd, \"prop1\":ModelID,\"prop2\":nwkaddr,\"prop3\":ep1};\n                                                msg.payload=payload;\n                                                //msg.filename='home/pi/HomeGateway/nwkFilestorage.txt'\n                                                return msg;\n                         \n\t\t\t\t\t\t\t\t\t\t\t}\n                            \n                            \n                        \n                        } else{\n                            msg.payload=\"ERROR: Network elements \";\n                        }\n                \n                }\n                break;\n            }\n            break;\n            \n            \n            \n        \n        } else {\n            \n            \n        }\n    \n    \n }\n\n   \n                 \n                 \n                 \n                 \n    \n    \n    \n","outputs":1,"noerr":0,"x":1030,"y":150,"wires":[["e1e7ec7d.230b18","7db593a5.a8ba64"]]}]

@JayDickson, the first debug msg you see completely, with all those parameters, is not a msg that passed through the node Change: 4 rules, but yes the 1st payload that I was created in the node JSON Parameters Persistence.

Best regards,
Alex

@aargollo what you provided is a single function node not what I asked for

supply your flow with a test case that shows the issue .

Sorry guys for my mistake. I didn´t know I needed to select all nodes
@zenofmud and @JayDickson can see bellow my complete flow code!
Note: I had problem to reproduce all those nodes because characters limitation. So just plug the previous one posted on this one!

image

Thanks a lot Alex!

[{"id":"94d623d0.d3459","type":"tab","label":"Flow 8","disabled":false,"info":""},{"id":"a52cd726.640b98","type":"debug","z":"94d623d0.d3459","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","x":1550,"y":270,"wires":[]},{"id":"7114bcee.1b2334","type":"function","z":"94d623d0.d3459","name":"","func":"var unique = String(msg.payload.name);\nvar prop1 = msg.payload.prop1;\nvar prop2 = msg.payload.prop2;\nvar prop3 = msg.payload.prop3;\n\n\nvar properties = {\n \"prop1\":prop1, \n \"prop2\":prop2, \n \"prop3\":prop3,\n};\n\nnode.send({\n \"uniqueIdentifier\":unique,\n \"properties\":properties});\nflow.set(unique,\n {\"uniqueIdentifier\":unique,\n \"properties\":properties});","outputs":1,"noerr":0,"x":1340,"y":240,"wires":[["a52cd726.640b98"]]},{"id":"67ab6367.bf19ec","type":"change","z":"94d623d0.d3459","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.name","tot":"msg"},{"t":"set","p":"payload.prop1","pt":"msg","to":"property1","tot":"str"},{"t":"set","p":"payload.prop2","pt":"msg","to":"prop2","tot":"str"},{"t":"set","p":"payload.prop3","pt":"msg","to":"property 3","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1370,"y":150,"wires":[["7114bcee.1b2334"]]},{"id":"79f872df.1553ac","type":"function","z":"94d623d0.d3459","name":"JSON Parameters Persistence","func":"/**************************************************************************************************\n  Filename:       JSON Parameters Persistence  - Storaging Parameters - Node-Red\n  Revised:        $Date: 2019-20-01 (Sun, 20 Jan 2019) $\n  Revision:       $Revision: 01 $\n  Description:    Zigbee Network Management - Device Announcement - Zigbee Gatehay AZH0001.\n  Write Nwk_short Addr, Nwk_IEEE Addr, EP and ZCL Device Model Attribute\n  Copyright 2018-2019 AZ Tecnologia e inovação Incorporated. All rights reserved.\n**************************************************************************************************/\n/* tratamento das respostas aos comandos do gateway*/\n\n/* Debug mode para explorar o NWK Short Address*/\nlet debug = 0;\n\nfor (i= 0; i < msg.payload.length; i++) {\n    \n        if(msg.payload[1]==2) {\n        \n            switch (msg.payload[2]){\n            \n            /* Analyze xxx */\n\n                case 77:{\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length ==1){\n        \n                        } else if (msg.sliced.length ==4){\n\n                            \n                        } else if(msg.add.length >=3){\n                            \n                            \n                        } else{\n                            msg.payload=\"Nwk_EndPoint_ERROR: Ne \";\n                        }\n                \n                }\n                break;\n                case 72:{ //new\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length ==1){\n                         \n                        } else if (msg.sliced.length ==4){\n                           \n                            \n                        } else if(msg.add.length >=3){\n                            \n                            \n                        } else{\n                            msg.payload=\"Nwk_EndPoint_ERROR: Ne \";\n                        }\n                \n                }\n                break;\n            }\n            break;\n                      \n   \n        }else if (msg.payload[1]==128) {\n                      switch (msg.payload[2]){\n            \n            /* Analyze xxx */\n\n                case 70:{\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length ==1){\n                            let nwkaddrs1 = global.get('NWKAdS1');\n                            let nwkaddrs2 = global.get('NWKAdS2');\n                            let nwkaddr1 = global.get('NWKAd1');\n                            let nwkaddr2 = global.get('NWKAd2');\n                            let ep1s = global.get('EP1s');\n                            let I3E1=global.get('IEEE1');\n\t\t\t\t\t\t\tlet I3E2=global.get('IEEE2');\n\t\t\t\t\t\t\tlet I3E3=global.get('IEEE3');\n\t\t\t\t\t\t\tlet I3E4=global.get('IEEE4');\n\t\t\t\t\t\t\tlet I3E5=global.get('IEEE5');\n\t\t\t\t\t\t\tlet I3E6=global.get('IEEE6');\n\t\t\t\t\t\t\tlet I3E7=global.get('IEEE7');\n\t\t\t\t\t\t\tlet I3E8=global.get('IEEE8');\n\t\t\t\t\t\t\tlet I3Eb1=global.get('IEEEb1');\n\t\t\t\t\t\t\tlet I3Eb2=global.get('IEEEb2');\n\t\t\t\t\t\t\tlet I3Eb3=global.get('IEEEb3');\n\t\t\t\t\t\t\tlet I3Eb4=global.get('IEEEb4');\n\t\t\t\t\t\t\tlet I3Eb5=global.get('IEEEb5');\n\t\t\t\t\t\t\tlet I3Eb6=global.get('IEEEb6');\n\t\t\t\t\t\t\tlet I3Eb7=global.get('IEEEb7');\n\t\t\t\t\t\t\tlet I3Eb8=global.get('IEEEb8');\n\t\t\t\t\t\t\tlet I3EAdd = +I3E1+I3E2+I3E3+I3E4+I3E5+I3E6+I3E7+I3E8\n\t\t\t\t\t\t\tlet I3EAdds = +I3Eb1+I3Eb2+I3Eb3+I3Eb4+I3Eb5+I3Eb6+I3Eb7+I3Eb8;\n\t\t\t\t\t\t\tlet nwkEP1 = msg.add;\n\t\t\t\t\t\t\n                            msg.payload=\"Nwk_IEEEAddrS  \" +I3EAdds;\n                            return msg;\n                        } else if (msg.sliced.length ==4){\n                            let nwkaddrs1 = global.get('NWKAdS1');\n                            let nwkaddrs2 = global.get('NWKAdS2');\n                            let ep1s = global.get('EP1s');\n                            let ep2s = global.get('EP2s');\n                            let I3E1=global.get('IEEE1');\n\t\t\t\t\t\t\tlet I3E2=global.get('IEEE2');\n\t\t\t\t\t\t\tlet I3E3=global.get('IEEE3');\n\t\t\t\t\t\t\tlet I3E4=global.get('IEEE4');\n\t\t\t\t\t\t\tlet I3E5=global.get('IEEE5');\n\t\t\t\t\t\t\tlet I3E6=global.get('IEEE6');\n\t\t\t\t\t\t\tlet I3E7=global.get('IEEE7');\n\t\t\t\t\t\t\tlet I3E8=global.get('IEEE8');\n\t\t\t\t\t\t    let I3Eb1=global.get('IEEEb1');\n\t\t\t\t\t\t\tlet I3Eb2=global.get('IEEEb2');\n\t\t\t\t\t\t\tlet I3Eb3=global.get('IEEEb3');\n\t\t\t\t\t\t\tlet I3Eb4=global.get('IEEEb4');\n\t\t\t\t\t\t\tlet I3Eb5=global.get('IEEEb5');\n\t\t\t\t\t\t\tlet I3Eb6=global.get('IEEEb6');\n\t\t\t\t\t\t\tlet I3Eb7=global.get('IEEEb7');\n\t\t\t\t\t\t\tlet I3Eb8=global.get('IEEEb8');\n\t\t\t\t\t\t\tlet I3EAdd = +I3E1+I3E2+I3E3+I3E4+I3E5+I3E6+I3E7+I3E8\n\t\t\t\t\t\t\tlet I3EAdds = +I3Eb1+I3Eb2+I3Eb3+I3Eb4+I3Eb5+I3Eb6+I3Eb7+I3Eb8;\n                            let nwkEP1 = msg.add;\n                            msg.payload=\"Nwk_IEEEAddrS  \" +I3EAdds;\n                            return msg;\n                            \n                        } else if(msg.add.length >=3){\n                            \n                            \n                        } else{\n                            msg.payload=\"Get Nwk_EndPoint_ERROR: Ne \";\n                        }\n                \n                }\n                break;\n                case 80:{ //new\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length ==1){\n                         \n                        } else if (msg.sliced.length ==4){\n                           \n                            \n                        } else if(msg.add.length >=3){\n                            \n                            \n                        } else{\n                            msg.payload=\"Get Nwk_EndPoint_ERROR: Ne \";\n                        }\n                \n                }\n                break;\n            }\n            break;\n                      \n        \n        }else if (msg.payload[1]==129){\n            \n            switch (msg.payload[2]){\n                 case 2:{\n  \n                        /* Análise do xxxx */\n                        if (msg.sliced.length >=1){\n                            let nwkaddrs1 = global.get('NWKAdS1');\n                            let nwkaddrs2 = global.get('NWKAdS2');\n                            let nwkaddr1 = global.get('NWKAd1');\n                            let nwkaddr2 = global.get('NWKAd2');\n                            let ep1s = global.get('EP1s');\n                            let ep2s = global.get('EP2s');\n                            let ep1 = global.get('EP1');\n                            let ep2 = global.get('EP2');\n                            let I3E1=global.get('IEEE1');\n\t\t\t\t\t\t\tlet I3E2=global.get('IEEE2');\n\t\t\t\t\t\t\tlet I3E3=global.get('IEEE3');\n\t\t\t\t\t\t\tlet I3E4=global.get('IEEE4');\n\t\t\t\t\t\t\tlet I3E5=global.get('IEEE5');\n\t\t\t\t\t\t\tlet I3E6=global.get('IEEE6');\n\t\t\t\t\t\t\tlet I3E7=global.get('IEEE7');\n\t\t\t\t\t\t\tlet I3E8=global.get('IEEE8');\n\t\t\t\t\t\t\tlet I3EAdd = +I3E1+I3E2+I3E3+I3E4+I3E5+I3E6+I3E7+I3E8;\n\t\t\t\t\t\t\tlet I3Eb1=global.get('IEEEb1');\n\t\t\t\t\t\t\tlet I3Eb2=global.get('IEEEb2');\n\t\t\t\t\t\t\tlet I3Eb3=global.get('IEEEb3');\n\t\t\t\t\t\t\tlet I3Eb4=global.get('IEEEb4');\n\t\t\t\t\t\t\tlet I3Eb5=global.get('IEEEb5');\n\t\t\t\t\t\t\tlet I3Eb6=global.get('IEEEb6');\n\t\t\t\t\t\t\tlet I3Eb7=global.get('IEEEb7');\n\t\t\t\t\t\t\tlet I3Eb8=global.get('IEEEb8');\n\t\t\t\t\t\t\tlet I3EAdds = +I3Eb1+I3Eb2+I3Eb3+I3Eb4+I3Eb5+I3Eb6+I3Eb7+I3Eb8;\n                            let ModelID = msg.sliced;\n                            let nwkaddr = global.get('NWKAddr');\n                            global.set('ZCLModelID',ModelID);\n                            \tif (debug==1){\n                                                let data={\"ModelID\":ModelID,\"IEEEAdd\":I3EAdd,\"NetworkAdd\":nwkaddr1+nwkaddr2,\"EP1\":ep1,\"IEEEAddS\":I3EAdds,\"NetworkAdd1S\":nwkaddrs1,\"NetworkAdd2S\":nwkaddrs2,\"EP1S\":ep1s};\n                                                node.log(typeof data);\n                                                msg.payload=JSON.stringify(data);\n                                                return msg;\n\t\t\t\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\t\t\t\t\t\t\t\t\t    payload={\"uniqueIdentifier\":I3EAdd, \"prop1\":ModelID,\"prop2\":nwkaddr,\"prop3\":ep1};\n                                                msg.payload=payload;\n                                                //msg.filename='home/pi/HomeGateway/nwkFilestorage.txt'\n                                                return msg;\n                         \n\t\t\t\t\t\t\t\t\t\t\t}\n                            \n                            \n                        \n                        } else{\n                            msg.payload=\"ERROR: Network elements \";\n                        }\n                \n                }\n                break;\n            }\n            break;\n            \n            \n            \n        \n        } else {\n            \n            \n        }\n    \n    \n }\n\n   \n                 \n                 \n                 \n                 \n    \n    \n    \n","outputs":1,"noerr":0,"x":1030,"y":150,"wires":[["67ab6367.bf19ec"]]}]

For a naming convention of these things, I’ve started using this. I’m not sure if you’d find it useful in your store:

I've been using this approach, below, for managing the attributes of my various sensors from within a function block. It has associated nodes to read from and write to disk. Each device definition can be converted to MQTT topics. I have a variety of devices including old X-10s and xbee radios.

Whenever I create a new device, I update this list (in a function block) and push the write-to-disk node. Then when node-red restarts, it reads from that disk file.

var devices = {
payload : [
    {
      "building": "home",
      "room": "bedroom",
      "device": "light",
      "tech": "X10",
      "id": "M5",
      "type": "actuator",
      "adc": "",
      "feed": "",
      "desc": "x10 device and lamp"
    },
    {
      "building": "home",
      "room": "stairwell",
      "device": "light",
      "tech": "LIFX",
      "id": "lifx1",
      "type": "actuator",
      "adc": "",
      "feed": "",
      "desc": "Wifi LED light bulb"
    },
    {
      "building": "home",
      "room": "livingroom",
      "device": "shelf-light",
      "tech": "LIFX",
      "id": "lifx2",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "Wifi LED light bulb"
    },
    {
      "building": "home",
      "room": "livingroom",
      "device": "cieling-light",
      "tech": "LIFX",
      "id": "lifx3",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "Wifi LED light bulb"
    },
    {
      "building": "home",
      "room": "office",
      "device": "light",
      "tech": "X10",
      "id": "M8",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "x10 device and lamp"
    },
    {
      "building": "home",
      "room": "guestroom",
      "device": "light",
      "tech": "X10",
      "id": "M7",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "x10 device and lamp"
    },
    {
      "building": "home",
      "room": "livingroom",
      "device": "light",
      "tech": "X10",
      "id": "M1",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "x10 device and lamp"
    },
    {
      "building": "home",
      "room": "kitchen",
      "device": "light",
      "tech": "X10",
      "id": "C4",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "x10 device and lamp"
    },
    {
      "building": "home",
      "room": "garage",
      "device": "light",
      "tech": "wemo",
      "id": "we4",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "wemo wifi switch and lamp"
    },
    {
      "building": "home",
      "room": "garage",
      "device": "relay",
      "tech": "ESP",
      "id": "E43",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "Wemos ESP device and 120VAC relay"
    },
    {
      "building": "home",
      "room": "kitchen",
      "device": "switch",
      "tech": "HZ",
      "id": "H1",
      "adc": "",
      "feed": "",
      "type": "sensor",
      "desc": "Capacitive switch on ESP Huzzah"
    },
    {
      "building": "home",
      "room": "backporch",
      "device": "tl-ms-0",
      "tech": "XB",
      "id": "2",
      "adc": "0,1,4,R",
      "feed": "",
      "adjust": "1,1,1,1",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },
    {
      "building": "home",
      "room": "kitchen",
      "device": "tl-ms-1",
      "tech": "XB",
      "id": "13",
      "adc": "0,1,2,3,R",
      "feed": "",
      "adjust": "1,1,1,1",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },
        {
      "building": "home",
      "room": "garage",
      "device": "tl-ms-1",
      "tech": "XB",
      "id": "29",
      "adc": "0,1,2,3,R",
      "feed": "",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },
        {
      "building": "home",
      "room": "bedroom",
      "device": "tl-ms-1",
      "tech": "XB",
      "id": "12",
      "adc": "0,1,2,3,R",
      "feed": "",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },
        {
      "building": "home",
      "room": "bathroom",
      "device": "tl-ms-1",
      "tech": "XB",
      "id": "15",
      "adc": "0,1,2,3,R",
      "feed": "",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },
        {
      "building": "home",
      "room": "office",
      "device": "tl-ms-1",
      "tech": "XB",
      "id": "23",
      "adc": "0,1,2,3,R",
      "feed": "",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },        
        {
      "building": "home",
      "room": "guestroom",
      "device": "tl-ms-1",
      "tech": "XB",
      "id": "9",
      "adc": "0,1,2,3,R",
      "feed": "25133",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },        
        {
      "building": "home",
      "room": "bedroom",
      "device": "tl-ms-1",
      "tech": "XB",
      "id": "8",
      "adc": "0,1,2,3,R",
      "feed": "25131",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },        
        {
      "building": "home",
      "room": "office",
      "device": "tl-ms-1",
      "tech": "XB",
      "id": "7",
      "adc": "0,1,2,3,R",
      "feed": "24660",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },
        {
      "building": "home",
      "room": "dining",
      "device": "tl-gas",
      "tech": "XB",
      "id": "5",
      "adc": "0,1,2,3,R",
      "feed": "10267",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },
        {
      "building": "home",
      "room": "diningroom",
      "device": "light",
      "tech": "X10",
      "id": "M14",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "x10 wall switch"
    },
        {
      "building": "home",
      "room": "porch",
      "device": "tl-temp",
      "tech": "XB",
      "id": "2",
      "adc": "0,1,R",
      "feed": "9709",
      "type": "sensor",
      "desc": "xbee based sensor board"
    },
        {
      "building": "home",
      "room": "laundry",
      "device": "switch",
      "tech": "ESP",
      "id": "E42",
      "adc": "",
      "feed": "",
      "type": "actuator",
      "desc": "Wemos ESP device and 120VAC relay"
    }
  ]
};

// set a global context to retrieve later
global.set("devices",devices.payload)

var s = JSON.stringify(devices.payload);
msg.payload=s;
return msg;

Hi Christl, thanks a lot for sharing your code w/ me!
I have a importante doubt before to construct the objects, I have structure my code as I mentioned before in 3 parts.

1st - the function necessary to form a new payload with the network parameters and get those parameter with global functions (JSON Parameters persistence).

}else if (msg.payload[1]==129){
            
            switch (msg.payload[2]){
                 case 2:{
  
                        /* Análise do xxxx */
                        if (msg.sliced.length >=1){
                            let nwkaddrs1 = global.get('NWKAdS1');
                            let nwkaddrs2 = global.get('NWKAdS2');
                            let nwkaddr1 = global.get('NWKAd1');
                            let nwkaddr2 = global.get('NWKAd2');
                            let ep1s = global.get('EP1s');
                            let ep2s = global.get('EP2s');
                            let ep1 = global.get('EP1');
                            let ep2 = global.get('EP2');
                            let I3E1=global.get('IEEE1');
							let I3E2=global.get('IEEE2');
							let I3E3=global.get('IEEE3');
							let I3E4=global.get('IEEE4');
							let I3E5=global.get('IEEE5');
							let I3E6=global.get('IEEE6');
							let I3E7=global.get('IEEE7');
							let I3E8=global.get('IEEE8');
							let I3EAdd =I3E1+I3E2+I3E3+I3E4+I3E5+I3E6+I3E7+I3E8;
							let I3Eb1=global.get('IEEEb1');
							let I3Eb2=global.get('IEEEb2');
							let I3Eb3=global.get('IEEEb3');
							let I3Eb4=global.get('IEEEb4');
							let I3Eb5=global.get('IEEEb5');
							let I3Eb6=global.get('IEEEb6');
							let I3Eb7=global.get('IEEEb7');
							let I3Eb8=global.get('IEEEb8');
							let I3EAdds = +I3Eb1+I3Eb2+I3Eb3+I3Eb4+I3Eb5+I3Eb6+I3Eb7+I3Eb8;
                            let ModelID = msg.sliced;
                            let nwkaddr = global.get('NWKAddr');
                            global.set('ZCLModelID',ModelID);
                            	if (debug==1){
                                                let data={"ModelID":ModelID,"IEEEAdd":I3EAdd,"NetworkAdd":nwkaddr1+nwkaddr2,"EP1":ep1,"IEEEAddS":I3EAdds,"NetworkAdd1S":nwkaddrs1,"NetworkAdd2S":nwkaddrs2,"EP1S":ep1s};
                                                node.log(typeof data);
                                                msg.payload=JSON.stringify(data);
                                                return msg;
											}else{
											    
											    payload={"uniqueIdentifier":I3EAdd, "prop1":ModelID,"prop2":nwkaddr,"prop3":ep1};
                                                msg.payload=payload;
                                                //msg.filename='home/pi/HomeGateway/nwkFilestorage.txt'
                                                return msg;
                         
											}
                            
                            
                        
                        } else{
                            msg.payload="ERROR: to create the Network elements ";
                        }

2st - The Change node to handling payload
image

3 rd - The Function to create a object.

var unique = String(msg.payload.name);
var prop1 = msg.payload.prop1;
var prop2 = msg.payload.prop2;
var prop3 = msg.payload.prop3;


var properties = {
 "prop1":prop1, 
 "prop2":prop2, 
 "prop3":prop3,
};

node.send({
 "uniqueIdentifier":unique,
 "properties":properties});
flow.set(unique,
 {"uniqueIdentifier":unique,
 "properties":properties});

The challenge is to store devices cyclically, independent of the labels, I got network parameter serially form protocol messages. For example the unique ID is IEEE addr, got from Zigbee protocol, I think that this parameter can used to make difference between each device attached and than we have a multiple devices each one with our unique ID.
I Think that my object need to have only a few attributes, like that:

var devices = {
payload : [
    {
      "uniqueIdentifier": I3EAdd,
      "Model": ModelID,
      "NwkAdd": :nwkaddr1+nwkaddr2,
      "tech": "Zigee",
      "EP": ep1,
      "desc": "Zigbee device actuator"
    },

  ]
};

I think that each device attached have the same attributes above. This way we would have an array of the objects, each identifiable by the Uniqueidentifier (IEEEaddr).
I cant understanding how to do to obtain this mechanism (form an array of object). Do you can help me?

Guys, I got to working well using file persistence, all those new device my code store in the file serially appended on end the file. I formatting my persistence with the code bellow:

˜˜˜
var devices = {
payload : [
{"Device": ModelID,
"IEEEAddr": I3EAdd,
"NwkAddr": nwkaddr1+nwkaddr2,
"EP1": ep1,
"EP2": ep2,
"IEEEAddrS":I3EAdds,
"NwkAddrs1":nwkaddrs1,
"NwkAddrs2":nwkaddrs2,
"EP1s": ep1s,
"EP2s": ep2s,
"desc": "Zigbee device actuator, lamps and secrurity things"}
]
};

                                                                // set a global context to retrieve later
                                                                global.set("devices",devices.payload)
                                                                msg.payload=JSON.stringify(devices.payload);
                                                                return msg;

˜˜˜
My nwk file that have all those device information have:
˜˜˜
[{"Device":"ZBHT-2","IEEEAddr":"0137a0000009a99","NwkAddr":"b75e","EP1":"0a","IEEEAddrS":"10137a1010109a99","NwkAddrs1":"b7","NwkAddrs2":"5e","EP1s":"1a","desc":"Zigbee device actuator, lamps and secrurity things"}]
˜˜˜
I really can know how to create the same structure using objects to persist in memory as JayDikson and Zenofmud advise me. Guys please can we help me?

Hi @zenofmud and @JayDickson, please would you advise or share more literature w/ me how about I can working with object (context variable) in memory sequentially. you can help me?

I have in my mind to storage multiples device objects, like device1, device2 and devicen, and those devices attributes in memory.

I got success to do it persist in the file, as @christl advise me. I share my device object here to showing all those objects:

{
    "Device": "ZBALRM",
    "IEEEAddr": "0137a000001d94d",
    "NwkAddr": "b39e",
    "EP1": "01",
    "IEEEAddrS": "10137a101011d94d",
    "NwkAddrs1": "b3",
    "NwkAddrs2": "9e",
    "EP1s": "11",
    "desc": "Zigbee device actuators, lamps or secrurity things"
}

{
    "Device": "ZBHT-2",
    "IEEEAddr": "0137a0000009a99",
    "NwkAddr": "b75e",
    "EP1": "0a",
    "IEEEAddrS": "10137a1010109a99",
    "NwkAddrs1": "b7",
    "NwkAddrs2": "5e",
    "EP1s": "1a",
    "desc": "Zigbee device actuators, lamps or secrurity things"
}
{
    "Device": "RWL020",
    "IEEEAddr": "0178801021a83e8",
    "NwkAddr": "3340",
    "EP1": "01",
    "EP2": "02",
    "IEEEAddrS": "10178811121a83e8",
    "NwkAddrs1": "33",
    "NwkAddrs2": "40",
    "EP1s": "11",
    "EP2s": "12",
    "desc": "Zigbee device actuators, lamps or secrurity things"
}

Thanks a lot guys!
Best Regards,
Alex

What kind of work are you wanting to do with them?

Hi JayDickson,
I have building a file persistence and I think that, mainly after you and Paul wrote me, the best way is to persist it in the memory, I did it on the file.
My code will check, during attaching process, if the device exist my code will not write it in the memory otherwise store it.

I believe that I need to have an memory array like that:
[device1, device2, devicen]

Each device above have those attribute {Device, IEEEAddr, NwkAddr and etc.}
Please, How can i do it?

arrgollo,
Seems you want to automatically add your devices to your persistence file (looks like json) whenever you introduce a new xbee radio. If that's it, I would suggest that you do a lookup for each packet you receive and determine if it exists. Use the IEEEAddr as the unique key. If it does not exist, add it to your file.

My reference here is how you store the particulars of your xbee devices; not the data that they create.

Reading the first message again, you asked about database to store data. Here I describe an overview of my system. Maybe it will help you.

I use an xbee radio on raspberry pi #1 (raspi-xb) and I use a python program to collect the data, bundle it up, and send each sensor's data to a node-red instance running on raspberry pi #2 (raspi-co).

Raspi-co does all of the control and redirection functions. It takes all my sensor data and converts it into MQTT (if it isn't already). Then various streams use the subscription feature of MQTT protocol (publish/subscribe) to direct data as needed.

One of the things the Raspi-co does is send a data stream to raspberry pi #3 (raspi-gr) in which I've installed Graphite/Grafana for charting; to see data trends. Graphite is the component that stores the data (3 parts: graphite web, carbon, whisper). Graphite web has very simple charting, carbon collects the data, whisper is a Round Robin database. Because graphite has such limited charts, I use grafana for pretty charts.

I don't do this right now, but if I wanted to send the data to a mysql database, influx, elasticsearch, etc., I would redirect it as needed from an MQTT subscription from within node-red.

A couple of other ideas:

  • Learn MQTT protocol - it works great within the node-red environment. Whatever your device, convert it to MQTT asap in the stream flow.
  • For each sensor (could be multiples on xbees) collect the data as {topic, value, timestamp}. Topic is more or less equivalent to your device specs.
  • Keep it simple.

some links:

1 Like

Hi Christl thanks a lot, all those informations is very valuable for me!
Would do you give a last help?
Do you have an example or node structure that i can use to find IEEEaddr (Json field) on the file?

note: this is my last step to finish my attaching procedure module!

I did a search on google: JavaScript find a record in json

The first reference provides an excellent example:

This looks interesting also:

Think of google search as your friend. I've been programming for years from dbase II, foxpro, C#, python, javascript, java, C++ (Arduino), bash, batch, etc. I use google often whenever I switch over to remember how to create arrays, for loops, try/catch, and other syntax constructs.

Have fun,
Chris.

Hi @christl I working on Json file to handling parameters as we have discuss before and I have problem to working on it. As you can see bellow:

Note: My node-red version is 0.19.4:

I already setup my globalcontext definitions on "settings.js"

As you can see i got the error "ReferenceError: require is not defined (line 1, col 1)"

I including here my flow that i did tests w/ Json file.

[{"id":"ec8958c7.a48858","type":"debug","z":"5f466627.7ec798","name":"","active":true,"tosidebar":true,"console":false,"complete":"true","x":740,"y":90,"wires":[]},{"id":"112615f9.b2867a","type":"function","z":"5f466627.7ec798","name":"Read folder, output file paths","func":"fs = require('fs')\nfs.readFile('/home/pi/HomeGateway/nwkFilestorage.json', 'utf8', function (err,data) {\n  if (err) {\n    return;\n  }\n  node.send({payload: data});\n});","outputs":1,"noerr":0,"x":510,"y":90,"wires":[["ec8958c7.a48858"]]},{"id":"9e678241.e64f2","type":"inject","z":"5f466627.7ec798","name":"Inject Payload JSON","topic":"","payload":"{\"Device\":\"ModelID\",\"IEEEAddr\":\"I3EAdd\",\"NwkAddr\":\"nwkaddr1\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":"","x":240,"y":90,"wires":[["112615f9.b2867a"]]}]
~~~
Would you can help to understanding how to fix it?

See if this helps...

To build the devices list, push the inject button after making changes in the function node:

[{"id":"c464440e.e08de8","type":"file","z":"d787cced.f8449","name":"save to devices.json","filename":"/home/pi/.node-red/devices.json","appendNewline":true,"createDir":true,"overwriteFile":"true","x":859,"y":575,"wires":[]},{"id":"e0e2941d.7ff928","type":"function","z":"d787cced.f8449","name":"devices table layout","func":"\nvar devices = {\npayload : [\n    {\n      \"building\": \"home\",\n      \"room\": \"bedroom\",\n      \"device\": \"light\",\n      \"tech\": \"X10\",\n      \"id\": \"M5\",\n      \"type\": \"actuator\",\n      \"adc\": \"\",\n      \"feed\": \"\",\n      \"desc\": \"x10 device and lamp\"\n    },\n    {\n      \"building\": \"home\",\n      \"room\": \"stairwell\",\n      \"device\": \"light\",\n      \"tech\": \"LIFX\",\n      \"id\": \"lifx1\",\n      \"type\": \"actuator\",\n      \"adc\": \"\",\n      \"feed\": \"\",\n      \"desc\": \"Wifi LED light bulb\"\n    }\n  ]\n};\n\n// set a global context to retrieve later\nglobal.set(\"devices\",devices.payload)\n\nvar s = JSON.stringify(devices.payload);\nmsg.payload=s;\nreturn msg;\n\n","outputs":1,"noerr":0,"x":413.5,"y":566.2499961853027,"wires":[["c464440e.e08de8","bb2d64d0.3dd398"]]},{"id":"3c331e32.2f8592","type":"inject","z":"d787cced.f8449","name":"set devices","topic":"file","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":189,"y":575,"wires":[["e0e2941d.7ff928"]]},{"id":"bb2d64d0.3dd398","type":"debug","z":"d787cced.f8449","name":"","active":false,"console":"false","complete":"true","x":609,"y":595,"wires":[]},{"id":"e2179eca.31378","type":"comment","z":"d787cced.f8449","name":"Set/Save device info","info":"These flows allow you to set up all the devices.  Edit the inventory of rooms and devices and save it.\n","x":149,"y":515,"wires":[]}]

To get the devices list via http call. I use this to provide devices list for my rocketchat bot:

[{"id":"f7522cfd.2fca9","type":"http in","z":"d787cced.f8449","name":"","url":"/devicelist","method":"get","swaggerDoc":"","x":196,"y":685,"wires":[["3e8da927.e83156"]]},{"id":"3e8da927.e83156","type":"file in","z":"d787cced.f8449","name":"","filename":"/home/pi/.node-red/devices.json","format":"utf8","x":466,"y":685,"wires":[["785ea473.d56f0c","7f75cb6d.d4ded4"]]},{"id":"7f75cb6d.d4ded4","type":"http response","z":"d787cced.f8449","name":"","x":706,"y":685,"wires":[]},{"id":"785ea473.d56f0c","type":"debug","z":"d787cced.f8449","name":"","active":false,"console":"false","complete":"payload","x":833,"y":701.9999961853027,"wires":[]},{"id":"fb2e51f8.0f4c8","type":"comment","z":"d787cced.f8449","name":"html GET device info","info":"These are web service calls which return meta-data about devices.","x":153,"y":651,"wires":[]}]

Hi Christl, thanks a lot. Right now I´m working on your examples!

Best Regards,
Alex