LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read multiple sensors trough TCP/IP protocol

I have a code that reads the information from 4 humidity sensors and depending on the value they read, each one turns a valve on or off and also sends some notifications if the values are too high or too low. Im using an ESP32 controller and I wrote the code in Arduino IDE. Since I´m new to using this protocol I´m confused with how to make LabVIEW read the values from each individual sensor without mixing them up. I´ve watched some tutorials and I saw someone explaining that you have to put a constant on the "bytes to read" on the TCP read function, but I don´t understand how to figure out what that number would be.

0 Kudos
Message 1 of 3
(668 Views)

The answers depends on how you programmed the ESP32 to send the data. If it appends a line feed after each message, you just need to change the mode of TCP read to CRLF (carriage return, line feed) and make bytes to read as long as your longest message. In your case just wire 100 to bytes to read and you're good.

 

Generelly, you can have the ESP32 send messages that have a fixed size (like four bytes for each value) or you need to encode the message length in the message itself. In CRLF mode the message length is "everything until a new line is encountered". Look at the help for TCP Read, it explains it better than me.

0 Kudos
Message 2 of 3
(633 Views)

CRLF mode, like the name says, expects a <CR> and an <LF> character in exactly that order to detect it as "end of line" indication. That is different to VISA communication where you only can configure one character as termination indication and it will stop reading as soon as that character arrives in the stream.

 

For most modern network protocols that CRLF is not a problem. HTTP and the like all have standardized on using the Windows line termination sequence, rather than the alternative Unix (LF) or MacOS Classic (CR) line termination.

 

But if you want to use the CRLF mode of the TCP Read node in LabVIEW, your ESP32 program better appends both a <CR> and <LF> character to the end of your strings.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 3
(629 Views)