sockSetGWParm (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


Sets the RTCU Communication Hub specific parameters.

This has the same effect as setting the parameters via Device: Network: RTCU Communication Hub settings.

The changes will take effect at the next call to gwOpen or at device reset. (e.g. by using boardReset).

On NX32L architecture devices this will set the fallback configuration, see also rchFallbackSet.

 

Input:        

GWEnabled : BOOL

Determines whether the RTCU Communication Hub will start automatically.

(See Autostart feature)

 

GWIP : STRING (Max 41 characters)

The IP address or symbolic name of the RTCU Communication Hub.

 

GWPort : DINT (default 5001)

The IP port the device should use to connect to the RTCU Communication Hub.

 

GWKey : STRING  (Max 8 characters)

The key (password) the device should use to connect to the RTCU Communication Hub.

 

MaxConnectionAttempt : INT (default 3)

Max number of connection attempts before the network media reconnects.

 

MaxSendReqAttempt : INT (default 5)

Max number of send-request attempt before send fails.

 

ResponseTimeout : INT (default 45)

Time waiting for response in seconds.

 

AliveFreq : DINT (default 300)

Frequency for sending self-transactions in seconds.

The purpose of the self-transaction is to ensure a healthy two-way communication channel over the RTCU Communication Hub.

For applications that are only sending data from the device to the server, this frequency can safely be increased.

Setting the value to zero will disable the self-transactions completely.

 

CryptKey : PTR

The key used to encrypt communication with the  RTCU Communication Hub.

If this parameter is not set (CryptKey set to 0), then the encryption key is not changed.

 

 

Returns:INT

0

- Success.

1

- String too long.

 

 

Declaration:

FUNCTION sockSetGWParm;
VAR_INPUT
  //RTCU Hub parameters:
  GWEnabled            : BOOL;         // false=disabled, true=enable RCH
  GWIP                 : STRING;       // RCHaddress (dotted / symbolic) (max 41 chars)
  GWPort               : DINT := 5001; // RCH port (def: 5001)
  GWKey                : STRING;       // RCH key, 8 characters
 
  //advanced settings (modification not recommended):
  MaxConnectionAttempt : INT := 3;     // Max number of connection attempts before the network media re-connects.
                                       // Interval: 1..60. (default: 3)
  MaxSendReqAttempt    : INT := 5;     // Max number of send-request attempt before send fails.
                                       // Interval: 1..60 (default: 5)
  ResponseTimeout      : INT := 45;    // Time waiting for response in seconds
                                       // Interval: 5..60 (def: 45 seconds).
  AliveFreq            : DINT := 300;  // Frequency for sending self-transactions in seconds
                                       // Interval: 0..60000 (def: 300 seconds).
                                       // 0 (zero) will disable self-trans.
  CryptKey             : PTR;          // Pointer to array containing 16 SINT.
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  gprsParm  : sockGetTCPIPParm;
  gwParm    : sockGetGWParm;
  parmReset : BOOL := FALSE;
  CryptKey  : ARRAY[1..16] OF SINT;
END_VAR;
 
// Check mobile network and hub settings
gprsParm();
gwParm();
IF gprsParm.IP <> 0 OR gprsParm.SubnetMask <> 0 OR gprsParm.Gateway <> 0 OR
  gprsParm.DNS1 <> 0 OR gprsParm.DNS2 <> 0 OR gprsParm.Authenticate <> 0 OR
  strCompare(str1 := gprsParm.Username, str2 := "") <> 0 OR
  strCompare(str1 := gprsParm.Password, str2 := "") <> 0 OR
  strCompare(str1 := gprsParm.APN, str2 := "internet") <> 0 THEN
  // Set APN and keep the default values for the others
  sockSetTCPIPParm(APN := "internet");
  parmReset := TRUE;
END_IF;
IF NOT gwParm.GWEnabled OR gwParm.GWPort <> 5001 OR gwParm.CryptKey[1] <> 0 OR
  gwParm.CryptKey[2] <> 0 OR gwParm.CryptKey[3] <> 0 OR gwParm.CryptKey[4] <> 0 OR
  gwParm.CryptKey[5] <> 0 OR gwParm.CryptKey[6] <> 0 OR gwParm.CryptKey[7] <> 0 OR
  gwParm.CryptKey[8] <> 0 OR gwParm.CryptKey[9] <> 0 OR gwParm.CryptKey[10] <> 0 OR
  gwParm.CryptKey[11] <> 0 OR gwParm.CryptKey[12] <> 0 OR gwParm.CryptKey[13] <> 0 OR
  gwParm.CryptKey[14] <> 0 OR gwParm.CryptKey[15] <> 0 OR gwParm.CryptKey[16] <> 0 OR
  strCompare(str1 := gwParm.GWIP, str2 := "gw.rtcu.dk") <> 0 OR
  strCompare(str1 := gwParm.GWKey, str2 := "AABBCCDD") <> 0 THEN
  // Clear encryption key
  CryptKey[1] := 0;
  CryptKey[2] := 0;
  CryptKey[3] := 0;
  CryptKey[4] := 0;
  CryptKey[5] := 0;
  CryptKey[6] := 0;
  CryptKey[7] := 0;
  CryptKey[8] := 0;
  CryptKey[9] := 0;
  CryptKey[10] := 0;
  CryptKey[11] := 0;
  CryptKey[12] := 0;
  CryptKey[13] := 0;
  CryptKey[14] := 0;
  CryptKey[15] := 0;
  CryptKey[16] := 0;
  // Set hub parameters
  sockSetGWParm(GWEnabled := TRUE, GWIP := "gw.rtcu.dk", GWPort := 5001, GWKey := "AABBCCDD", CryptKey := ADDR(CryptKey));
  parmReset := TRUE;
END_IF;
IF parmReset THEN
  // Reset device before the changes are used
  boardReset();
END_IF;
 
gsmPower(power := TRUE);
gprsOpen();
 
BEGIN
  ...
END;
END_PROGRAM;