This shows you the differences between two versions of the page.
| — | sdk:wifimodechanger [2018/04/09 14:39] (current) – created juraschek | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | <code c wifimodechanger.are> | ||
| + | ### Change Wifi mode if AP is available | ||
| + | |||
| + | ## Variable that hold the configs for both WLAN Modes | ||
| + | ClientConfig=""; | ||
| + | ApConfig=""; | ||
| + | nextWlanMode=" | ||
| + | |||
| + | |||
| + | IFC = " | ||
| + | homeNetwork = " | ||
| + | MIN_SIGNAL = -110; | ||
| + | |||
| + | |||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | ApConfig=sprintf(" | ||
| + | |||
| + | |||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | ClientConfig=sprintf(" | ||
| + | |||
| + | |||
| + | |||
| + | currentWlanMode=nb_config_get(" | ||
| + | |||
| + | |||
| + | |||
| + | /* ATTENTION: Scanning for WLAN networks will tear down any running access-point */ | ||
| + | nets = nb_scan_networks(IFC); | ||
| + | nr_nets = struct_get(nets, | ||
| + | |||
| + | if (is_void(nr_nets) || nr_nets < 1) { | ||
| + | nb_syslog(" | ||
| + | exit(0); | ||
| + | } | ||
| + | |||
| + | /* lookup WLAN networks */ | ||
| + | for (i = 1; i <= nr_nets; i++) { | ||
| + | k = sprintf(" | ||
| + | ssid = struct_get(nets, | ||
| + | k = sprintf(" | ||
| + | signal = (int)struct_get(nets, | ||
| + | |||
| + | if (strlen(ssid) == 0) continue; | ||
| + | |||
| + | nb_syslog(" | ||
| + | |||
| + | if ((ssid == homeNetwork) && signal > MIN_SIGNAL) { | ||
| + | nextWlanMode=" | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | if (nextWlanMode == " | ||
| + | nb_syslog(" | ||
| + | nb_config_set(ClientConfig); | ||
| + | } | ||
| + | |||
| + | if (nextWlanMode == " | ||
| + | nb_syslog(" | ||
| + | nb_config_set(ApConfig); | ||
| + | } | ||
| + | |||
| + | exit(0); | ||
| + | |||
| + | |||
| + | |||
| + | </ | ||