# Skip blank lines from network data

**URL:** <https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551>\
**Category:** Processing for Pi\
**Created:** [July 7, 2019, 8:04am UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551 "2019-07-07T08:04:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauledd](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@pauledd](https://discourse.processing.org/u/pauledd)\
**Post date:** [July 7, 2019, 8:04am UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/1 "2019-07-07T08:04:05Z")

</div>

Hi there,

**Constitution** :  
bloody beginner

**Situation** :  
I try to receive serial data into processing via LAN from a Raspberry Pi that in turn receives the data from /dev/ttyUSB0 connected Arduino (ADC Data, println every 2ms)  
The data looks like that:

```auto
646
382
364
374
364
...

```

The chain looks like that:

Arduino ADC -\> Serial.println -\>RaspberryPi -\> nc 192.168.1.100 5555 \< /dev/ttyUSB0 -\> ClientPC 192.168.1.100 port 5555 -\>processing

**Problem:**  
For some unknown reason I get a blank line between every data line. The blank line does not exist at RaspberryPi side… I checked that with “screen /dev/ttyUSB0 38400”.

Now I use this code in processing to receive the data and output it in the console:

```auto
import processing.net.*;

Server myServer;
int port = 5555;

void setup(){
 size(2,2);
 myServer = new Server(this, port);
}

void draw() {
    Client thisClient = myServer.available();
    if(thisClient != null){
      String whatClientSaid = thisClient.readString();
      if(whatClientSaid != null){
       println(whatClientSaid);
      }
    }
}

```

And the output looks like this:

```auto
589

592

602

614

621

622

```

I cant figure out where in my chain the blank line gets inserted, maybe netcat is doing that. Does anyone have a idea how to get rid of the blank line? Or how to skip those lines in processing since they seem not to match “!=null”…  
Any ideas?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [July 7, 2019, 9:12am UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/2 "2019-07-07T09:12:28Z")

</div>

yes,  
“null” means empty  
but the arduino uses to send CR LF

---

<div class="post-metadata">

**Author:** ![pauledd](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@pauledd](https://discourse.processing.org/u/pauledd)\
**Post date:** [July 7, 2019, 9:40am UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/3 "2019-07-07T09:40:55Z")

</div>

Thanks. I found another working approach:

On the RaspberryPi I now use “socat” to send the data from “ttyUSB0” to a listen port 5555, then on the ClientPC I use socat again to connect to the raspberryPi and  
relay the data to a virtual device called “ttyVUSB0”:

RaspberryPi:  
`socat /dev/ttyUSB0,raw,echo=0 tcp-listen:5555,reuseaddr`

ClientPC:  
`sudo socat PTY,raw,echo=0,link=/dev/ttyVUSB0cp:<RaspberryPi-IP>:5555`

Now I can simply use processing serial interface to receive the data:  
`myPort = new Serial(this, "/dev/ttyVUSB0" , 38400);`

Data is now received without blank lines.  
I had to “chown youruser:users /dev/ttyVUSB0” to gain permission  
to the device in processing.

---

<div class="post-metadata">

**Author:** ![pauledd](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@pauledd](https://discourse.processing.org/u/pauledd)\
**Post date:** [July 8, 2019, 4:08pm UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/4 "2019-07-08T16:08:52Z")

</div>

Well, it turned out this approach was also not ideal.  
Everytime I stopped processing and started it again it complains  
about the port being busy, so I had to stop the whole chain and restart all.

I ended up in using the network way in processing again:

this time only using one socat on the raspberryPi when processing  
has been started and is listening for an incoming connection from socat:

ClientPc(processing)

```auto
...
myServer = new Server(this, SERVERPORT);
...
Client thisClient = myServer.available();
...
myString = thisClient.readStringUntil('\n');
...

```

raspberryPi:  
`socat /dev/ttyUSB0,raw,echo=0 tcp:<ClientPcIp>:8888`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 8, 2019, 4:30pm UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/5 "2019-07-08T16:30:53Z")

</div>

Serial.println() adds a **carriage return and line feed** to end of string.  
[https://www.arduino.cc/reference/en/language/functions/communication/serial/println/](https://www.arduino.cc/reference/en/language/functions/communication/serial/println/)

println() adds a **carriage return and line feed** to the console print.

So…

`Serial.println("012");`

is same as sending:  
`Serial.print("012\r\n");`

On the receiving end you were not getting a “blank line” you were printing a string with a **carriage return and line feed** and printing a **carriage return and line feed** with:

`println("012\r\n");`

🙂

---

<div class="post-metadata">

**Author:** ![pauledd](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@pauledd](https://discourse.processing.org/u/pauledd)\
**Post date:** [July 8, 2019, 6:10pm UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/6 "2019-07-08T18:10:22Z")

</div>

So if I understand correctly CR+LF is practically two newlines at once?  
But why does the ArduinoIDE Serial Monitor not show both too? does it ignore one of it? Also “screen /dev/ttyUSB0 38400” does not show these  
double newlines… why does processing show them?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 8, 2019, 6:10pm UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/7 "2019-07-08T18:10:48Z")

</div>

Thanks for socat tip!

Came across this:

> **[socat - Cindy Sridharan - Medium](https://medium.com/@copyconstruct/socat-29453e9fc8a6)**
>
> I learned about socat a few years ago and am generally surprised more developers don’t know about it. Maybe I appreciate it all the more…

I will be exploring it further later in the year.

You may also want to explore:  
[https://processing.org/reference/libraries/net/Client.html](https://processing.org/reference/libraries/net/Client.html)  
[https://processing.org/reference/libraries/net/Client\_readStringUntil\_.html](https://processing.org/reference/libraries/net/Client_readStringUntil_.html)  
[https://processing.org/reference/trim\_.html](https://processing.org/reference/trim_.html)

🙂

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 8, 2019, 6:18pm UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/8 "2019-07-08T18:18:45Z")

</div>

> [@pauledd](#):
>
> So if I understand correctly CR+LF is practically two newlines at once?

That is not correct.

Serial.println(“012”); sends “012” to serial monitor along with a **carriage return and line feed** from the Serial.println() to serial monitor.

Serial.println(“012”) that is sent as a string to Processing sends “012\r\n”.

If Processing receives this string “012\r\n” and does a **print** (“012\r\n”) it will print **ONE**  **carriage return and line feed** that is already in the string.

If you do a **println** (“012\r\n”) you have **TWO**  **carriage return and line feeds** ; ONE from **string** and **TWO** from the **println()**;

Just a Serial.println(“”) alone will send a **carriage return and line feed**.

It will come to you…

glv

---

<div class="post-metadata">

**Author:** ![pauledd](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@pauledd](https://discourse.processing.org/u/pauledd)\
**Post date:** [July 8, 2019, 6:28pm UTC](https://discourse.processing.org/t/skip-blank-lines-from-network-data/12551/9 "2019-07-08T18:28:05Z")

</div>

thanks a lot, got it 🙃
