- 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?
17 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Pravarthana P
2022-2-14
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:
%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
fopen(t);
%Transmit data to the server(or a request for data from server)
fprintf(t, "GET /");
%Pause for the communication delay, if needed.
pause(1)
%Receive lines of data from server
while(get(t,'BytesAvailable')>0)
t.BytesAvailable
DataReceived=fscanf(t)
end
%Disconnect and clean up the server connection.
fclose(t);
delete(t);
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:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!