Nach jedem Neustart schlägt mein Sensordienst mit fehlendem /dev/i2c-1 fehl
Von English mit KI übersetzt ·
Facility Manager in einem Hotel. Ich habe einen Pi 4 mit einem BME280 im Technikraum unseres Betriebs eingerichtet. Ein Python-Skript liest ihn aus und veröffentlicht die Daten an Hermetry, als systemd-Dienst. Es funktioniert bis der Pi neu startet, dann bricht der Dienst mit folgendem Fehler ab:
FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'
sensor.service: Main process exited, code=exited, status=1/FAILURE
Wenn ich mich per SSH einlogge, sudo modprobe i2c-dev ausführe und danach den Dienst neu starte, funktioniert es bis zum nächsten Neustart. Wir hatten am Sonntag einen Stromausfall, und niemand hat es einen Tag lang bemerkt, weil die Platine nur alte Werte anzeigte.
Facility manager at a hotel, I set up a Pi 4 with a BME280 in our plant room. A Python script reads it and publishes to Hermetry, running as a systemd service. It works until the Pi reboots, then the service dies with:
FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'
sensor.service: Main process exited, code=exited, status=1/FAILURE
If I SSH in and run sudo modprobe i2c-dev then restart the service, it works until the next reboot. We had a power cut on Sunday and nobody noticed for a day because the board just showed old values.
Von English mit KI übersetzt ·
Hast du I2C in raspi-config aktiviert? Dann sollte es beim Booten geladen werden.
Did you enable I2C in raspi-config? That should load it at boot.
Von English mit KI übersetzt ·
Habe ich, und zur Sicherheit habe ich außerdem selbst dtparam=i2c_arm=on in /boot/config.txt eingetragen.
I did, and I also added dtparam=i2c_arm=on to /boot/config.txt myself to be sure.
Von English mit KI übersetzt ·
Vielleicht time.sleep(30) an den Anfang des Skripts setzen, damit das Modul Zeit zum Laden hat?
maybe put time.sleep(30) at the start of the script so the module has time to load?
Von English mit KI übersetzt ·
Welche OS-Version? Wenn es Bookworm ist, liegt dort der Fehler: Die Datei heißt jetzt /boot/firmware/config.txt, und /boot/config.txt wird nicht mehr gelesen (darin steht ein Hinweis dazu). Deine Zeile steht in einer Datei, die niemand liest, und raspi-config wurde möglicherweise durch etwas anderes, das du später geändert hast, rückgängig gemacht.Was ich tun würde:
# /boot/firmware/config.txt
dtparam=i2c_arm=on
# load the char device at boot
echo i2c-dev | sudo tee /etc/modules-load.d/i2c.conf
Und damit der Dienst einen langsamen Start übersteht, statt einmal abzubrechen:
[Service]
Restart=on-failure
RestartSec=10
Rahul, ein Sleep würde an den meisten Tagen funktionieren, aber Restart= deckt dies und jedes andere Startup-Race ab.Zu den alten Werten nach dem Stromausfall: Füge dem Profil des Sensors einen Offline-Alarm hinzu. Dann liefert ein toter Pi dir einen Alarm statt eines Diagramms, das normal aussieht.
Which OS release? If it’s Bookworm, that’s your bug: the file is /boot/firmware/config.txt now, and /boot/config.txt is not read anymore (there’s a note in it saying so). Your line is in a file nobody reads, and raspi-config may have been undone by something else you changed later.
What I’d do:
# /boot/firmware/config.txt
dtparam=i2c_arm=on
# load the char device at boot
echo i2c-dev | sudo tee /etc/modules-load.d/i2c.conf
And make the service survive a slow start instead of dying once:
[Service]
Restart=on-failure
RestartSec=10
Rahul, a sleep would work most days, but Restart= covers this and any other startup race.
About the old values after the power cut: add an offline alarm on the sensor’s profile. Then a dead Pi gets you an alarm instead of a chart that looks normal.
Von English mit KI übersetzt ·
Warum schreibt raspi-config nicht einfach beide Dateien? Das scheint eine einfache Falle zu sein.
Why does raspi-config not just write both files? Seems like an easy trap.
Von English mit KI übersetzt ·
Megan, genau richtig. Bookworm, und meine Zeile stand in der alten /boot/config.txt, oben steht ein Kommentar, dass sie verschoben wurde, den hatte ich nie bemerkt. Die richtige Datei korrigiert, die modules-load-Zeile und Restart=on-failure hinzugefügt, zweimal den Stecker gezogen, beide Male lief es einwandfrei hoch. Der Offline-Alarm ist auch eingerichtet.
Megan, spot on. Bookworm, and my line was in the old /boot/config.txt, which has a comment at the top saying it moved, never saw it. Fixed the right file, added the modules-load line and Restart=on-failure, pulled the plug twice, came up fine both times. Offline alarm is set too.
Von English mit KI übersetzt ·
Marcus, raspi-config schreibt den richtigen Eintrag. Emilys eigene manuelle Änderung war die, die an der falschen Stelle steht.
Marcus, raspi-config does write the right one. Emily’s own manual edit was the one in the wrong place.
- Du musst angemeldet sein, um auf dieses Thema antworten zu können.
Mitdiskutieren
Melde dich an, um Fragen zu stellen und zu beantworten, hilfreiche Beiträge mit „Gefällt mir“ zu markieren und die Antwort zu kennzeichnen, die dein Problem gelöst hat. Jeder Beitrag bringt Punkte und Stufen.

