Recieving UDP from iphone

3 Ansichten (letzte 30 Tage)
Farhaan SHaikh
Farhaan SHaikh am 24 Jun. 2011
Kommentiert: Kiat Nern Yeo am 18 Jun. 2019
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 Kommentare
Amir
Amir am 30 Jul. 2012
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 am 18 Jun. 2019
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 !

Melden Sie sich an, um zu kommentieren.

Antworten (4)

Ankit Desai
Ankit Desai am 29 Jul. 2011
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 Kommentare
Amir
Amir am 30 Jul. 2012
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 am 21 Aug. 2012
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.

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 24 Jun. 2011
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 am 24 Jun. 2011
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 Kommentar
Walter Roberson
Walter Roberson am 24 Jun. 2011
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

Melden Sie sich an, um zu kommentieren.


Farhaan SHaikh
Farhaan SHaikh am 4 Aug. 2011
Ankit, thanks for the help. Will try that and see where i get.. Will report back.
Thanks

Kategorien

Mehr zu MATLAB Mobile finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by