I have sent a number from Matlab via UDP using the commands below:
u=udp('192.168.137.239',5004) ;create UDP object
u.OutputBufferSize = 1000;
fopen(u)
fwrite(u,200,'int' ) ; write number 200
but when I receive this number on the Raspberry in python via UDP, it is not displayed correctly (it display 3355443200L), I use unpack to convert as in the following code:
import sys, struct
from socket import*
import numpy
import numpy as np
import pickle
SIZE = 65535
hostName = gethostbyname('0.0.0.0')
mySocket = socket(AF_INET, SOCK_DGRAM)
mySocket.bind((hostName,5004))
repeat = True
while repeat:
(data, addr)=mySocket.recvfrom(SIZE)
data1 = struct.unpack('I', data)
print " received meassage:",data1
Please tell me how to convert binary from Matlab into integer in python.