Recieving UDP from iphone
5 次查看(过去 30 天)
显示 更早的评论
Hi
I have an iphone application called Accel Pro which can stream data via UPD (see here http://www.wavefrontlabs.com/Wavefront_Labs/Accelerometer_Data.html)
the app gives me an address and port and continuously streams acceleration data from the iphones accelerometers. My question is how do i read this on Matlab???? I have been trying for hours.
Im haven't used matlab for this kind of thing ever before!!
2 个评论
Amir
2012-7-30
Hi,
Were you able to resolve your question? I'm stuck with the exact same problem. I can read those packets just fine using python, but no luck with the instrument control toolbox.
Kiat Nern Yeo
2019-6-18
Hello, does this work for the android tcp/ip block ?
I am not sure whether set it to the "server" or "client" mode.
I want to make the android phone the receipient of a wifi signal.
Another device will be the one emiting the wifi signal.
Cheers !
回答(4 个)
Ankit Desai
2011-7-29
u = udp('localhost',<port>,'localport',<port>);
u.InputBufferSize = 1000;
u.DatagramReceivedFcn = @localReadDatagram;
fopen(u);
The code above creates a UDP object and listens to port port. Depending on the packet size of the datagram you are receiving update the InputBufferSize property of the object. You want to make sure that input buffer size is greater than the packet length. The iPhone app that I used was sending packets of size lower than 1000, so the code above worked fine for me.
The DatagramReceivedFcn is the property you can set to point to a function that will be called everytime a datagram arrives. It is in this function that you can parse the incoming data and get the raw accelerometer values. Parsing will depend on the format in which you get the data from the iPhone.
The app that I used sent the data in string format and I ended up using the textscan. Here's the code I used to parse the incoming packet, inside the localReadDatagram function:
function localReadDatagram(obj,event)
rawString = fscanf(obj);
values = textscan(rawString,'%*s %*s %f %f %f','Delimiter',',');
x = values{1};
y = values{2};
z = values{3};
Hope this helps
-Ankit
2 个评论
Amir
2012-7-30
The above solution does not seems to work for me (I have matlab and the instrumentation control toolbox). I'm trying to stream data from an application called 'sensor data' (by the same publisher, wavefrontlabs). Using the code above, the datagramRecieverFcn is never called, as no bytes are recived on the port.
Ankit Desai
2012-8-21
That appears to be a configuration issue.
You might want to check the network settings and buffer size of the UDP object. Make sure you have your buffer size big enough to accommodate at least one datagram packet.
Walter Roberson
2011-6-24
You either need the Instrument Control Toolbox, or the MATLAB File Exchange contribution named "tcpudpip"
And you have to hope that your ISP isn't blocking incoming data on that port. And if you have a home or lab firewall, you have to hope that isn't blocking the data. And if you are running Windows, you probably have to work in the Security control panel to open the port.
0 个评论
Farhaan SHaikh
2011-6-24
1 个评论
Walter Roberson
2011-6-24
which udp
and see where it says the routine is. Basic MATLAB doesn't have a "udp" routine, so if the one you find is not one you wrote yourself, it is probably an appropriate one.
I suggest you read the Solution at http://www.mathworks.com/support/solutions/en/data/1-OUCYT/?solution=1-OUCYT
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!