Raspberrypi5-simulink TCP/IP problem transfering data
4 views (last 30 days)
Show older comments
Hi, i am trying to establish a TCP/IP communication between simulink model and my raspberry pi 5 board, i am able to connect them but when it's the time to receive data from simulink to raspberry pi i am not able to receive something, although the ip adress and port are correct, you find attached a part of the simulink model responsable of sending data to raspberrypi and u will find the code of receving data in raspberrypi![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1673271/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1673271/image.png)
and this is my code:
import socket
import numpy as np
def process_data(received_data):
a, b, c = [float(val) for val in received_data.split(',')]
command = simulationat(a, b, c)
return command
def setup_server(host='0.0.0.0', port=25000):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((host, port))
server_socket.listen(1)
print(f"Listening on {host}:{port}")
return server_socket
def accept_connections(server_socket):
while True:
client_socket, addr = server_socket.accept()
print(f"Connected by {addr}")
try:
while True:
# Receiving data from client (Simulink)
data = client_socket.recv(1024).decode().strip()
if not data:
break
print(f"Received data: {data}")
# Process the data
response_command = process_data(data)
# Send the response command back to client (Simulink)
client_socket.sendall((response_command + '\n').encode())
except ConnectionResetError:
print(f"Connection lost with {addr}")
finally:
client_socket.close()
server_socket = setup_server(host='192.168.x.x', port=25000)
accept_connections(server_socket)
0 Comments
Answers (0)
See Also
Categories
Find more on Development Computer Setup in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!