I have an appdesigner application where the data coming from two sensors is graphed in real time through Arduino. Those sensors are: ultrasonic sensor and light sensor. The application in appdesigner reads the data through the Arduino Uno and plots the data into a UIAxes component.
Private properties of the app:
properties (Access = private)
a;
h;
h2;
h3;
btnSt = 0;
initialTime = 2;
end
Code to configure the Arduino when the app is executed:
function startupFcn(app)
movegui(app.UIFigure, "center")
app.a = arduino;
app.a.configurePin('A0', 'AnalogInput');
app.a.configurePin('A1', 'AnalogInput');
end
Code that read and plot the data in the UIAxes when a button is pressed:
function StartPushed(app, event)
cla(app.UIAxes, "reset");
cla(app.UIAxes2, "reset");
app.h = animatedline(app.UIAxes, "Color", "Black");
app.h2 = animatedline(app.UIAxes2, "Color", "Black");
start = 1;
% stops the app when the stop button is pressed
while app.btnSt == 0
fotoRes = readVoltage(app.a, 'A0');
distance = readVoltage(app.a, 'A1');
distCm = (3027.4/distance)^1.2134;
tp = app.initialTime - start;
% plot the data of the light sensor
addpoints(app.h, tp, fotoRes);
% plot the data of the ultrasonic sensor
addpoints(app.h2, tp, distCm);
drawnow
app.initialTime = app.initialTime + 1;
end
end
So in conclusion, is there a way to do the same but from a Matlab web application server? Offcourse, with the condition of take the data from real time. Any help is appreciated.
What you need to make is a web service, but im not really sure if Matlab could be used to code a Web Service, however Matlab can read data from a web service using an http request... let me explain...
Here is what i what your local setup looks like:
Sensor->(reads voltages)->Arduino A0 Pin ->(usb serial communication)->Your local computer with Matlab
and that works totally fine, but when you host your matlab app lives in a web server elsewhere the flow of the data would be as follows:
Sensor->Arduino-[something to connect the arduino to the internet]->Web Service->WebApp
So there are two additional steps to consider:
Sensor->Arduino-[something to connect the arduino to the internet]->[Web Service living within your app->WebApp]
but i have not found any info on how to do that... the alternative would be to use an existing service like Arduino Cloud IoT or aREST my recomended architecture would look like this:
Sensor->Arduino with esp8266-> Arduino IoT API ->WebApp
Hope this helps, and goodluck!