05-05-2023 09:55 AM
Hi,
I'm using LabVIEW 2013 and currently develop a solar panel lawn mower for personal use. I'm having a problem acquiring voltage from the 10-bit ESP8266 to LabVIEW after some time. It is a simple data acquisition read from a voltage sensor for monitoring the battery voltage. I implemented a multiplexer (74HC4051) as I am planning to acquire more values from voltage and current sensors. For the time being, I try to test with one parameter and observe if it works. During the start, the acquired voltage is as expected but after some time the reading value changes to 0. In the Arduino program, it controls the selection of the input (A, B and C) for the output. Then it reads the ADC value followed by a delay of 40ms. Is the problem have something to do with TCP/IP protocols?
Thank you.
05-05-2023 10:30 AM
Is the value exactly zero? If so, then you likely have a TCP error. It will be displayed in the error out indicator after you stop the loop.
You should terminate the loop if you encounter an error. The shift register passes the error from the right to the left of the loop, which will make TCP Write/Read skip normal operation and output default values - which is an empty string that gets converted to a zero.
05-05-2023 11:07 AM
I haven't looked at your code (no time sorry) but might I recommend switching from raw TCP/IP to an MQTT protocol? It will handle a lot of your backend stuff automagically. Plus it'll let you monitor things VERY easily.
05-05-2023 03:13 PM
What would be better is to upload your VI and not a image of your VI.
05-05-2023 06:33 PM
Hi,
Thanks for the reply. I added a read string indicator to observe what exactly the received string and I found out the string contains \r\n after the data string (0-1023). The value 0 occurs when the received data has \r\n before the data string. So I made some changes to the VI.
a. Change from "intermediate" to "CRLF" at the read TCP/IP.
b. Inner while loop will stop when there is an error occurs and close TCP/IP connection.
c. Outer while loop to reconnect the TCP/IP and acquire data.
Hope this will work. If there is better suggestions please share.
Regards
05-06-2023 08:04 AM
Looks good. If you are sure your number fits withing four characters, you can leave it as it is. Otherwise increase the number of bytes to read a little, TCP Read will return as soon as either the requested number of bytes were received, or a CRLF was encountered.