# Trigger a message payload based on input from parallel port

**URL:** <https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017>\
**Category:** Dashboard\
**Created:** [9 June 2019 23:30 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017 "2019-06-09T23:30:13Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 June 2019 08:57 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/21 "2019-06-11T08:57:10Z")

</div>

Put a debug node showing what is going into the function node and another showing what is coming out. Configer the second on to `show complete msg`. Make a screenshot showing the input and output messages.

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [11 June 2019 09:00 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/22 "2019-06-11T09:00:47Z")

</div>

I will do tomorrow as soon as I will get back here at work. Now I need to gather all my stuff and punch out.  
. For now I want to thank you @Colin and @Steve-Mcl for all the help..

Have a wonderful Day/Night

---

<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:** [11 June 2019 14:20 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/23 "2019-06-11T14:20:09Z")

</div>

> [@krikkit](#):
>
> Unfortunately all the message goes through the function unfiltered.  
> I really have no clues why.

you wont be catching anything on your switch

as @Colin said, put a debug before and after the function node. Inspect what goes in & compare that to the `case`'s you have created.

I remember earlier in this thread you said there were newlines in the string. Did you look at removing all whitespace like i suggested?

try this...

```auto

/* 
strip whitespace etc. 
e.g. turn this...
  " tr

  ch

  @123 "

into this...

  "trch@123" 

... then you will have a better chance of matching.
*/

//the code...

//replace everything that isnt a~Z 0~9 @ with nothingness
let alphaNumeric = msg.payload.replace(/[^a-z0-9@+]+/gi, ''); 
//use switch to populate msg.output based on content of alphaNumeric
switch (alphaNumeric) {
  case "@1T@1XR@1Y10":
  msg.output = "1";
  break;
  case "@1T@1XR@1Y236":
  msg.output = "2";
  break;
  default:
  node.error(`UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.output`, msg);
  return null;//halt flow of msg - dont trigger output of this node
}
return msg;//return msg so next node is triggered

```

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [12 June 2019 05:50 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/24 "2019-06-12T05:50:47Z")

</div>

Ok before I was using socat and sed for the spaces, but I like msg.payload.replace.

I did try this function but the source stays the same no matter what.  
Also the debug node does not give me any error.

I am trying to inject the payload with the inject node (it is quicker) but still the payload goes through unchanged.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 June 2019 07:36 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/25 "2019-06-12T07:36:18Z")

</div>

> [@krikkit](#):
>
> but still the payload goes through unchanged.

The payload will always go through unchanged, because you have no code to change msg.payload. You are setting msg.output. That is why I suggested setting the debug node to show the complete message, then you would see if msg.output is being set.

---

<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:** [12 June 2019 07:47 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/26 "2019-06-12T07:47:44Z")

</div>

Hmmm. I suspect with the lack of screen shots or exported `flow`, we are misunderstanding each other.

**Try this...**

1. Add debug node before and after the function node
  1. SET the DEBUG nodes to output **'complete msg'**

2. Replace the function node code with below.
3. In the debug window, expand the resulting msg `object`s
4. Take Screenshots and post here.
  1. Include the debug window
  2. Include an image showing (at minimum) the region of interest of your flow

**Why..**  
We need to see all properties of the `msg` so we can see why it gets past the `case` statements. So in the debug window we should see what is in `msg.alphaNumeric`.  
I would bet my left nut and several packet of my favorite crisps that the value in `msg.alphaNumeric` IS NOT a match to any of the `case` entries you have.

```auto
//remove all non alphanumeric (and the @) from the input 
//NOTE: store it in msg object so we can inspect it in the debug window
msg.alphaNumeric = msg.payload.replace(/[^a-z0-9@+]+/gi, ''); 
//use switch to populate msg.output based on content of alphaNumeric
switch (msg.alphaNumeric) {
  case "@1T@1XR@1Y10":
  msg.output = "1";
  break;
  case "@1T@1XR@1Y236":
  msg.output = "2";
  break;
  default:
  node.error(`UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.output`, msg);
  return null;//halt flow of msg - dont trigger output of this node
}
return msg;//return msg so next node

```

_Lastly, if you want further help, it may be beneficial if you post your flow and sample data. [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)_

---

<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:** [12 June 2019 07:50 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/27 "2019-06-12T07:50:57Z")

</div>

> [@Colin](#):
>
> You are setting msg.output.

Good point.

Actually, I suspect everything is working.

When the OP said he got no error (i.e. the `default` was never reached) I hadn't considered the OP may not be inspecting the right part of the result.

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [12 June 2019 08:52 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/28 "2019-06-12T08:52:29Z")

</div>

you are both right... if I set the debug note to catch debug.output the function works perfectly... so now how can I set the output in the right way?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4d2b23237984dcdb5423ab636af843979148efdf.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 June 2019 09:03 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/29 "2019-06-12T09:03:23Z")

</div>

What do you mean 'the right way'? Do you want to set msg.payload instead of msg.output? If so then just put `msg.payload = ...` instead of `msg.output = ...`

---

<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:** [12 June 2019 10:15 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/30 "2019-06-12T10:15:34Z")

</div>

Also, you still have spaces and newlines in you string.  
Also you did not output complete msg after BEFORE and AFTER function node

We still cannot help you if you wont do what we ask.

> [@Steve-Mcl](#):
>
> 1. Add debug node before and after the function node  
> SET the DEBUG nodes to output **'complete msg'**
> 2. Replace the function node code with below.
> 3. In the debug window, expand the resulting msg `object` s
> 4. Take Screenshots and post here.  
> Include the debug window  
> Include an image showing (at minimum) the region of interest of your flow

---

<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:** [12 June 2019 10:25 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/31 "2019-06-12T10:25:32Z")

</div>

Ah I'm getting impatient in my old age.

I had hoped you would follow our advice and figure it out (learn from trial and error).

Never mind.

**If you had did what I said - this is what youd have...**

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/307d6ec94f974898701bb7c93239234061545294.png)

The code I took the time to write for you works & by looking at pictures you posted (where spaces and newlines can be seen) you didnt bother to use my code or follow the steps I set out. ☹

Here is my flow for reference...

```auto
[{"id":"7569f1ce.da9e1","type":"inject","z":"673afa83.cf1d04","name":"","topic":"","payload":" @1T @1XR @1Y10 ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":786,"y":144,"wires":[["3092f4d3.c8fb0c","be16b96e.74f838"]]},{"id":"3092f4d3.c8fb0c","type":"function","z":"673afa83.cf1d04","name":"convert msg","func":"//remove all non alphanumeric (and the @) from the input \n//NOTE: store it in msg object so we can inspect it in the debug window\nmsg.alphaNumeric = msg.payload.replace(/[^a-z0-9@+]+/gi, ''); \n//use switch to populate msg.output based on content of alphaNumeric\nswitch (msg.alphaNumeric) {\n case \"@1T@1XR@1Y10\":\n msg.output = \"1\";\n break;\n case \"@1T@1XR@1Y236\":\n msg.output = \"2\";\n break;\n default:\n node.error(`UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.output`, msg);\n return null;//halt flow of msg - dont trigger output of this node\n}\nreturn msg;//return msg so next node","outputs":1,"noerr":0,"x":1054,"y":192,"wires":[["b3d26da3.3c93e"]]},{"id":"cd1fb152.bb90a","type":"inject","z":"673afa83.cf1d04","name":"","topic":"","payload":"@1T @1XR @1Y236","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":796,"y":192,"wires":[["3092f4d3.c8fb0c","be16b96e.74f838"]]},{"id":"be16b96e.74f838","type":"debug","z":"673afa83.cf1d04","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1034,"y":240,"wires":[]},{"id":"b3d26da3.3c93e","type":"debug","z":"673afa83.cf1d04","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1202,"y":240,"wires":[]},{"id":"be0cd7b7.c383f8","type":"inject","z":"673afa83.cf1d04","name":"","topic":"","payload":"@wont- work -no @case","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":806,"y":264,"wires":[["3092f4d3.c8fb0c","be16b96e.74f838"]]}]

```

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [12 June 2019 22:58 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/32 "2019-06-12T22:58:00Z")

</div>

I did an oopsie ehehe sorry for that.  
I am going to post the code as soon as I get on the raspberry pi. I am reading the guidelines on how to export the nodes and post them in the appropriate way.

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [12 June 2019 22:58 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/33 "2019-06-12T22:58:25Z")

</div>

Oh no the right way for me is msg.output 🙂

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [12 June 2019 23:27 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/34 "2019-06-12T23:27:14Z")

</div>

This is my flow:

```auto
[{"id":"94f5aaf1.dd7478","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"95ea4fc2.371a2","type":"serial in","z":"94f5aaf1.dd7478","name":"","serial":"14fa8305.476bfd","x":130,"y":140,"wires":[["f6106e64.cbeac","a3d13068.0f127"]]},{"id":"2c887c0c.675924","type":"inject","z":"94f5aaf1.dd7478","name":"","topic":"","payload":"@1T @1XR @1Y236","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":140,"y":340,"wires":[["f6106e64.cbeac","c90a02ea.9cad3"]]},{"id":"f6106e64.cbeac","type":"function","z":"94f5aaf1.dd7478","name":"better filter","func":"let alphaNumeric = msg.payload.replace(/[^a-z0-9@+]+/gi, ''); \n//use switch to populate msg.output based on content of alphaNumeric\nswitch (alphaNumeric) {\n case \"@1T@1XR@1Y10\":\n msg.output = \"1\";\n break;\n case \"@1T@1XR@1Y236\":\n msg.output = \"2\";\n break;\n default:\n node.error(`UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.output`, msg);\n return null;//halt flow of msg - dont trigger output of this node\n}\nreturn msg;//return msg so next node is triggered","outputs":1,"noerr":0,"x":370,"y":300,"wires":[["727922a7.a2d37c"]]},{"id":"a3d13068.0f127","type":"debug","z":"94f5aaf1.dd7478","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":360,"y":80,"wires":[]},{"id":"727922a7.a2d37c","type":"debug","z":"94f5aaf1.dd7478","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"output","targetType":"msg","x":570,"y":200,"wires":[]},{"id":"c90a02ea.9cad3","type":"debug","z":"94f5aaf1.dd7478","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":370,"y":400,"wires":[]},{"id":"746dc34b.166b5c","type":"catch","z":"94f5aaf1.dd7478","name":"Debug","scope":["f6106e64.cbeac"],"uncaught":false,"x":350,"y":260,"wires":[["69a50aa4.e72c24"]]},{"id":"c0124ff9.3a91c","type":"status","z":"94f5aaf1.dd7478","name":"","scope":null,"x":740,"y":220,"wires":[[]]},{"id":"69a50aa4.e72c24","type":"debug","z":"94f5aaf1.dd7478","name":"test","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":590,"y":260,"wires":[]},{"id":"14fa8305.476bfd","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"9","bin":"false","out":"count","addchar":"","responsetimeout":"10000"}]

```

I did try to use the one @Steve-Mcl posted but when I add the node to the arduino I still get the whole payload instead of the object "1" or "2" that I need for the Arduino to light up the specific set of leds

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [12 June 2019 23:45 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/35 "2019-06-12T23:45:26Z")

</div>

Ok I think I got it adding a change function

```auto
[{"id":"714f58a9.946ac8","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"bd4b5a0.20216a8","type":"inject","z":"714f58a9.946ac8","name":"","topic":"","payload":" @1T @1XR @1Y10 ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":160,"wires":[["31311d91.73a682","1a22b267.c69f7e"]]},{"id":"31311d91.73a682","type":"function","z":"714f58a9.946ac8","name":"convert msg","func":"//remove all non alphanumeric (and the @) from the input \n//NOTE: store it in msg object so we can inspect it in the debug window\nmsg.alphaNumeric = msg.payload.replace(/[^a-z0-9@+]+/gi, ''); \n//use switch to populate msg.output based on content of alphaNumeric\nswitch (msg.alphaNumeric) {\n case \"@1T@1XR@1Y10\":\n msg.output = \"1\";\n break;\n case \"@1T@1XR@1Y236\":\n msg.output = \"2\";\n break;\n default:\n node.error(`UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.output`, msg);\n return null;//halt flow of msg - dont trigger output of this node\n}\nreturn msg;//return msg so next node","outputs":1,"noerr":0,"x":478,"y":208,"wires":[["8d77016.235ab","a02dc229.65926"]]},{"id":"1863da45.f47a86","type":"inject","z":"714f58a9.946ac8","name":"","topic":"","payload":"@1T @1XR @1Y236","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":208,"wires":[["31311d91.73a682","1a22b267.c69f7e"]]},{"id":"1a22b267.c69f7e","type":"debug","z":"714f58a9.946ac8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":458,"y":256,"wires":[]},{"id":"8d77016.235ab","type":"debug","z":"714f58a9.946ac8","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":626,"y":256,"wires":[]},{"id":"f3de9fc2.62caf","type":"inject","z":"714f58a9.946ac8","name":"","topic":"","payload":"@wont- work -no @case","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":280,"wires":[["31311d91.73a682","1a22b267.c69f7e"]]},{"id":"3492f4b7.06d0bc","type":"serial out","z":"714f58a9.946ac8","name":"arduino","serial":"59dec7e8.7f4548","x":700,"y":180,"wires":[]},{"id":"10d75f01.a41b01","type":"debug","z":"714f58a9.946ac8","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":700,"y":80,"wires":[]},{"id":"a02dc229.65926","type":"change","z":"714f58a9.946ac8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"output","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":120,"wires":[["10d75f01.a41b01"]]},{"id":"59dec7e8.7f4548","type":"serial-port","z":"","serialport":"/dev/ttyACM0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"500"}]

```

---

<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:** [13 June 2019 07:43 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/36 "2019-06-13T07:43:06Z")

</div>

Change node is unnecessary.

If you read the code in the function you can clearly see `msg.output` is set. Simply change that to `msg.payload` like @Colin said ...

> [@Colin](#):
>
> What do you mean 'the right way'? Do you want to set msg.payload instead of msg.output? If so then just put `msg.payload = ...` instead of `msg.output = ...`

**For example...**

```auto
switch (msg.alphaNumeric) {
  case "@1T@1XR@1Y10":
  msg.payload = "1"; //<<<<<<<< SET msg.payload INSTEAD OF msg.output!!!
  break;
  case "@1T@1XR@1Y236":
  msg.payload = "2"; //<<<<<<<< SET msg.payload INSTEAD OF msg.output!!!
  break;
  default:
  node.error(`UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.output`, msg);
  return null;//halt flow of msg - dont trigger output of this node
}

```

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [17 June 2019 06:28 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/37 "2019-06-17T06:28:00Z")

</div>

Ok so with the changes suggested nothing is working anymore...

```auto
[{"id":"b69086aa.ed1058","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"271f4c3.6eeceb4","type":"inject","z":"b69086aa.ed1058","name":"","topic":"","payload":" @1T @1XR @1Y10 ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":140,"wires":[["10322b90.247df4","4c5c7ece.16a05"]]},{"id":"10322b90.247df4","type":"function","z":"b69086aa.ed1058","name":"convert msg","func":"//remove all non alphanumeric (and the @) from the input \n//NOTE: store it in msg object so we can inspect it in the debug window\nmsg.alphaNumeric = msg.payload.replace(/[^a-z0-9@+]+/gi, ''); \n//use switch to populate msg.output based on content of alphaNumeric\nswitch (msg.alphaNumeric) {\n case \"@1T@1XR@1Y10\":\n msg.payload = \"1\";\n break;\n case \"@1T@1XR@1Y236\":\n msg.payload = \"2\";\n break;\n case \"@1T@1XR@1Y219\":\n msg.payload = \"3\";\n break;\n default:\n node.error(`UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.payload`, msg);\n return null;//halt flow of msg - dont trigger output of this node\n}\nreturn msg;//return msg so next node","outputs":1,"noerr":0,"x":478,"y":208,"wires":[["8a76d1fa.60dd9","b7c00d44.8b1f7","b0a89545.b2f5b8"]]},{"id":"3adf3e51.fef132","type":"inject","z":"b69086aa.ed1058","name":"","topic":"","payload":"@1T @1XR @1Y236","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":200,"wires":[["10322b90.247df4","4c5c7ece.16a05"]]},{"id":"4c5c7ece.16a05","type":"debug","z":"b69086aa.ed1058","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":458,"y":256,"wires":[]},{"id":"8a76d1fa.60dd9","type":"debug","z":"b69086aa.ed1058","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":626,"y":256,"wires":[]},{"id":"986f82bc.f22df","type":"inject","z":"b69086aa.ed1058","name":"","topic":"","payload":"@wont- work -no @case","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":260,"wires":[["10322b90.247df4","4c5c7ece.16a05"]]},{"id":"b0a89545.b2f5b8","type":"serial out","z":"b69086aa.ed1058","name":"arduino","serial":"59dec7e8.7f4548","x":700,"y":180,"wires":[]},{"id":"a549fd1b.78b35","type":"debug","z":"b69086aa.ed1058","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":700,"y":80,"wires":[]},{"id":"b7c00d44.8b1f7","type":"change","z":"b69086aa.ed1058","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"output","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":120,"wires":[["a549fd1b.78b35","b0a89545.b2f5b8"]]},{"id":"69cd710.1e52e9","type":"serial in","z":"b69086aa.ed1058","name":"","serial":"59dec7e8.7f4548","x":140,"y":80,"wires":[["10322b90.247df4","3ade415e.d1f86e"]]},{"id":"3ade415e.d1f86e","type":"debug","z":"b69086aa.ed1058","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":400,"y":60,"wires":[]},{"id":"59dec7e8.7f4548","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"500"}]

```

The error is UNKNOWN value in payload '@1XR'. Cannot generate value for msg.output

I have no Idea what is going on

---

<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:** [17 June 2019 07:41 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/38 "2019-06-17T07:41:44Z")

</div>

> [@krikkit](#):
>
> The error is UNKNOWN value in payload '@1XR'. Cannot generate value for msg.output

Its telling you there was no matching `case` in the `switch` & so the `default` was reached where very clearly the error `UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.payload` is generated.

Look at comments in the code...

```auto
switch (msg.alphaNumeric) {
  case "@1T@1XR@1Y10": /* <<< ***MATCH @1T@1XR@1Y10 will hit here**** /
  msg.payload = "1";
  break;
  case "@1T@1XR@1Y236": /* <<< ***MATCH @1T@1XR@1Y236 will hit here**** /
  msg.payload = "2";
  break;
  case "@1T@1XR@1Y219": /* <<< ***MATCH @1T@1XR@1Y219 will hit here**** /
  msg.payload = "3";
  break;
  default: /*<<< *** ANYTHING NOT MATCHED WILL COME HERE - the below will be fired - THIS IS WHATS HAPPENING */
  node.error(`UNKNOWN value in payload '${msg.payload}'. Cannot generate value for msg.payload`, msg);
  return null;//halt flow of msg - dont trigger output of this node
}

```

...so add another case for `@1XR`

If you look at the debug output generated by the function node `convert msg` - it will include the EXACT value in `msg.alphaNumeric` that you need to MATCH in your additional `case` statement.

---

<div class="post-metadata">

**Author:** ![krikkit](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@krikkit](https://discourse.nodered.org/u/krikkit)\
**Post date:** [17 June 2019 08:51 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/39 "2019-06-17T08:51:04Z")

</div>

The more I scan the more inconsistency I have with same items... I wonder if it is related with the input from the serial port? I mean for same items I get  
0162  
R 016  
162

I am adding all the cases but I wonder if I could have a little bit more of consistency.

The serial port is set to 9600 because it is the only speed that gives me ascii code instead of binary data and I split the message after 9 characters

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 June 2019 10:02 UTC](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017/40 "2019-06-17T10:02:52Z")

</div>

Remind us what the data is coming from. Do you have a spec of what it should be?

[Previous page](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017.md?page=1)

[Next page](https://discourse.nodered.org/t/trigger-a-message-payload-based-on-input-from-parallel-port/12017.md?page=3)
