Search/Regex node to retrieve data from error list

#1

Hi Everyone
I am new to node red and just need some direction, I have allot of instrumentation on allot of trucks and allot of sites. but they do breakdown and it then spits out a 4 digit error code. I want the driver to punch in the error code on their tablet and get the possible causes for the issue before they phone me at 2 am an make me drive
300 KM!!! just to press a print button!!!!!

I managed to have a button on the dashboard that shows the error in a specific file when the specific button is pushed. but I only listed the 8 most common errors and there is allot more.
I just do not know for the life of me how to use a Input Text box that tells a Function or Change node to log in a list and then spit it out onto a Text output tab

Then there is a 3 columns 1st tells the error 2nd gives an explanation and the 3rd is the remedy of how to go about to fix the issue.


this is how it looks like in the manual.
I wan the river to log this error once he/she cannot fix the issue and send a assistance request for a technician and thus have a record of when and where this happened.
I managed to figure out the UI control node which makes the screens less clustered.

Sorry I am just a technician that don't understand programming (reason I chose to do node red) that just want to make life easier.

Kind regards

Paul Euvrard

#2

I guess you made the right choice by selecting node-RED. You clearly stated the problem and already outlined the solution but you did not share your dataset. I will therefore come up with something from my mind. I imagine an object like this one holding your data:

[
    {
        "code": 1111,
        "reason": "Wet sensor, It is raining again",
        "details": "......."
    },
    {
        "code": 2222,
        "reason": "Wet sensor, It Never Rains in Southern California",
        "details": "......."
    }
]

You flow will need a way to store the dataset into the memory (loading from a file or maybe hard coding the data), the input text node, a function node and the output text node. For your use case i would prefer using a function node, for the search/filtering, rather than a change node, just to avoid using a jsonata expression (which I suppose you are not familiar).

So the function node would need to filter your dataset to select the data (reason and details) associated with the 4 digit error code coming from the UI Input Text node.

It could be as simple as:

const pay = msg.payload;

// Load dataset from memory
const dset = global.get("dataset");

// Filter dataset for code
const result = dset.filter(ob => ob.code == pay);

return result

As for the dashboard here is a draft that shows the result of the search for error code 2222

Play with below flow and try to understand it. I would be happy to explain whatever it is not clear for you or help you further on any improvement.

[{"id":"44b4daf0.020054","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"f7c3644d.682df8","type":"ui_text_input","z":"44b4daf0.020054","name":"","label":"","group":"e4aa1bd9.47a7d8","order":0,"width":"8","height":"1","passthru":true,"mode":"text","delay":"0","topic":"","x":180,"y":300,"wires":[["5f005b99.2533c4"]]},{"id":"163cd6a1.1a77f9","type":"debug","z":"44b4daf0.020054","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":510,"y":220,"wires":[]},{"id":"bf393097.0be8a","type":"inject","z":"44b4daf0.020054","name":"Load Dataset","topic":"","payload":"Dataset loaded","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":200,"y":80,"wires":[["e7c5269c.fb2cf8"]]},{"id":"e7c5269c.fb2cf8","type":"change","z":"44b4daf0.020054","name":"","rules":[{"t":"set","p":"dataset","pt":"global","to":"[{\"code\":1111,\"reason\":\"Wet sensor, It is raining again\",\"details\":\"Come on, you little fighter, No need to get up-tighter, Come on, you little fighter, And get back up again\"},{\"code\":2222,\"reason\":\"Wet sensor, It Never Rains in Southern California\",\"details\":\"Seems it never rains in southern California, Seems Ive often heard that kind of talk before, It never rains in California, but girl, dont they warn ya?,It pours, man, it pours\"}]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":80,"wires":[["7a2c18e5.443ec8"]]},{"id":"7a2c18e5.443ec8","type":"debug","z":"44b4daf0.020054","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":80,"wires":[]},{"id":"5f005b99.2533c4","type":"function","z":"44b4daf0.020054","name":"Filter dataset","func":"const pay = msg.payload;\n\n// Load dataset from memory\nconst dset = global.get(\"dataset\");\n\n// Filter dataset for code\nconst result = dset.filter(ob => ob.code == pay);\n\nreturn result;","outputs":1,"noerr":0,"x":370,"y":300,"wires":[["163cd6a1.1a77f9","19c1a6c1.499099","b8c22734.915458","81567218.788cf"]]},{"id":"19c1a6c1.499099","type":"ui_text","z":"44b4daf0.020054","group":"e4aa1bd9.47a7d8","order":0,"width":"8","height":"2","name":"","label":"Code","format":"{{msg.code}}","layout":"row-left","x":530,"y":260,"wires":[]},{"id":"b8c22734.915458","type":"ui_text","z":"44b4daf0.020054","group":"e4aa1bd9.47a7d8","order":0,"width":"8","height":"2","name":"","label":"Reason","format":"{{msg.reason}}","layout":"row-spread","x":540,"y":300,"wires":[]},{"id":"81567218.788cf","type":"ui_text","z":"44b4daf0.020054","group":"e4aa1bd9.47a7d8","order":0,"width":"8","height":"4","name":"","label":"Details","format":"{{msg.details}}","layout":"row-spread","x":530,"y":340,"wires":[]},{"id":"e4aa1bd9.47a7d8","type":"ui_group","z":"","name":"G1","tab":"763667c5.ae1af8","order":1,"disp":true,"width":"8","collapse":false},{"id":"763667c5.ae1af8","type":"ui_tab","z":"","name":"LAB","icon":"dashboard"}]
2 Likes