Read CSV file and Replace the name of a variable

Hi all,

I have thounsands of sensors which has his deveui (identificator) with numbers like 54-23-12-54.... In a csv file I have in the first colum this deveui and in the second the name that I want to put at my sensor. Somebody has an idea or example related on how I can do it. The steps I'm thinking about are read the csv, do something to know if the deveui of the first column exists and change the name if yes, but I don't know how to do this process.

It's the same that change node, but I have a lot of sensors and I don't want to put this charge on node red.

Thank you,
Roger.

If i under stand you could just use array.map() in a function node to check all col1's, and change if needed.
i.e.

[{"id":"5ad7b371.e3aa7c","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"search","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":2000,"wires":[["fa632041.9888a8"]]},{"id":"fa632041.9888a8","type":"template","z":"57675e72.26a0d8","name":"simulate csv","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"dname1,newname1,more\nname1,newname1,more\ndname2,newname2,more\nname2,newname2,more\n","output":"str","x":440,"y":2000,"wires":[["ee3daed8.93c5a8"]]},{"id":"ee3daed8.93c5a8","type":"csv","z":"57675e72.26a0d8","name":"","sep":",","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":210,"y":2060,"wires":[["3465403.2c9b8c"]]},{"id":"3465403.2c9b8c","type":"function","z":"57675e72.26a0d8","name":"","func":"let search =\"dname\";\nmsg.payload = msg.payload.map(v => (v.col1.substr(0,search.length) === search) ? Object.assign(v,{\"col1\":v.col2}) : v);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":2060,"wires":[["25013c10.49587c"]]},{"id":"25013c10.49587c","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":2000,"wires":[]}]

Thank you E1cid, I'm going to try in this way.

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