# Serial input won't split on hex character? (re: STX / ETX)

**URL:** https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260
**Category:** General
**Created:** [13 June 2020 03:01 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260 "2020-06-13T03:01:57Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![sofakng](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sofakng](https://discourse.nodered.org/u/sofakng)
#### Post date: [13 June 2020 03:01 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/1 "2020-06-13T03:01:57Z")

</div>

I'm new to Node-RED and I'm trying to use the serial input node to have it detect response messages from the serial port in the format: STX .. ETX.

If I don't assign a start character and split character it displays fine:

 ![Screen Shot 2020-06-12 at 10.52.52 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/00b0804345fe84381ba6fa52c5fafc446acf56e7.png)

In the debug output you can see the 0x2 and 0x3 in the message.

However, if I assign them as start/split characters then I don't get any output at all:

 ![Screen Shot 2020-06-12 at 10.54.16 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a1e25ddebdfa757f2a74700b464edc3e44026b2.png)

What am I doing wrong?

I'm looking at [other threads](https://discourse.nodered.org/t/split-input-on-character-is-not-working-with-a-serial-port/16018/13) that might provide a clue. In my flow, I have one serial output node (to send test messages to the serial port) and then a separate serial input node to see the responses. I will look into using the serial request node, but I wanted to separate them for now to play around with Node-RED.

---

<div class="post-metadata">

### Author: ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)
#### Post date: [13 June 2020 07:46 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/2 "2020-06-13T07:46:21Z")

</div>

The answer is on the bottom of the screen shot.  
You have to enter 0x02 instead of 0x2.

---

<div class="post-metadata">

### Author: ![sofakng](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sofakng](https://discourse.nodered.org/u/sofakng)
#### Post date: [13 June 2020 14:19 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/3 "2020-06-13T14:19:57Z")

</div>

I've also tried that (and double-checked just now) and it doesn't work either. ☹

I think I've tried everything I can think of ... (and I made sure to re-deploy, etc)

 ![Screen Shot 2020-06-13 at 10.21.16 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b6b58dd112c6a2846db917611c5921ef36dbac7d.png)

Here is my flow:

 ![Screen Shot 2020-06-13 at 10.22.22 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc793973b765ef7f78405ea1d900daa136793405.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: [13 June 2020 15:12 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/4 "2020-06-13T15:12:07Z")

</div>

With that setup what do you see in the debug?  
What happens if you leave in the split on but take off the wait for, and vice versa.

---

<div class="post-metadata">

### Author: ![sofakng](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sofakng](https://discourse.nodered.org/u/sofakng)
#### Post date: [13 June 2020 15:57 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/5 "2020-06-13T15:57:19Z")

</div>

OK - This is quite strange and frustrating.

These settings produce consistent results every single time:

 ![Screen Shot 2020-06-13 at 11.51.31 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce0957521b17572a33d2c48502e10b385c7592d7.png)

You can see the 0x2 at buffer[8] and the 0x3 at buffer[14].

These next settings only work sometimes and it's very random:

 ![Screen Shot 2020-06-13 at 11.55.27 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/dedef4a2f2650d5a3127ded3085c2fd77b944ef7.png)

This is really driving me crazy... The first settings work every single time without fail and the data is exactly the same in the debug window. I'm using my [Turn Off] injector to send data into the serial port for my testing. I've also monitored the serial port myself (minicom, etc) and the data input/output is exactly the same so I'm not sure why the start character is acting so inconsistently?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [13 June 2020 16:51 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/6 "2020-06-13T16:51:53Z")

</div>

Has anyone got any quick Arduino/ESP fu to knock up a quick .ino file to send some data over serial like above so we can attempt to debug this ? thanks

---

<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: [13 June 2020 16:54 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/7 "2020-06-13T16:54:00Z")

</div>

With the start character specified and the timeout, when it doesn't work what do you see in the debug? Anything?

---

<div class="post-metadata">

### Author: ![sofakng](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sofakng](https://discourse.nodered.org/u/sofakng)
#### Post date: [13 June 2020 17:16 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/8 "2020-06-13T17:16:47Z")

</div>

@dceejay I'll create an Arduino sketch to recreate the exact input/output sequence. Thank you SO MUCH for looking into this!

What device is easiest for you to test with? I can write something for Arduino Uno, ESP8266, ESP32, etc.

@Colin When it doesn't work I don't see anything at all in the debug.

---

<div class="post-metadata">

### Author: ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)
#### Post date: [13 June 2020 17:19 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/9 "2020-06-13T17:19:59Z")

</div>

Here is an Arduino test script.

```auto

#define ARRAYSIZE 15

byte myarray[ARRAYSIZE] = {0x33,0x30,0x20,0x61,0x31,0x20,0x30,0xd,0x2,0x20,0x32,0x20,0x38,0x20,0x3};

void setup() {
  Serial.begin(19200);

}

void loop() {
  for (int i = 0; i < ARRAYSIZE ; i++) {
    Serial.write(myarray[i]);
  }
delay(1000);
}

```

Sorry for the crtl+v, it's not allowed to upload ino or zip file here.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [13 June 2020 17:33 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/10 "2020-06-13T17:33:24Z")

</div>

Great - that looks good.. will give it a go.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [13 June 2020 19:37 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/11 "2020-06-13T19:37:32Z")

</div>

Found it... - version 0.10.3 pushed to npm. Should update in flows soon.  
Thanks all.  
Now prints me a buffer like  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/47a8174b578efb4049d59ff1f93f2d613f576253.png)  
when set to look for 0x02 and split on 0x03

---

<div class="post-metadata">

### Author: ![sofakng](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sofakng](https://discourse.nodered.org/u/sofakng)
#### Post date: [13 June 2020 19:53 UTC](https://discourse.nodered.org/t/serial-input-wont-split-on-hex-character-re-stx-etx/28260/12 "2020-06-13T19:53:06Z")

</div>

@dceejay Wow - thanks so much for taking the time to fix it and so quickly! Initial testing looks like your fix is working.

Thanks very much as well to @edje11 for writing the test code and to @Colin for helping!

Going forward, it looks like I should use the serial request node though, right? For example, I need to send a serial command and wait for an acknowledge response. (I was using Serial In and Serial Out to learn Node-RED and test the commands individually, etc)

The goal is of my first project (workflow) is to convert a serial device to mqtt.
