turtlebot / turtlebot4

Turtlebot4 common packages.
Apache License 2.0
102 stars 45 forks source link

NTP sync warning #10

Closed alexswerner closed 2 years ago

alexswerner commented 2 years ago

On our campus network, outgoing NTP is blocked. Ubuntu by default rejects any ntp server supplied through DHCP. This results in no time synchronization on the raspberry pi as it has no RTC with battery backup. ROS suffers from this issue as does apt.

This can be fixed by using the DHCP-provided NTP server by adding a dispatch script to NetworkManager:

# cat /etc/NetworkManager/dispatcher.d/10-update-timesyncd 
#!/bin/sh
set -v
echo args: $@

[ -z "$CONNECTION_UUID" ] && exit 0
INTERFACE="$1"
ACTION="$2"

case $ACTION in
up | dhcp4-change | dhcp6-change)
    [ -n "$DHCP4_NTP_SERVERS" ] || exit
    mkdir -p /etc/systemd/timesyncd.conf.d
    cat <<-THE_END >"/etc/systemd/timesyncd.conf.d/${CONNECTION_UUID}.conf"
        [Time]
        NTP=$DHCP4_NTP_SERVERS
    THE_END
    systemctl restart systemd-timesyncd.service
    ;;
down)
    rm -f "/etc/systemd/timesyncd.conf.d/${CONNECTION_UUID}.conf"
    systemctl restart systemd-timesyncd.service
    ;;
esac

This file needs to be made executable. The file is taken from somewhere else.

alexswerner commented 2 years ago

This probably needs some further investigation, especially if the fix works (it is for systemd-timesyncd and turtlebot4 uses chrony). In our case, we finally resolved the issue with unblocking ntp traffic in the firewall. I suggest that the manual should state that this robot needs a time server to work, that public timeservers are pre-configured and that dhcp supplied ntp servers are ignored.

roni-kreinin commented 2 years ago

Thanks, I'll add a note to the manual.

teufelweich commented 1 year ago

Thanks, I'll add a note to the manual.

I've searched for NTP inside the manual and didn't find any note.

teufelweich commented 1 year ago

Since my WiFi setup usually doesn't allow internet connection I used my laptop as the NTP server (through chrony). I've added the following lines to the configs.

on my laptop 192.168.0.10 (server): /etc/chrony/chrony.conf

# Allow TurtleBots to use this chrony instance as their NTP server
allow 192.168.0.0/24

on the Pi/Turtlebot (client): /etc/chrony/chrony.conf

# Laptop as source
server 192.168.0.10 iburst

The Create3 then syncs it's time from the Turtlebot Pi.

teufelweich commented 1 year ago

@roni-kreinin why does contain /etc/chrony/chrony.conf the following line?

server 192.168.186.2 presend 0 minpoll 0 maxpoll 0 iburst  prefer trust

should the Pi really use the Create 3 as prefered trusted source? This conflicts with the Pi being the source for the Create3.