Update PP modem time from internet

My provider (bob in Austria) does not provide time via the mobile network. Consequently, the Pinephone modem does not have current time which can lead to problems using AGPS and also with SMS.

The Pinephone has two clocks, the baseband time and the modem userspace time. The modem userspace time can be set with the date command (via adb). However, the newest open source firmware from biktorgj will use the baseband time if that is available. So it suffices to set the baseband (CCLK) time.

We do this via a systemd timer unit, as there is no crontab on mobian,

  1. enable time-sync target so we only start syncing the modem once we have internet time
sudo systemctl enable systemd-time-wait-sync

2. create files

sudo vi /etc/systemd/system/setmodemtime.service

[Unit]
Description=Set Modem Time from Internet Time
[Service]
Type=oneshot
ExecStart=/bin/bash /home/mobian/scripts/setmodemtime.sh

sudo vi /etc/systemd/system/setmodemtime.timer

[Unit]
Description=Timer for setting Modem time from internet time
After=time-sync.target

[Timer]
OnUnitActiveSec=30m
OnBootSec=10s

[Install]
WantedBy=timers.target

vi /home/mobian/scripts/setmodemtime.sh

#! /bin/sh
set -x

if  [ "$(id -u)" -ne 0 ]; then
  echo "Please run as root"
  exit
fi

# Set timezone offset, for me thats UTC/GMT+1
# CCLK wants the timezone offset in two-digits of quarterhours, so GMT+1 is "+04"
offset="+04"
# set modem baseband time via AT command
mmcli -m any --command=$(echo AT+CCLK=\"`date -u +%y/%m/%d,%H:%M:%S$offset`\")

chmod +x /home/mobian/scripts/setmodemtime.sh

3. Allow ModemManager to send AT commands

Nowadays ModemManager is running in a restricted mode which bars it from sending AT commands to the modem. We need to enable AT commands by setting it into „debug mode“

sudo vi /usr/lib/systemd/system/ModemManager.service.d/mobile-tweaks.conf
Add --debug to the ExecStart Command
sudo systemctl daemon-reload
sudo service ModemManager restart

4. enable timer

sudo systemctl enable setmodemtime.timer

5. check that it works

systemctl list-timers --all
sudo systemctl status setmodemtime.service
sudo mmcli -m any --command='AT+CCLK?'