# feb/23/2018 21:28:41 by RouterOS 6.27 # software id = YTTQ-EI5V # /system script add name=Alarme policy=\ ftp,reboot,read,write,policy,test,password,sniff,sensitive source="# Scrip\ t Alarme_Victron\ \n# Acquisition de l'alarme d'un chargeur Victron\ \n# En fonctionnement normal le chargeur Victron presente une boucle entre\ \_les broches NC et COM\ \n# sur la paire 3 du cable ethernet de 5 metres, cette boucle disparait e\ n cas de faute (tension\ \n# trop basse ou tension trop elevee).\ \n# Marc Dilasser, Le Net du Kermeur, Fevrier 2018\ \n\ \n:local TT\ \n:local PST1\ \n:local PST2\ \n:local STA1\ \n:local LEN1\ \n:local STA2\ \n:local LEN2\ \n:local PAIR\ \n:local MSG\ \n:local NUMTEL\ \n:local PORT\ \n:local IJ\ \n:local STAS [:toarray (p1=\"x\", p2=\"x\", p3=\"x\", p4=\"x\")]\ \n:local LENS [:toarray (p1=0, p2=0, p3=0, p4= 0)]\ \n:local STAT\ \n:local INTF \"ether5\"\ \n:local STATOK \"short\"\ \n:local LENMIN 4\ \n:local LENMAX 6\ \n:local DEBUG 0\ \n\ \n# Acquisition des infos des paires de l'interface ether5\ \n:set TT [:tostr [/interface ethernet cable-test \$INTF as-value]]\ \n:if (\$DEBUG > 0) do={ :put \$TT; }\ \n:set PST1 [:find \$TT \"=\" 0 ]\ \n:set PST2 [:find \$TT \";status\" \$PST1 ]\ \n:set STAT [:pick \$TT (\$PST1 + 1) (\$PST2 - \$PST1) ] \ \n:if (\$DEBUG > 0) do={ :put \"\$PST1 \$PST2 \$STAT\"; }\ \n#\ \n:for IJ from 1 to 4 step 1 do={\ \n :set PST1 [:find \$STAT \":\" 0 ]\ \n :set PST2 [:find \$STAT \";\" 0 ]\ \n :set PAIR [:tostr (\"p\" . \$IJ)]\ \n :set (\$STAS->\$PAIR) [:pick \$STAT 0 \$PST1]\ \n :set (\$LENS->\$PAIR) [:pick \$STAT (\$PST1 + 1)]\ \n :if (\$DEBUG > 0) do={ :put (\"Paire \" . \$IJ . \" : \" . \$STAS->\$\ PAIR . \" , \" . \$LENS->\$PAIR); }\ \n :set STAT [:pick [:tostr \$STAT] (\$PST2 + 1) 50]\ \n}\ \n\ \n# Etat normal : boucle sur la paire 3 a une distance comprise entre 4 et\ \_6m.\ \n# Sinon envoi d'un SMS d'alerte\ \n:if ((\$STAS->\"p3\" != \$STATOK) || (\$LENS->\"p3\" < \$LENMIN) || (\$L\ ENS->\"p3\" > \$LENMAX)) do={\ \n :set MSG (\"Le chargeur Victron est en faute\\nDatas : \" . \$STAS->\ \"p3\" . \", d=\" . \$LENS->\"p3\" . \"m\")\ \n :if (\$DEBUG = 0) do={\ \n :set PORT [/tool sms get port]\ \n :if ([:len \$NUMTEL] = 0) do={\ \n :set NUMTEL [/tool sms get allowed-number]\ \n }\ \n :do { \ \n /tool sms send \$PORT \$NUMTEL message=\$MSG\ \n } on-error={ \ \n :log error (\"Alarme_Victron en envoi de SMS\") \ \n }\ \n :log info (\$MSG)\ \n } else={\ \n :put (\"Erreur : \" . \$MSG)\ \n }\ \n}"