Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
app-hotes:wifi-switcher [2023/10/31 14:02] cakirapp-hotes:wifi-switcher [2023/12/12 12:21] (current) – [Goal] cakir
Line 1: Line 1:
 ====== Wifi Switcher ====== ====== Wifi Switcher ======
  
-===== Ziel ===== +===== Goal and benefit for the costumer ===== 
-Bei dieser Anleitung geht es um das Einrichten und Erklären des SDK Scripts das automatisch zu einem der WLAN access point wechseltDie erlaubten APs und das dazu passende Passwort sind in einer seperaten Datei zu finden.+In this guide we will describe how to setup the WiFi Switcher SDK script on a Netmodule routerThis script will take care of automatically connecting to a WiFi Access Point when it is part of a list we defined. The list is in a seperate file and consists of SSIDs and associated Password. The benefit is that only these known access points can be connected to.
  
-===== Anwendungsbeispiel ===== + 
-Hintergrund ist das ein Kunde, der unsere Router in Zügen einsetzt, gerne automatisiert zu dem WLAN am jeweiligen Bahnhof wecheln möchteJedoch aber nur zu diesen APs und nicht zu irgendwelchen anderen WLAN Netzen die irgendwo noch verfügbar sein sollten+===== Application example ===== 
 +Background for this script is a customer who uses our routers in railway applicationsThe router in the train is supposed to connect to a WiFi network on each respective train station. Only WiFi access points that can be found in the list are used to connect to
      
-===== Einrichten ===== +   
-Es folgt nun der step-by-step guide zum Einrichten der Wifi Switcher funktionalität.+<code c application-example> 
 +TRAIN        TRAIN        TRAIN          TRAIN 
 +STATION A    STATION B    STATION C      STATION X 
 ++--------+   +--------+   +--------+     +--------+ 
 +|WIFI AP1|   |WIFI AP2|   |WIFI AP3|     |WIFI APX| 
 +|        |          |          |            | 
 ++--------+   +--------+   +--------+ ... +--------+
  
-==== WAN im Link Manager ==== +     TRAIN WIFI CLIENT 
-Zunächst ist zu beachten das, nach dem Einrichten den Wifi Client, unser WLAN an Position 2 im Link Manager zu finden ist. +        +--------+ 
-Dies ist nötig damit das Script das richtige WAN Interface nach seinem Status abfragt. ++----------------------------------------------> 
-Die Rheinfolge der WAN Interfaces kann unter INTERFACES -> WAN -> Link Management geändert werden. +</code>
-Das WLAN Interface wird auch auf permanent gesetzt.+
  
-{{:app-notes:setup-wan.png}}+===== Setup ===== 
 +Here we will describe step-by-step how to setup the router with the wifi switcher functionality.
  
-==== Script anlegen und verknüpfen ==== +==== WAN in Link Manager ==== 
-Nach den folgenden Schritten ist das wifi-switcher.are Script(findet sich weiter unten in dieser Anleitung)  angelegt und kann schon laufenEs fehlt allerdings noch die Liste der Access Points (erledigen wir im nächsten Schritt).+First we need to make sure that, after setting up our WiFi client, WLAN1 is supposed to be in position 2 in link manager. This is neccessary so that the script queries the correct interface for it's status. The order of WAN interfaces can be changed under "INTERFACES -> WAN -> Link Management"Also we set WLAN1 to permanent. 
 + 
 +{{:app-notes:setup-wan.png}}
  
-=== Trigger === +==== Setup Trigger ==== 
-Hier richten wir den Trigger ein der das SDK Script starten wirdDa es die ganze Zeit laufen soll wird hier event-based -> sdk-startup gewähltSobald SDK also enabled ist wird auch under Wifi Switcher Script laufen.+Here we setup a trigger that will start our SDK script later onSince the script is supposed to run at all times we will set our trigger to "event-based -> sdk-startup"As soon as SDK is enabled our wifi switcher script will be running
  
 {{:app-notes:triggers.png}} {{:app-notes:triggers.png}}
  
-=== Script === +=== Setup Script === 
-Hier laden wir unser Wifi Switcher Script hoch. Es ist weiter unten in dieser Anleitung zu finden.+This is where we insert the code of our wifi-switcher script (can be found further down in this guide).
  
 {{:app-notes:scripts.png}} {{:app-notes:scripts.png}}
  
-=== Job === +=== Setup Job === 
-Zu guter letzt muss nun noch das Script und der Trigger in einem Job zusammengeführt werden.+Finally we have to bring script and trigger together in a job so that the trigger will be applied to our script.
  
 {{:app-notes:jobs.png}} {{:app-notes:jobs.png}}
  
-==== Wifi Networks Liste ==== +==== Setup WiFi Networks List ==== 
-Anders als das Wifi Switcher Script ist es hier nicht nötig für diese Liste von Access Points Job und Trigger zu setzenEs reicht aus wenn die Datei einfach nur zu finden istDer Grund warum wir die Liste via GUI einfügen und nicht einfach per Hand auf den Router kopieren ist das es so Update sicher ist und auch in der config auftaucht.+Unlike the wifi-switcher script the list of allowed wifi access points does not need to be connected with a job or triggerIt just needts to be available on the deviceThe reason why we use the GUI to insert this list is update security and also having this file be part of the router config. This would not be the case when we simply just copy it by hand.
  
-Wichtig ist aber das hier der korrekte Namen eingetragen wird. Also einfach die Liste (auch weiter unten zu finden) hoch laden und den Namen "wifi-networks.cfg" vergebenEs können übrigens beliebig viele WLAN Access Points in diese Liste eingetragen werden.+It is important to use the correct name "wifi-networks.cfg" for this file, otherwise the WiFi Switcher script will not be able to find it. So just get the list example (can be found at the end of this guide) and adjust SSIDs and passwords to your scenarioThe list is not limited to 7 entrys, it is possible to insert an arbitary number of SSIDs to the file.
  
 {{:app-notes:networks.png}} {{:app-notes:networks.png}}
  
-Nach erfolgreichem Einrichten solle unser Scripts Tab nun so aussehen.+After succesfull setup your Scripts Tab should look like this.
  
 {{:app-notes:two-scripts.png}} {{:app-notes:two-scripts.png}}
Line 50: Line 59:
  
 ==== wifi-switcher.are ==== ==== wifi-switcher.are ====
-Hier eine kurze Erklärung wie das Script funktioniert.+Here is a short description of the funtionality of the script.
  
-Zunächst+You have the option to set DEBUG=1, this will give you some debug output visible in tail-log. 
 + 
 +First the scirpt will import the list of access points it is supposed to connect to. Then the scirpt will keep on looking up the state of the WiFi (WLAN1 which is setup as WANLINK2). 
 + 
 +In case of the state being "dialing" or "up" we do nothing and wait for 5 seconds before we check this status again. In caste the state is "down" and the last scan is at least 30 seconds in the past we trigger a new scan of the currently available Wifi networkss.  
 + 
 +After the scan is finished we take the data and compare it to the list we imported earlier. When a known access point is found and the last WiFi config update is at least 120 seconds in the past, we update the wifi config so we can connect to the now available WiFi AP.
  
 <code c wifi-switcher.are> <code c wifi-switcher.are>
Line 134: Line 149:
 </code> </code>
  
-<code c wifi-networks.are>+==== wifi-networks.are ==== 
 + 
 +<code c wifi-networks.cfg>
 wifi_list=mkarray( wifi_list=mkarray(
     mkarray("SSID1", "wifipassword1"),     mkarray("SSID1", "wifipassword1"),