How can I read streaming UDP or TCP/IP sensor data from smartphone on MATLAB desktop?

6 views (last 30 days)
I want to read the real-time sensor data on MATLAB by using UDP or TCP/IP server. However, I don't know which command I should use to read the data on the server. The main purpose of this to obtain the real-time sensor data from my smartphone's sensors on MATLAB desktop. I will use MATLAB desktop as client. How can I achieve that?

Answers (1)

Pravarthana P
Pravarthana P on 14 Feb 2022
Hi Ezgi Ecevit, it can be understood from your query that you are trying to read data from mobile sensor through UDP or TCP/IP. I hope you will find the following codes useful to use TCP/IP to acquire the data.
You can do it in two ways:
Either you can use simply the MATLAB support package for android package to use the predefined functions and object to acquire different sensor data.
Or as you have mentioned you can use TCP/IP or UDP server to acquire the data as follows:
This requires the usage if Instrument Control toolbox’s tcpip or udp object.
%Create TCP/IP object 't' Specify the server and corresponding port number.
t = tcpip("", 80);
%Set size of receiving buffer, if needed.
set(t, "InputBufferSize", 30000);
%Open connection to the server
%Transmit data to the server(or a request for data from server)
fprintf(t, "GET /");
%Pause for the communication delay, if needed.
%Receive lines of data from server
%Disconnect and clean up the server connection.
clear t
If you wish to use UDP server you can define the object using, change the object declaration part as follows and use UDP object instead of TCP/IP object:
u = udp('localhost',<port>,'localport',<port>);
Few links that you may find helpful:

Community Treasure Hunt

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

Start Hunting!