Sending a danger message on email or phone Number.

3 views (last 30 days)
I Have a live modbus data which once reached trip value i want it to send me a mail or message on phone as danger or machine under trip level. Is it possible in matlab to write a code where i can recive a mail or message. Can anyone guide me with the code of how i can send a mail from matlab to email/Phone. I have attached my code as well as the app.
i = 1;
data1A=[];
data1T=[];
data1Al=[];
while strcmp(app.Switch.Value, 'On')
clear m
m = modbus('serialrtu','COM5',BaudRate=9600);
m.Timeout = 0.5;
% Rack 1 Slot 1 Module 1
serverId1 = 2;
tripM1A = read(m,"holdingregs",1,1,serverId1,"uint16");
alarmM1A = read(m,"holdingregs",6,1,serverId1,"uint16");
fullscaleM1A = read(m,"holdingregs",11,1,serverId1,"uint16");
processM1A = read(m,"holdingregs",44,1,serverId1,"uint16");
tripM1B = read(m,"holdingregs",21,1,serverId1,"uint16");
alarm1B = read(m,"holdingregs",26,1,serverId1,"uint16");
fullscaleM1B = read(m,"holdingregs",31,1,serverId1,"uint16");
processM1B = read(m,"holdingregs",45,1,serverId1,"uint16");
% To plot data in UI Axes
data1A(i) = processM1A;
data1T(i) = tripM1A;
data1Al(i) = alarmM1A;
if i <= 60
plotRange = 1:i;
else
plotRange = (i-59):i;
end
% Ensure previous plots are not erased
hold(app.UIAxes, 'on');
plot(app.UIAxes, plotRange, data1A(plotRange), 'LineWidth', 1.5, 'Color', 'b'); % Process data
plot(app.UIAxes, plotRange, data1T(plotRange), 'LineWidth', 1.5, 'Color', 'r'); % Trip line
plot(app.UIAxes, plotRange, data1Al(plotRange), 'LineWidth', 1.5, 'Color', 'g'); % Alarm line
% Release hold after plotting
hold(app.UIAxes, 'off');
title(app.UIAxes, 'Simulated Live Trend');
xlabel(app.UIAxes, 'Time in seconds', 'Color', 'k');
ylabel(app.UIAxes, 'Amplitude', 'Color', 'k');
ylim(app.UIAxes, [0 fullscaleM1A]);
grid(app.UIAxes, "on");
pause(0.1);
i = i + 1;
end
Thanks & Regards.

Answers (1)

Christopher Stapels
Christopher Stapels on 3 Apr 2024
Sure, there are several ways to do that using ThingSpeak. The best way is using the alerts API. Jsut set up the alert in ThingSpeak and call the api endpoint in your code when you want to trigger the event. This will only send an email to you, but you can use a forwarding rule in you inbox to send it on. Or you can use an api call in MATLAB analysis (called by the alerts API) that calls an external service like Twilio that will distribute your email.

Categories

Find more on ThingSpeak 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!