Recieving UDP from iphone

9 ビュー (過去 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 Center および File ExchangeMATLAB Mobile についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by