netSetAPParam (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900, LX5

Firmware version:

1.50.00


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

 

The AP 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:

SSID : STRING

The SSID of the wireless network.

 

Country : STRING

The country code where the device operates.

The ISO 3166-1 standard is used for the country code, as f.ex. 'DK' for Denmark.

 

Hidden : BOOL

Control whether the SSID will be broadcast.

 

Chnl : SINT (1..14)

The channel to use.

Please note:

That not all 14 channels is available in every country. Channel 1 to 11 is always available, but it should be checked if channel 12, 13 or 14 is available.

That if both the WLAN and AP network interfaces are open, then the channel can be changed when a connection to a WLAN network is established.

 

Sec_config : PTR

The security configuration for the wireless network (passwords must be of at least 8 characters length).

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

 

Address : DINT

The IP address of the device.

 

Subnet : DINT

The Subnet mask of the device.

 

 

Returns: INT

0

- Success.

2

- Illegal SSID

3

- Unknown security configuration

4

- Illegal security configuration

6

- Illegal parameter.

 

 

Declaration:

FUNCTION netSetAPParam : INT;
VAR_INPUT
  SSID           : STRING;

  Country        : MANDATORY STRING;
  Hidden         : BOOL;
  Chnl           : SINT;
  Sec_config     : PTR;
  Address        : DINT;
  Subnet         : DINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  wpa_psk  : netWLANSecurityWPA;
  net      : netGetAPParam;
END_VAR;
 
FUNCTION ap_set;
VAR
  rc       : INT;
END_VAR;
 
  // Setup security
  wpa_psk.phrase  := "passphrase";
 
  // Setup WLAN network
  rc := netSetAPParam(
                      ssid        := "SSID"
                      ,hidden     := FALSE
                      ,chnl       := 1
                      ,sec_config := ADDR(wpa_psk)
                      ,Address    := sockIPFromName(str := "192.168.1.1")
                      ,Subnet     := sockIPFromName(str := "255.255.255.0")
                     );
  DebugFmt(message := "netSetAPParam=    \1", v1 := rc);
END_FUNCTION;
 
FUNCTION ap_show;
  net();
  DebugMsg(message := " SSID=         " + net.ssid);
  IF net.security = 0 THEN
    DebugMsg(message := " Security=     None");
  ELSIF net.security = 1 THEN
    DebugFmt(message := " Security=     WPA/WPA2 PSK");
    netGetAPSecurity(sec_config := ADDR(wpa_psk));
    DebugMsg(message := "   phrase=         " + wpa_psk.phrase);
  ELSE
    DebugFmt(message := " Security=     Unknown (\1)", v1 := net.security);
  END_IF;
  DebugMsg(message := " Network=      IPv4");
  DebugMsg(message := "   Address=        " + sockIPToName(ip := net.Address));
  DebugMsg(message := "   Subnet=         " + sockIPToName(ip := net.Subnet));
END_FUNCTION;
 
PROGRAM example;
 
ap_set();
ap_show();
 
BEGIN
// ...
END;
END_PROGRAM;