Traduit de English par IA ·
Voilà, c’est donc ça. Un Pi 3 n’a pas d’horloge temps réel. Au démarrage, il restaure l’heure enregistrée lors de l’extinction propre précédente (fake-hwclock), puis attend NTP. Votre réseau de laboratoire bloque NTP (UDP 123), donc l’horloge reste dans le passé et, pour la bibliothèque TLS, le certificat du serveur n’est pas encore valide. J’ai vu cela sur la moitié des Pi déployés que j’ai mis en service derrière des pare-feu verrouillés.Solutions, à choisir :
# 1. demander à l'informatique le serveur NTP interne et l'utiliser
sudo nano /etc/systemd/timesyncd.conf
[Time]
NTP=ntp.your-lab.example
sudo systemctl restart systemd-timesyncd
timedatectl # "System clock synchronized: yes"
# 2. si seul le port 443 est ouvert : synchroniser via les en-têtes HTTPS
sudo apt install htpdate
sudo htpdate -s https://www.example.org
Supprimez l’IP codée en dur. Le broker nécessite SNI, il faut donc se connecter par nom d’hôte ; le certificat est de toute façon vérifié par rapport à ce nom, ce qui explique la non-correspondance. Un simple client.tls_set() avec le bundle de CA du système convient ; Tyler, aucun certificat client n’est nécessaire pour les connexions par jeton, le serveur en demande un mais ne l’exige pas.Faites aussi attendre au script une horloge synchronisée avant de se connecter, sinon un redémarrage au laboratoire le fera à nouveau échouer. Une boucle simple sur timedatectl show -p NTPSynchronized fonctionne. Voir la section TLS de MQTT.
That’s it then. A Pi 3 has no real time clock. At boot it restores the time it saved at the last clean shutdown (fake-hwclock) and then waits for NTP. Your lab network blocks NTP (UDP 123), so the clock stays in the past, and to the TLS library the server certificate isn’t valid yet. Seen this on half the field Pis I’ve commissioned behind locked-down firewalls.
Fixes, pick one:
# 1. ask IT for the internal NTP server and use it
sudo nano /etc/systemd/timesyncd.conf
[Time]
NTP=ntp.your-lab.example
sudo systemctl restart systemd-timesyncd
timedatectl # "System clock synchronized: yes"
# 2. if only 443 is open: sync from HTTPS headers
sudo apt install htpdate
sudo htpdate -s https://www.example.org
Undo the hardcoded IP. The broker needs SNI, so connect by host name, and the certificate is checked against that name anyway, which is why you got the mismatch. Plain client.tls_set() with the system CA bundle is fine; Tyler, no client certificate is needed for token logins, the server asks for one but doesn’t require it.
Also make the script wait for a synced clock before connecting, otherwise a reboot in the lab breaks it again. A quick loop on timedatectl show -p NTPSynchronized works. See the TLS section of MQTT.

