Files
matlab-python/ATD/SMS.m

130 lines
5.6 KiB
Matlab
Executable File

function SMS(IDcentralina,DTcatena,Sito,Users_SMS,Criterio,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
[rU,cU] = size(Users_SMS);
NumTel = cell(1);
Language = cell(1);
j = 1;
if cU > 1
for i = 1:rU
if isempty(Users_SMS{i,6}) == 0 % l'utente ha un numero di telefono
NumTel(j,1) = Users_SMS(i,6);
Language(j,1) = Users_SMS(i,4);
j = j+1;
end
end
end
%% ------ INVIO SMS TRAMITE MAIL-TO-SMS SKEBBY -------
% Settaggio Email mittente
setpref('Internet','E_mail','aseparma@gmail.com');
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username','aseparma@gmail.com');
setpref('Internet','SMTP_Password','Mums@2016');
props=java.lang.System.getProperties;
pp=props.setProperty('mail.smtp.auth','true'); %#ok
pp=props.setProperty('mail.smtp.socketFactory.class','javax.net.ssl.SSLSocketFactory'); %#ok
pp=props.setProperty('mail.smtp.socketFactory.port','465'); %#ok
if strcmp(Criterio,'Fukuzono')
sms = 1;
elseif strcmp(Criterio,'FIFA')
sms = 2;
elseif strcmp(Criterio,'Soglie')
sms = 3;
end
% --- Invio sms di allertamento utenti ---
[r,~]=size(NumTel);
Condizione = cell2mat(NumTel);
if isempty(Condizione) == 0 % almeno un utente da avvisare
for k=1:r
check = char(NumTel(k,1));
[~,cC] = size(check);
if cC >= 1
if Language{k,1} == 2 %ITA
if sms == 1
testosms = (['ALLARME - Criterio Inverso della Velocità attivato per la Centralina ' IDcentralina...
', Catena ' DTcatena ' nel sito di ' Sito '. Controllare l''email per maggiori dettagli.']); %testo sms
elseif sms == 2
testosms = (['ALLARME - Criterio FIFA attivato per la Centralina ' IDcentralina...
', Catena ' DTcatena ' nel sito di ' Sito '. Controllare l''email per maggiori dettagli.']); %testo sms
elseif sms == 3
testosms = (['ALLARME - Soglie superate per la Centralina ' IDcentralina...
', Catena ' DTcatena ' nel sito di ' Sito '. Controllare l''email per maggiori dettagli.']); %testo sms
end
else %ENG
if sms == 1
testosms = (['ALARM - Inverse of Velocity Criterion Activated for Datalogger ' IDcentralina ', Array ' DTcatena ', Site: ' Sito...
'. Check the email for further details. ''']); %testo sms
elseif sms == 2
testosms = (['ALARM - FIFA Criterion Activated for Datalogger ' IDcentralina ', Array ' DTcatena ', Site: ' Sito...
'. Check the email for further details. ''']); %testo sms
elseif sms == 3
testosms = (['ALARM - Thresholds activated for Datalogger ' IDcentralina ', Array ' DTcatena ', Site: ' Sito...
'. Check the email for further details. ''']); %testo sms
end
end
NUMERO_TEL = num2str(cell2mat(NumTel(k,1))); % numero telefono
soggetto = 'ASE: Allarme Fukuzono!';
utente = [NUMERO_TEL '@classic.skebby.com'];
sendmail(utente,soggetto,testosms)
if sms == 1
text = ['Alert of Level #5 SMS sent to ' NUMERO_TEL '!'];
elseif sms == 2
text = ['Alert of Red Code SMS sent to ' NUMERO_TEL '!'];
elseif sms == 3
text = ['Alert SMS sent to ' NUMERO_TEL ' for the thresholds overcoming!'];
end
fprintf(fileID,fmt,text);
end
end
% scrivo invio sms a utenti autorizzati nel logfile
text = 'Alarm activated, email-to-sms process completed - Alert sent to authorized users!';
fprintf(fileID,fmt,text);
end
% --- Invio sms a destinatari ASE ---
recipients_ITA{1,1} = '+393482453680'; % Alessandro Valletta
recipients_ITA{2,1} = '+393493048545'; % Andrea Carri
recipients_ITA{3,1} = '+393406654863'; % Roberto Savi
recipients_ITA{4,1} = '+393485113211'; % Andrea Segalini
[rASE,~]=size(recipients_ITA);
for z = 1:rASE
if sms == 1
smsASE = (['ALLARME di livello massimo - Criterio di Fukuzono Attivato per la Centralina' IDcentralina...
', Catena ' DTcatena ' nel sito di ' Sito '. Controllare l''email per maggiori dettagli.']);
soggettoASE = 'ASE: Allarme Fukuzono!';
elseif sms == 2
smsASE = (['ALLARME - Criterio FIFA Attivato per la Centralina' IDcentralina...
', Catena ' DTcatena ' nel sito di ' Sito '. Controllare l''email per maggiori dettagli.']);
soggettoASE = 'ASE: Allarme FIFA!';
elseif sms == 3
smsASE = (['ALLARME - Soglie superate per la Centralina' IDcentralina...
', Catena ' DTcatena ' nel sito di ' Sito '. Controllare l''email per maggiori dettagli.']);
soggettoASE = 'ASE: Allarme Soglie!';
end
Num_ASE = num2str(cell2mat(recipients_ITA(z,1))); % numero telefono ASE
utenteASE = [Num_ASE '@classic.skebby.com'];
sendmail(utenteASE,soggettoASE,smsASE)
% scrivo invio sms a utenti autorizzati nel logfile
if sms == 1
text = ['Alert of Level #5 SMS sent to ' Num_ASE '!'];
elseif sms == 2
text = ['Alert of Red Code SMS sent to ' Num_ASE '!'];
elseif sms == 3
text = ['Alert SMS sent to ' NUMERO_TEL ' for the thresholds overcoming!'];
end
fprintf(fileID,fmt,text);
end
text = 'Alarm activated, email-to-sms process completed - Alert sent to ASE users!';
fprintf(fileID,fmt,text);
fclose(fileID);
end