I am trying to gather data from sensors connected to a raspberry pi and send them over to my laptop for some processing. I have written a very basic matlab server (for on my laptop)
t = tcpip('127.0.0.1', 42069, 'NetworkRole', 'server');
fopen(t);
flag = true;
while flag
if t.BytesAvailable > 0
t.BytesAvailable
raw_data = fread(t, t.BytesAvailable);
data = typecast(uint8(raw_data), 'double');
current_x = data(1);
current_y = a.cell_size*a.rows - data(2);
current_th = -data(3);
flag = false;
end
end
.
.
.
fclose(t)
On my PI I have written the following class to handle sending the data over.
class LocalizationClient():
#TCP_IP = '127.0.0.1'
TCP_IP = '192.168.1.5'
TCP_PORT = 42069
BUFFER_SIZE = 1000
# MESSAGE = "Hello, World!"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def __init__(self):
self.s.connect((self.TCP_IP, self.TCP_PORT))
print("connected to server")
def sendData(self,MESSAGE):
try:
self.s.send(MESSAGE)
except BrokenPipeError as e:
print(e)
self.close()
raise RuntimeError()
In my driver code I create an object and try to send a message like so:
lo_c = lc.LocalizationClient()
lo_c.sendData(np.array([float(x), float(y), float(th)]))
.
.
.
for x in range(50):
measures = lidar.measures
measures = np.append([float(dx), float(dy), float(dth)], measures)
lo_c.sendData(measures)
time.sleep(.2)
All of this was working fine and dandy while I was just testing with loopback on my laptop, but when I tried to put it on the pi I get the following error on the python client side:
connected to server [Errno 32] Broken pipe
Traceback (most recent call last):
File "/home/pi/Desktop/EXAMPLES/LocalizationClient.py", line 21, in sendData
self.s.send(MESSAGE)
BrokenPipeError: [Errno 32] Broken pipe
It seems that connecting still works but when I try to send to the server the client throws an error. The server seems fine and Im not trying to send any data back over to the client yet. I have been banging my head into this one for a while now and any help would be appreciated.
ps some details about the network setup if it helps, I have put the pi in ad-hoc mode with IP statically assigned as 192.168.1.1 and connected my macbook to the network it created. My Mac is assigned static IP 192.168.1.5.