Script to autochange SSID when not internet

Hi Fellows,

I have the following challenge:

I’ve to develop an script to change SSID when internet is down.

I have the following script:

:log info “Check if internet is alive”

:if ([/ping altavista.com count=1] = 0) do={

/interface ethernet set [/interface wireless find name=wlan1] disabled=no
/interface ethernet set [/interface wireless find name=wlan1] disabled=yes


:log info “Altavista.com is down”
} else={
:log info “Altavista.comv is up”
}
:log info “It wansnt need to re-start wlan interface”


But my question is: how can I switch automatically SSID from my connection list?

I have an idea to disable for a second the current SSID with no internet until I get other that is up.

I need coaching to resolve this.

Thank you in advance

It sounds like the wireless is your internet connection, and if one goes down, you want to change to a different connection.

Assuming I understand you correctly, this bit of untested code should get you going:
:if ([/ping altavista.com count=1] = 0) do={
:log Internet down, switching providers
:local CurrentSSID [/int wireless get [find interface=“wlan1”] ssid];
:if ($CurrentSSID=“isp1-ssid”) do={
/interface wireless set [/int wi find name=wlan1] ssid=isp2-ssid
} else {
/interface wireless set [/int wi find name=wlan1] ssid=isp1-ssid
}
} else {
:log Internet up… nothing to do
}If you need to change security profiles, you can do this at the same time you change the ssid.

good luck!

Exactly!!! Thanks

About this, other question, is it possible to do this code using connection lists? Or how can I set a security profile?
Dummy question the code above isp1-ssid is the name of ssid I gonna switch?

yes… isp1-ssid would be the value to change.

You can set multiple paramaters at the same time… ssid=FOO security-profile=BAR

Good luck!

Mikrotik Masters, I’ve made some changes to the first version of this script, but I have problems running it.
Could you look around to figure what the problem is?


Script for verify internet status and do modifications in case of internet fail

Creating local variables

:local currentStat 1;
:log info (“Verifying if internet is up”);

Chech by ping if intenet is up

:if ([/ping altavista.com count=1] = 0) do={
:set currentStat 0;
}

#Modifier process Starts
:while ($currentStat = 0) do={
:log info (“No internet access, searching new connection”)
/interface ethernet set [/interface wireless find name=wlan1] disabled=no
:if ($currentStat = 0) do={
/interface wireless set [/interface wireless find name=wlan1] ssid=“CONNECTION1” security-profile=“default”
:delay 5s
:if ([/ping altavista.com count=1] != 0) do={
/log info (“Switched to CONNECTION1”);
:set currentStat 1;}}
:if ($currentStat = 0) do={
/interface wireless set [/interface wireless find name=wlan1] ssid=“CONNECTION2” security-profile=“default”;
:delay 5s
:if ([/ping altavista.com count=1] != 0) do={
:log info (“Switched to CONNECTION2”);
:set currentStat = 1;}}
}

You can do with netwatch tool also.
When the host is up execute the script like this:
/interface wireless set 0 ssid=Is-Up

When the host is down execute this:

/interface wireless set 0 ssid=Is-Down

Sent from my mobile phone using Tapatalk.

:if ([/ping altavista.com count=1] = 0) do={
  :log Internet down, switching providers
  :local CurrentSSID [/int wireless get [find interface="wlan1"] ssid];
  :if ($CurrentSSID="isp1-ssid") do={
    /interface wireless set [/int wi find name=wlan1] ssid=isp2-ssid
   } else {
    /interface wireless set [/int wi find name=wlan1] ssid=isp1-ssid
   }    
} else {
:log Internet up... nothing to do
}

i have mikrotik v.6.39.1
script cannot switching when internet on ssid1 down