gsmNetworkTime (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

3.10 / 1.00.00 (5.04/1.40.00 for the UTC parameter)


This function requests the current time expressed as seconds since 1980-1-1 00:00:00 (LINSEC), from the cellular network.
 

Note:
Not all networks offer a time-service. The time information is transmitted with a variable frequency by the network.

 

 

Input:                

UTC : BOOL (default: FALSE)

Specifies whether the local-time or UTC time should be returned.
Not all devices supports UTC time and will therefore return the local time in all cases.
 
 

Returns: DINT

The current time as seconds since 1980-1-1 00:00:00 (LINSEC).

0

- Updated network time is currently not available.

-1

- Network time not supported by device.

-2

- Not connected to the network.

-3

- General error.

 

Declaration:

FUNCTION gsmNetworkTime : INT;
VAR_INPUT
  UTC : BOOL;
END_VAR;

 

 

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  update : BOOL;
END_VAR;
 
PROGRAM test;
VAR
  upd_old : BOOL;
  time   : DINT;
END_VAR;
 
  // Initialize
  gsmPower(power:=ON);
  DebugMsg(message:="Program running");
 
BEGIN
  ...
  // Update device clock
  IF update AND NOT upd_old THEN
    // Get time
     time := gsmNetworkTime();
    // Set current time
    IF time > 0 THEN
        clockSet(linsec := time);
    END_IF;
  END_IF;
  upd_old := update;
END;
END_PROGRAM;