Network identity and timezone (NITZ) functionality

I would like in my application to find a way to synch the date and time using NITZ functionality.
So, I did these following steps:

  1. I have disabled NTP : /etc/config/system
  2. I have activated NITZ using this AT commande : AT+CTZU=1
  3. I deliberately took a bad hour: AT+CCLK="21/03/10,08:00:00-04"
  4. After the board reboot, I noticed that AT+CCLK? return a correct time
  5. I tested the busybox date command, it return's a wrong value

From my understanding, when we activate NITZ, the time is automatically updated every GSM / GPRS event (network registration, call / data communication, SMS, ...)

Is there something that I missed ?

Yes, you are correct about NITZ. The modem will get time from the cellular network in every event.
I don´t think there is any function in OpenWrt to get the time from the modem.
But, you can use a script. Maybe not the most optimized script. :slight_smile:

#!/bin/sh
#
# Device on your modem
DEV=/dev/ttyUSB0

NITZtime=$(COMMAND="AT+CCLK?" gcom -d "$DEV" -s /etc/gcom/getruncommand.gcom | awk 'NR==2' | awk '{print $2}')
RouterEpoch=$(date '+%s')
#Convert NITZ format 21/03/13,16:26:41+04,0 to 2021-03-13 16:26:41
NITZ_y="20${NITZtime:0:2}"
NITZ_m="${NITZtime:3:2}"
NITZ_d="${NITZtime:6:2}"
NITZ_time="${NITZtime:9:8}"
NITZ_tz="${NITZtime:17:1}"
NITZ_TZq="${NITZtime:18:2}"
NITZ_TZs=$(($NITZ_TZq*15*60))
NITZdate="date -d '"$NITZ_y"-"$NITZ_m"-"$NITZ_d" "$NITZ_time"' '+%s'"
NITZepoch=$(eval $NITZdate)

#Adjust for time zone
if [ $NITZ_tz == '+' ]
then
        NITZepoch=$(($NITZepoch+$NITZ_TZs))
elif [ $NITZ_tz == '-' ]
then
        NITZepoch=$(($NITZepoch-$NITZ_TZs))
fi

timeDiff=$(($RouterEpoch-$NITZepoch))

# Set new time if differnce > 1sec
if [ ${timeDiff#-} -gt 1 ]
then
        newTime=$(date -d '@'$NITZepoch '+%Y-%m-%d %T')
        logger -t NITZ 'New time: '$newTime
        newDate="date -s '"$newTime"'"
        eval $newDate 1>/dev/null
fi

You need to install comgt-ncm and add script getruncommand.gcom to /etc/gcom/

getruncommand.gcom

# run AT-command from environment
opengt
 set com 115200n81
 set senddelay 0.02
 waitquiet 1 0.2
 flash 0.1

:start
 send $env("COMMAND")
 send "^m"
 get 1 "" $s
 print $s

:continue
 exit 0
1 Like

Thank you! This is what I am looking for! it should help me solve my problem !

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.