Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
app-notes:wlan-switching [2025/08/04 15:17] – created grayapp-notes:wlan-switching [2025/08/04 15:25] (current) gray
Line 1: Line 1:
-test+ ====== Set up and use the SDK skript WLAN-Switching ====== 
 + 
 +++++show code|  
 +<code – WLAN_switching.are> 
 +
 +###################################################################### 
 +###########  Please only make changes to the script here   ########### 
 +###################################################################### 
 + 
 +###### Please enter all SSIDs to be searched for here 
 +wlan_ssid_field = mkarray ( "<WLAN_SSID_1>", 
 +                            "<WLAN_SSID_2>", 
 +                            "<WLAN_SSID_3>", 
 +                            "<WLAN_SSID_4>"); 
 + 
 +###### Please enter the passwords here in the correct order for the SSID!  
 +###### Example: WLAN_SSID_1 for WLAN_Password_1 
 +wlan_passwort_field = mkarray ( "<WLAN_Password_1>", 
 +                                "<WLAN_Password_2>", 
 +                                "<WLAN_Password_3>", 
 +                                "<WLAN_Password_4>"); 
 + 
 +###### Please specify here where this function should be entered, under  
 +###### WLAN Client Configuration. Under WLAN Client, 10 (1 - 10) entries are possible. 
 +wlan_client_entry = 10;    #### int Value 1 to 10 Possible 
 + 
 +###### Which WLAN module should be used (WLAN 1 or WLAN 2)? 
 +wlan_interface =  2;     #### The one for WLAN 1 or the two for WLAN 2 
 + 
 +############################################################################### 
 +DEBUG=false;  # Enable debugging with true or disable with false 
 +############################################################################### 
 + 
 +prio_value = 0; 
 +release = 0; 
 + 
 +if (length(wlan_ssid_field) == length(wlan_passwort_field)){ 
 +   if(DEBUG)printf("Both fields are the same\n"); 
 +} else { 
 +     if(DEBUG)printf("An SSID:%s or password:%s is missing for execution.\n",length(wlan_ssid_field),length(wlan_passwort_field)); 
 +     nb_syslog("An SSID:%s or password:%s is missing for execution.",length(wlan_ssid_field),length(wlan_passwort_field)); 
 +     printf("end of program\n"); 
 +     exit(1); 
 +  } 
 +if (wlan_client_entry > 0){ 
 +  if(DEBUG)printf("The value wlan_client_entry is greater than zero: %s\n",wlan_client_entry); 
 +  if (wlan_client_entry <=10 ){ 
 +    if(DEBUG)printf("The value wlan_client_entry is less than or equal to ten: %s\n",wlan_client_entry); 
 +    wlan_client_entry = wlan_client_entry -1; 
 +    if(DEBUG)printf("The value wlan_client_entry has been changed: %s\n",wlan_client_entry); 
 +    prio_value = 10 - wlan_client_entry; 
 +    if(DEBUG)printf("The value prio_value is: %s\n",prio_value); 
 +  } else { 
 +       if(DEBUG)printf("The value wlan_client_entry is greater than ten: %s\n",wlan_client_entry); 
 +       nb_syslog("The value wlan_client_entry is greater than ten: %s",wlan_client_entry); 
 +       printf("end of program\n"); 
 +       exit(2); 
 +    } 
 +} else{ 
 +     if(DEBUG)printf("The value wlan_client_entry is less than or equal to zero: %s\n",wlan_client_entry); 
 +     nb_syslog("The value wlan_client_entry is less than or equal to zero: %s",wlan_client_entry); 
 +     printf("end of program\n"); 
 +     exit(2); 
 +  } 
 +switch (wlan_interface){ 
 +   case 1:  if(DEBUG)printf("The value one for WLAN 1: %s\n",wlan_interface); 
 +               wlan_interface = wlan_interface - 1; 
 +               if(DEBUG)printf("The value after the change: %s\n",wlan_interface); 
 +               wlan_scan = "WLAN1"; 
 +               if(DEBUG)printf("Output of the WLAN scan interface: %s\n",wlan_scan); 
 +            break; 
 +   case 2:  if(DEBUG)printf("The value two for WLAN 2: %s\n",wlan_interface); 
 +               wlan_interface = wlan_interface - 1; 
 +               if(DEBUG)printf("The value after the change: %s\n",wlan_interface); 
 +               wlan_scan = "WLAN2"; 
 +               if(DEBUG)printf("Output of the WLAN scan interface: %s\n",wlan_scan); 
 +            break; 
 +   default: if(DEBUG)printf("The value is not WLAN 1 or WLAN 2: %s\n",wlan_interface); 
 +               nb_syslog("The value is not WLAN 1 or WLAN 2: %s",wlan_interface); 
 +               printf("end of program\n"); 
 +               exit(3); 
 +            break; 
 +
 +while(true){ 
 + lan_link = struct_get(nb_status("wan"),"WANLINK1_STATE"); 
 + if (lan_link == "up") {                                                   /   WAN LINK setup */ 
 +   if(DEBUG)printf("LAN is up\n");                                         /   WANLINK1 is LAN2/WAN , WANLINK2 is WLAN2 , WANLINK3 is WWAN1 and WANLINK4 is WWAN2 */ 
 + } else {                                                                  /*    Must be adjusted according to customer requirements  */ 
 +      if(DEBUG)printf("LAN is down\n"); 
 +      wlan_off = struct_get(nb_status("wlan"),"WLAN2_OPER_TYPE"); 
 +      wlan_link = struct_get(nb_status("wan"),"WANLINK2_STATE"); 
 +      if (wlan_link == "down" || wlan_off == "off" || wlan_link == "dialing"){ 
 +        if(DEBUG)printf("WLAN is down\n"); 
 +        hotlink = struct_get(nb_status("wan"),"WAN_HOTLINK"); 
 +        if (hotlink == "WANLINK3" || hotlink == "WANLINK4" || release == 1){ 
 +          if (release != 1){ 
 +          if(DEBUG)printf("WWAN is currently online\n"); 
 +          } else { 
 +               if(DEBUG)printf("WWAN is currently not online\n"); 
 +            } 
 +          if(DEBUG)printf("Search for Wi-Fi now\n"); 
 +          sleep(1); 
 +          wlan_networks = nb_scan_networks(spriend of programntf("%s",wlan_scan)); # scan WLAN module 
 +          wlan_count = struct_get(wlan_networks,"NETWORK_COUNT"); 
 +          if(DEBUG)printf("%s SSIDs were found during the scan.\n\n", wlan_count); 
 +          for (i=0; (int)wlan_count > i; ++i){ 
 +             number_count = i + 1; 
 +             if(DEBUG)printf("Which number is used: %s\n",number_count); 
 +             wlan_ssid = struct_get(wlan_networks,sprintf("NETWORK%s_SSID",number_count)); 
 +             if(DEBUG)printf("The WLAN SSID that is there: %s\n", wlan_ssid); 
 +             if(DEBUG)printf("The WLAN stored in memory location %s\n\n",wlan_client_entry); 
 + 
 +      ##################################################################### 
 +      #####         From here, the Wi-Fi networks are stored          ##### 
 +      ##################################################################### 
 + 
 +             for (q=0; ((int)temp = length(wlan_ssid_field)) > q; ++q){ 
 +                index = q + 1; 
 +                if(DEBUG)printf("Which ssid field: %s\n",wlan_ssid_field[q]); 
 +                if(DEBUG)printf("How many SSIDs: %s\n",temp); 
 +                if(DEBUG)printf("Output the index: %s\n",index); 
 +                if (wlan_ssid == wlan_ssid_field[q]){ 
 +                  if(DEBUG)printf("The wireless network %s has been found.\n",wlan_ssid); 
 +                  ssid = struct_get(wlan_networks,sprintf("NETWORK%s_SSID",number_count)); 
 +                  cipher = struct_get(wlan_networks,sprintf("NETWORK%s_CIPHER_1",number_count)); 
 +                  if(DEBUG)printf("What parameters do we have: %s \n", cipher); 
 +                  if (cipher == "CCMP"){ 
 +                    cipher = tolower(cipher); 
 +                  } else { 
 +                     cipher = "all"; 
 +                    } 
 +                  encryption = struct_get(wlan_networks,sprintf("NETWORK%s_ENCRYPTION_1",number_count)); 
 +                  if (encryption == "WPA-PSK"){ 
 +                    encryption = "wpa1andwpa2"; 
 +                  } 
 +                  if (encryption == "WPA2-SAE"){ 
 +                  encryption = "wpa2andwpa3"; 
 +                  } 
 +                  if (encryption == "WPA2-PSK"){ 
 +                  encryption = "wpa2"; 
 +                  } 
 +                  ## Scan from Wi-Fi 
 +                  nb_config_set("wlan.1.settings.channel=0"); 
 +                  ret = nb_config_done(); 
 +                  while (ret){ 
 +                       if(DEBUG)printf("The config parameter channel 0 is in the execution: %s\n",ret); 
 +                       ret = nb_config_done(); 
 +                       sleep(1); 
 +                  } 
 +                  if(DEBUG)printf("The config parameter channel 0 is set to: %s\n",ret); 
 +                  nb_config_set(sprintf("wlan.%s.client.%s.ssid=%s",wlan_interface,wlan_client_entry,ssid)); 
 +                  ret = nb_config_done(); 
 +                  while (ret){ 
 +                       if(DEBUG)printf("The config parameter %s is in execution: %s\n",ssid,ret); 
 +                       ret = nb_config_done(); 
 +                       sleep(1); 
 +                  } 
 +                  if(DEBUG)printf("The config parameter %s is set to: %s\n",ssid,ret); 
 +                  nb_config_set(sprintf("wlan.%s.client.%s.cipher=%s",wlan_interface,wlan_client_entry,cipher)); 
 +                  ret = nb_config_done(); 
 +                  while (ret){ 
 +                       if(DEBUG)printf("The config parameter %s is in execution: %s\n",cipher,ret); 
 +                       ret = nb_config_done(); 
 +                       sleep(1); 
 +                  } 
 +                  if(DEBUG)printf("The config parameter %s is set to: %s\n",cipher,ret); 
 +                  nb_config_set(sprintf("wlan.%s.client.%s.secproto=%s",wlan_interface,wlan_client_entry,encryption)); 
 +                  ret = nb_config_done(); 
 +                  while (ret){ 
 +                       if(DEBUG)printf("The config parameter %s is in execution: %s\n",encryption,ret); 
 +                       ret = nb_config_done(); 
 +                       sleep(1); 
 +                  } 
 +                  if(DEBUG)printf("The config parameter %s is set to: %s\n",encryption,ret); 
 +                  ## Feste Wert 
 +                  nb_config_set(sprintf("wlan.%s.client.%s.secmode=wpa-psk",wlan_interface,wlan_client_entry)); 
 +                  ret = nb_config_done(); 
 +                  while (ret){ 
 +                       if(DEBUG)printf("The config parameter secmode is in the execution: %s\n",ret); 
 +                       ret = nb_config_done(); 
 +                       sleep(1); 
 +                  } 
 +                  if(DEBUG)printf("The config parameter secmode is set by: %s\n",ret); 
 +                  nb_config_set(sprintf("wlan.%s.client.%s.prio=%s",wlan_interface,wlan_client_entry,prio_value)); 
 +                  ret = nb_config_done(); 
 +                  while (ret){ 
 +                       if(DEBUG)printf("The config parameter prio is in the execution: %s\n",ret); 
 +                       ret = nb_config_done(); 
 +                       sleep(1); 
 +                  } 
 +                  if(DEBUG)printf("The config parameter prio is set by: %s\n",ret); 
 +                  ## Wi-Fi password 
 +                  nb_config_set(sprintf("wlan.%s.client.%s.psk=%s",wlan_interface,wlan_client_entry,(wlan_passwort_field[q])));  ## Passwort wird aus der Feld gezogen 
 +                  ret = nb_config_done(); 
 +                  while (ret){ 
 +                       if(DEBUG)if(DEBUG)printf("The config parameter psk is in the execution: %s\n",ret); 
 +                       ret = nb_config_done(); 
 +                       sleep(1); 
 +                  } 
 +                  q = length(wlan_ssid_field); 
 +                  if(DEBUG)printf("Value of q: %s\n",q); 
 +                  if(DEBUG)printf("The config parameter psk is set to: %s\n",ret); 
 +                  i = 100;   ## for end loop 
 +                  release = 0; 
 +                  } else { 
 +                       if(DEBUG)printf("no\n"); 
 +                    } 
 +             } 
 +          } 
 +          if(DEBUG)printf("The value i is: %s\n",i); 
 +          if (i <= 100) { 
 +            if(DEBUG)printf("No suitable Wi-Fi network found\n"); 
 +          } 
 +        } else{ 
 +             if(DEBUG)printf("The status of the hotlink at the moment %s\n", hotlink); 
 +             for (a=0; 3 > a; ++a){ 
 +                if(DEBUG)printf("Waiting for WWAN to come online\n"); 
 +                sleep(60); 
 +                if(DEBUG)printf("The value a: %s\n",a); 
 +                wwan_link = struct_get(nb_status("wan"),"WANLINK1_STATE"); 
 +                if(DEBUG)printf("Is WWAN still down: %s\n",wwan_link); 
 +                if (wwan_link == "down" || "dialing" && a == 2){ 
 +                  a = 10; 
 +                  release = 1; 
 +                  if(DEBUG)printf("Value release: %s\n",release ); 
 +                  if(DEBUG)printf("The WWAN is still down after 3 minutes.\n"); 
 +                  if(DEBUG)printf("Search for Wi-Fi\n"); 
 +                } 
 + 
 +             } 
 +          } 
 +      } 
 +      wlan_link = struct_get(nb_status("wan"),"WANLINK2_STATE"); 
 +      if (wlan_link == "up"){ 
 +        ret = nb_config_done(); 
 +        if(DEBUG)printf("The configuration has been completed:  %s\n\n",ret); 
 +        if(DEBUG)printf("WLAN is up\n\n"); 
 +      } else{ 
 +           if(DEBUG)printf("WLAN is Down\n\n"); 
 +        } 
 +   } 
 +   printf("New search after 30 seconds\n"); 
 +   sleep(30); 
 +
 +printf("end of program\n"); 
 +nb_syslog("end of program"); 
 +exit(0); 
 + 
 + 
 +
 +</code> 
 +++++