# Scan code automatization

**URL:** <https://discourse.nodered.org/t/scan-code-automatization/26936>\
**Category:** General\
**Created:** [19 May 2020 15:52 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936 "2020-05-19T15:52:39Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 May 2020 17:21 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/21 "2020-05-20T17:21:06Z")

</div>

Export your flow and paste it in a reply (don't forget backticks)

---

<div class="post-metadata">

**Author:** ![belo0196](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@belo0196](https://discourse.nodered.org/u/belo0196)\
**Post date:** [20 May 2020 17:26 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/22 "2020-05-20T17:26:51Z")

</div>

```auto
[{"id":"5a7ef36c.a575bc","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"cf7f4827.e63978","type":"e-mail in","z":"5a7ef36c.a575bc","name":"","protocol":"IMAP","server":"imap.gmail.com","useSSL":true,"port":"993","box":"INBOX","disposition":"Read","criteria":"ALL","repeat":"6","fetch":"auto","inputs":0,"x":410,"y":500,"wires":[["91b2e64c.c25da8"]]},{"id":"941feb52.2af968","type":"function","z":"5a7ef36c.a575bc","name":"","func":"\nif(msg.payload.x === msg.payload.y){\n msg.payload=\"RIGHT\";\n}else{\n msg.payload=\"WRONG\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":970,"y":380,"wires":[["b34b3483.4402c8"]]},{"id":"91b2e64c.c25da8","type":"join","z":"5a7ef36c.a575bc","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":420,"wires":[["85823265.ba4ab","941feb52.2af968"]]},{"id":"85823265.ba4ab","type":"debug","z":"5a7ef36c.a575bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1030,"y":600,"wires":[]},{"id":"2ba4d3ea.56f3fc","type":"inject","z":"5a7ef36c.a575bc","name":"","topic":"x","payload":"10987654321","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":480,"y":340,"wires":[["91b2e64c.c25da8"]]},{"id":"b34b3483.4402c8","type":"debug","z":"5a7ef36c.a575bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1190,"y":440,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![belo0196](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@belo0196](https://discourse.nodered.org/u/belo0196)\
**Post date:** [20 May 2020 17:50 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/23 "2020-05-20T17:50:24Z")

</div>

![8](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93535afa7e447faf90f451b6932628077d4dc5af.png)

 ![9](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd7d2bb4fe004b5042d94c72c35ec94eb73c3443.png)  
if i use a normal input string it works

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 May 2020 17:52 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/24 "2020-05-20T17:52:23Z")

</div>

In situations where you are unsure what is going on, it always helps to fake the data.

As i dont have your Emails - i am faking the data here...

 ![yDyvTAEjov](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bdad0eb8d3e370f3406bcc01e83f527406af0cb4.gif)

Here is the flow...

```auto
[{"id":"ee6feeca.2b3ae","type":"function","z":"75a7c9c2.729228","name":"","func":"\nif(msg.payload.x === msg.payload.y){\n msg.payload=\"RIGHT\";\n}else{\n msg.payload=\"WRONG\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":280,"wires":[["c458cb3b.3e6348"]]},{"id":"2420dc69.f2f964","type":"join","z":"75a7c9c2.729228","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":510,"y":280,"wires":[["5bd0f723.e37058","ee6feeca.2b3ae"]]},{"id":"5bd0f723.e37058","type":"debug","z":"75a7c9c2.729228","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":690,"y":340,"wires":[]},{"id":"2094efc.f0ab61","type":"inject","z":"75a7c9c2.729228","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"x","payload":"123456789","payloadType":"str","x":310,"y":180,"wires":[["2420dc69.f2f964"]]},{"id":"c458cb3b.3e6348","type":"debug","z":"75a7c9c2.729228","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":280,"wires":[]},{"id":"269f3a72.035b96","type":"inject","z":"75a7c9c2.729228","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"y","payload":"123456789","payloadType":"str","x":310,"y":340,"wires":[["2420dc69.f2f964"]]},{"id":"24cc5e8e.7c8962","type":"inject","z":"75a7c9c2.729228","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"y","payload":"987654321","payloadType":"str","x":310,"y":380,"wires":[["2420dc69.f2f964"]]},{"id":"fe06ad3e.d0a15","type":"inject","z":"75a7c9c2.729228","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"x","payload":"987654321","payloadType":"str","x":310,"y":220,"wires":[["2420dc69.f2f964"]]}]

```

---

<div class="post-metadata">

**Author:** ![belo0196](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@belo0196](https://discourse.nodered.org/u/belo0196)\
**Post date:** [20 May 2020 18:08 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/25 "2020-05-20T18:08:14Z")

</div>

![10](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a84559e7643b9e46ee84670733efe5499a38a26.png) ![11](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f45c57908c899df81ce0a14e19a2b2e483c95f5b.png)  
i try to store the email data into a file .log and then compare that file to the input but it says to me WRONG how can i resolve that?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 May 2020 18:11 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/26 "2020-05-20T18:11:33Z")

</div>

> [@belo0196](#):
>
> can i resolve that?

A single line string will NEVER equal multi-line string

What do you expect to happen?

Are you looking for msg.payload.x inside? on one line? in a loop?

Please explain your logic

---

<div class="post-metadata">

**Author:** ![belo0196](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@belo0196](https://discourse.nodered.org/u/belo0196)\
**Post date:** [20 May 2020 18:21 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/27 "2020-05-20T18:21:18Z")

</div>

i know that one single line string isn't equal multi-line string, i want to know if it's possible to look inside the file .log and see if the input msg.payload.x(10987654321) is inside. then if it's inside "RIGHT" else "WRONG".

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 May 2020 18:27 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/28 "2020-05-20T18:27:01Z")

</div>

> [@belo0196](#):
>
> i want to know if it's possible to look inside the file

But you didnt say that.

You said

> [@belo0196](#):
>
> compare that file to the input but it says to me WRONG

Also, your terminology is incorrect, node-red doesnt "look inside" a file - you load the file and scan its content.

you could use the JS string [includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) function

```auto
if(msg.payload.y.includes(msg.payload.x)){
//found it
} else {
//not found
}

```

* * *

NOTE: If you are want to be proficient in node-red then you really should do some JavaScript training Nothing too heavy - something online - or YouTube JavaScript for beginners.

---

<div class="post-metadata">

**Author:** ![belo0196](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@belo0196](https://discourse.nodered.org/u/belo0196)\
**Post date:** [21 May 2020 10:23 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/29 "2020-05-21T10:23:03Z")

</div>

![12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fb62cc171a40d1d09201dda573397f245c93f360.png) ![13](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c6aa12577f0048c1b5efaf45e9338d39c794de8d.png)  
now my flow look like this. if the msg.payload.y contains msg.payload.y then light the led 1 else light the led 2, how can i insert a button that reset the if in short word switch off the led?

---

<div class="post-metadata">

**Author:** ![RNCTX](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@RNCTX](https://discourse.nodered.org/u/RNCTX)\
**Post date:** [25 May 2020 01:31 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/30 "2020-05-25T01:31:15Z")

</div>

I don't see the reasoning behind a manual comparison function when a switch node does the same thing.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 May 2020 08:02 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/31 "2020-05-25T08:02:26Z")

</div>

Your question doesn't make a lot of sense. do you want to turn off the opposite pin?

If so, then instead of `return [msg,null]`, `return [msg,{payload:false}]`

That will send a false value to the 2nd output of the function to turn off the opposite pin.

Do the reverse for the 2nd `return`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 July 2020 08:02 UTC](https://discourse.nodered.org/t/scan-code-automatization/26936/32 "2020-07-24T08:02:27Z")

</div>

Closed on 24 July 2020 08:02 UTC

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

[Previous page](https://discourse.nodered.org/t/scan-code-automatization/26936.md?page=1)
