Help with a function node

ok, understood. In such case it is very simple.

Just use this code inside your function node (replacing everything else that is there):

let good = msg.payload.trim();
msg.payload = good;
return msg;

perfect thanks @Andrei

HI @Andrei

I have been playing with this flow a lot lately and managed to insert a timestamp into the log file which was needed, but the one thing I cant seem to get correct, is to change the msg.topic that gets to your LogLine function to be the name that is associated cardUID when it check the cardUID to return a true or false.

The idea would be that if the change: 3 rules returns a true for cardUID, that it then reads the Name of line in the csv or object where it matched and inserts that as the msg.topic so that when the log file lines are created I can see who successfully presented a card.

Hope you done mind helping with this as I have tried all sorts of methods, but cant get it correct.

Thanks

sure, I will check and reply you back. Question: Do you want keep authenticating also by username ? This is in place in the code but not sure if it is of any use for your case. perhaps it is better to authenticate only based on cardID ?

@ Andrei - I need to only authenticate/check on the cardUID. Great suggestion.

If the cardUID exists, i need some way of recovering the Name field associated with the cardUID.

Thanks

Hi @RackIoT,

It took me a while to refactor the code. This use case was great for me to practice using jsonata. It is amazing how fast we can forget something when not using it for ... 1 or 2 days (yep, I hope one day science will find a cure for Anterograde Amnesia).

Here is the code , I hope it works..

[{"id":"c8c1ca3b.e4d8c8","type":"tab","label":"Dexter List","disabled":false,"info":""},{"id":"b3b4a21c.2f6c9","type":"inject","z":"c8c1ca3b.e4d8c8","name":"Trigger Flow","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":160,"wires":[["45f7c805.f01608"]]},{"id":"45f7c805.f01608","type":"file in","z":"c8c1ca3b.e4d8c8","name":"Read CSV","filename":"C:\\Users\\OCM\\.node-red\\static\\nrfiles\\dexter.csv","format":"utf8","chunk":false,"sendError":false,"x":310,"y":160,"wires":[["a97ac176.6e676"]]},{"id":"a97ac176.6e676","type":"csv","z":"c8c1ca3b.e4d8c8","name":"","sep":",","hdrin":true,"hdrout":false,"multi":"mult","ret":"\\n","temp":"","skip":"0","x":450,"y":160,"wires":[["3b798098.1b92f"]]},{"id":"b7c75a79.0c2a28","type":"debug","z":"c8c1ca3b.e4d8c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":710,"y":260,"wires":[]},{"id":"3b798098.1b92f","type":"change","z":"c8c1ca3b.e4d8c8","name":"","rules":[{"t":"set","p":"csv","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":160,"wires":[[]]},{"id":"61923d0.76ef2c4","type":"inject","z":"c8c1ca3b.e4d8c8","name":"Valid card","topic":"","payload":"UID007","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":260,"wires":[["5f821927.3bafc8"]]},{"id":"5f821927.3bafc8","type":"change","z":"c8c1ca3b.e4d8c8","name":"","rules":[{"t":"set","p":"csv","pt":"msg","to":"csv","tot":"flow"},{"t":"set","p":"list","pt":"msg","to":"csv{UID : Name}","tot":"jsonata"},{"t":"set","p":"valid","pt":"msg","to":"payload in $keys(list)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":260,"wires":[["94e8cfd6.08269"]]},{"id":"76e40342.b4463c","type":"inject","z":"c8c1ca3b.e4d8c8","name":"Invalid card","topic":"","payload":"UID022","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":320,"wires":[["5f821927.3bafc8"]]},{"id":"94e8cfd6.08269","type":"function","z":"c8c1ca3b.e4d8c8","name":"Logline","func":"let pay = msg.payload;\nif (msg.valid) {\n    msg.payload = `Pass:      ${pay},${msg.list[pay]}`} else {\n    msg.payload = `Violation: ${pay}, Not in the list`    \n    }\n\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":260,"wires":[["b7c75a79.0c2a28"]]},{"id":"47fe33d4.d0d61c","type":"comment","z":"c8c1ca3b.e4d8c8","name":"Dexter file","info":"UID, Name\nUID001,Dexter\nUID002,Dee Dee\nUID003,Mandark\nUID004,Simion\nUID005,Major Glory\nUID006,Val Hallen\nUID007,Dad\nUID008,Mom","x":140,"y":80,"wires":[]}]

Hey,

This is a very interesting flow which I might be able to use for my project. Does anyone know how to scan a new rfid user in the csv file and use the touch panel to enter the name?

Hi @RackIoT
I am interested the wiegand decoder node. I would like to use the wiegand decoder. Could you please advice me?