- MATLAB Support Package for Android Sensors Documentation (mathworks.com)
- Setup and Configuration - MATLAB & Simulink (mathworks.com)
- Sensor Data Collection with MATLAB Mobile or MATLAB Online - MATLAB & Simulink (mathworks.com)
- Collect and plot data from a TCPIP server in real time - File Exchange - MATLAB Central (mathworks.com)
- MATLAB TCP/IP - code example - File Exchange - MATLAB Central (mathworks.com)
How can I read streaming UDP or TCP/IP sensor data from smartphone on MATLAB desktop?
31 views (last 30 days)
Show older comments
Ezgi Ecevit on 4 Jan 2021
Answered: Pravarthana P on 14 Feb 2022
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?
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("www.EXAMPLE_WEBSITE.com", 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.
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:
Find more on TCP/IP Communication in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!