netSetWLANParam (Function)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

1.00.00


Sets the parameters for establishing connections to a wireless network with the WLAN network interface. It has the same effect as setting the parameters via Device: Network: Network Settings.

In cases where multiple wireless networks are present, the network with the lowest index is connected to.

 

The WLAN network interface must be closed and opened again before the changes can take effect if already opened (see also netClose / netOpen).

The format of an IP address is the same as returned by the sockGetLocalIP function.

 

 

Input:

index : INT (1..10)

The index of the wireless network.

 

SSID : STRING

The SSID of the wireless network.

 

sec_config : PTR

The security configuration for the wireless network.

The security is configured by way of a pointer to a struct block which contains the parameters.

0

No security

None

1

WPA/WPA2 PSK

netWLANSecurityWPA

 

DHCP : BOOL (default TRUE)

Use DHCP to obtain TCP/IP parameters automatically.

 

IP : DINT

The IP address of the device.

 

SubnetMask : DINT

The Subnet mask of the device.

 

Gateway : DINT

The TCP/IP gateway the device must use.

 

AutoDNS : BOOL (default TRUE)

Obtain the DNS parameters automatically. Can only be used in combination with DHCP.

 

DNS1 : DINT

The first Domain Name Server the device should use to look up symbolic names.

 

DNS2 : DINT

The second Domain Name Server the device should use to look up symbolic names.

 

 

Returns: INT

0

- Success.

1

- Illegal wireless network index

2

- Illegal SSID

3

- Unknown security configuration

4

- Illegal security configuration

5

- AutoDNS enabled without DHCP.

 

 

Declaration:

FUNCTION netSetWLANParam : INT;
VAR_INPUT
   index          : INT;
   ssid           : STRING;
   sec_config     : PTR;
   DHCP           : BOOL := TRUE;
   IP             : DINT;
   SubnetMask     : DINT;
   Gateway        : DINT;
   AutoDNS        : BOOL := TRUE;
   DNS1           : DINT;
   DNS2           : DINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
   wpa_psk  : netWLANSecurityWPA;
   wlan     : netGetWLANParam;
END_VAR;
 
FUNCTION booltostr : STRING;
VAR_INPUT
   v : BOOL;
END_VAR;
IF v THEN booltostr := "Yes"; ELSE booltostr := "No"; END_IF;
END_FUNCTION;
 
FUNCTION wlan_set;
VAR
   rc       : INT;
END_VAR;
 
   // Setup security
   wpa_psk.phrase  := "passphrase";
 
   // Setup WLAN network
   rc := netSetWLANParam(
                         index       := 1
                         ,ssid       := "SSID"
                         ,sec_config := ADDR(wpa_psk)
                         ,DHCP       := ON
                         ,AutoDNS    := ON
                        );
   DebugFmt(message := "netSetWLANParam=    \1", v1 := rc);
END_FUNCTION;
 
FUNCTION wlan_show;
VAR_INPUT
   index : INT := 1;
END_VAR;
 
   wlan(index := index);
   DebugMsg(message := " SSID=         " + wlan.ssid);
   IF wlan.security = 0 THEN
      DebugMsg(message := " Security=     None");
   ELSIF wlan.security = 1 THEN
      DebugFmt(message := " Security=     WPA/WPA2 PSK");
      netGetWLANSecurity(index := index, sec_config := ADDR(wpa_psk));
      DebugMsg(message := "   phrase=         " + wpa_psk.phrase);
   ELSE
      DebugFmt(message := " Security=     Unknown (\1)", v1 := wlan.security);
   END_IF;
   DebugMsg(message := " Network=      IPv4");
   DebugMsg(message := "   IP=             " + sockIPToName(ip := wlan.ip));
   DebugMsg(message := "   Subnet=         " + sockIPToName(ip := wlan.SubnetMask));
   DebugMsg(message := "   Gw=             " + sockIPToName(ip := wlan.Gateway));
   DebugMsg(message := "   DHCP=           " + booltostr(v := wlan.dhcp));
   DebugMsg(message := "   Auto DNS=       " + booltostr(v := wlan.AutoDNS));
   DebugMsg(message := "   DNS=            " + sockIPToName(ip := wlan.DNS1));
   DebugMsg(message := "   DNS=            " + sockIPToName(ip := wlan.DNS2));
END_FUNCTION;
 
PROGRAM test;
 
wlan_set();
wlan_show(index := 1);
 
BEGIN
  // ...
END;
END_PROGRAM;