Recieving UDP from iphone

조회 수: 8 (최근 30일)
Farhaan SHaikh
Farhaan SHaikh 2011년 6월 24일
댓글: Kiat Nern Yeo 2019년 6월 18일
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
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
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
Ankit Desai 2011년 7월 29일
You can use Instrument Control Toolbox's UDP object to achieve that.
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
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
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
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.

Farhaan SHaikh
Farhaan SHaikh 2011년 6월 24일
how do i know if i have the instrument control toolbox?? If i do have it how do i go about writing the right code?? I have been trying u = udp('127.0.0.1',10552) Then using fopen etc but to be honest i dont really know what i am doing.
  댓글 수: 1
Walter Roberson
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

댓글을 달려면 로그인하십시오.


Farhaan SHaikh
Farhaan SHaikh 2011년 8월 4일
Ankit, thanks for the help. Will try that and see where i get.. Will report back.
Thanks

카테고리

Help CenterFile Exchange에서 MATLAB Mobile에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by