LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UDP connection with Raspbery Pi

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.

0 Kudos
Message 1 of 6
(8,857 Views)

@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...

 

UDP Rasberry-1_BD.png

0 Kudos
Message 2 of 6
(8,832 Views)

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.

 

0 Kudos
Message 3 of 6
(8,823 Views)

@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...

0 Kudos
Message 4 of 6
(8,817 Views)

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:

 

  • Ports 0 to 1023 are Well-Known Ports.
  • Ports 1024 to 49151 are Registered Ports (often registered by a software developer to designate a particular port for their application)
  • Ports 49152 to 65535 are Public Ports.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 6
(8,796 Views)

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.

0 Kudos
Message 6 of 6
(8,779 Views)