netGetWLANParam (Functionblock)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

1.00.00


netGetWLANParam will read out the parameters for a wireless network previously set from the RTCU M2M Studio or by the netSetWLANParam function.

 

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.

 

 

Output:

SSID : STRING

The SSID of the wireless network.

 

security : INT

The type of security used by the wireless network. Use the netGetWLANSecurity function to get the security configuration.

0

None

None

1

WPA/WPA2 PSK

netWLANSecurityWPA

 

DHCP : BOOL

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 uses.

 

AutoDNS : BOOL

Obtain the DNS parameters automatically.

 

DNS1 : DINT

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

 

DNS2 : DINT

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

 

 

Declaration:

FUNCTION_BLOCK netGetWLANParam;
VAR_INPUT
   index          : INT;
END_VAR;
VAR_OUTPUT
   DHCP           : BOOL;
   IP             : DINT;
   SubnetMask     : DINT;
   Gateway        : DINT;
   AutoDNS        : BOOL;
   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;