01-24-2018 04:27 AM
Hello,
I am trying to establish a connection between labview and raspberry pi. My raspberry pi measures two values and I would like to see them in the labview using UDP connection. I have a port and IP number of my raspberry pi but it seems it does not connect. I am getting error 1 saying that the path might be incorrect. If you have any ideas on how to make it work I would be very greatful for all the help. I am attaching the vi file.
Thank you.
01-24-2018 05:49 AM - edited 01-24-2018 05:57 AM
@Skigorv wrote:
Hello,
I am trying to establish a connection between labview and raspberry pi. My raspberry pi measures two values and I would like to see them in the labview using UDP connection. I have a port and IP number of my raspberry pi but it seems it does not connect. I am getting error 1 saying that the path might be incorrect. If you have any ideas on how to make it work I would be very greatful for all the help. I am attaching the vi file.
Thank you.
I think the port you use (5000) is reserved/blocked for other tasks. Use another port number, like 650...
By the way, it is enough if you specify the port number, you can leave that "service name" string input (where you typed in an IP address) unused.
Also, be sure that you have an ongoing UDP broadcast at the Raspberry side. You do not need to use timing at the LabVIEW side, since the UDP Read has a timeout input (by default 25 sec as i remember). So your UDP server (Raspberry Pi) will determine the timing (use there some sane delay, I guess you use Python, see an example UDP code below which works for me).
#UDP Python server at your Raspberry Pi import time import random import socket UDP_IP = "192.168.1.126" #IP address of your PC UDP_PORT = 650 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP while True: try: value = random.uniform(0, 10) print(value) sock.sendto(value, (UDP_IP, UDP_PORT)) # Sleep for half a second. time.sleep(0.5) except KeyboardInterrupt: break print('\nStopped fine!')
Edit: here is your modified VI. You should also program error handling, so if you need, you can clear Timeout error for example...
01-24-2018 06:07 AM - edited 01-24-2018 06:08 AM
Thank you very much for your response!
In the string format I wanted to see the timestamp because the Raspberry Pi also provides that (forgot to mention that in the first post)
Thank you again, I will make these changes as you suggested.
01-24-2018 06:10 AM
@Skigorv wrote:
Thank you very much for your response!
In the string format I wanted to see the timestamp because the Raspberry Pi also provides that (forgot to mention that in the first post)
Thank you again, I will make these changes as you suggested.
Still, this is definitely the wrong way to parse an incoming string using LabVIEW. If you show your typical string format, we can suggest a more straightforward parsing...
01-24-2018 10:23 AM
To be safe, I would avoid using port numbers below 1024 unless you are specifically communicating with a known service. Here are the recommendations for port number ranges in TCP:
|
01-25-2018 07:20 AM - edited 01-25-2018 07:21 AM
Thank you very much for your answers.
The string looks as follows:
1516885782 25/01/2018 14:09:42 r temp: 24.46 °C RH: 31.27 temp1: 24.00 °C temp2: 23.81 °C
which corressponds to:
Linux time, date, time, r, temperature, humidity, temperature1, temperature 2.
They are seperated by two spaces.
I would need to extract date, time, temperature, humidity, temperature1 and temperature2.
I am planning to see the whole string in one window, and seperate windows for the date and time and seperate windows for these 4 measurements.
Thank you again for all your help.