Tras cada reinicio, mi servicio del sensor falla: no existe /dev/i2c-1
Traducido del English por IA ·
Soy responsable de instalaciones de un hotel. Monté una Pi 4 con un BME280 en nuestra sala de máquinas. Un script de Python lee el sensor y publica los datos en Hermetry, ejecutándose como servicio de systemd. Funciona hasta que la Pi se reinicia; entonces el servicio se cae con este error:
FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'
sensor.service: Main process exited, code=exited, status=1/FAILURE
Si me conecto por SSH, ejecuto sudo modprobe i2c-dev y luego reinicio el servicio, funciona hasta el siguiente reinicio. Tuvimos un corte de luz el domingo y nadie se dio cuenta durante un día, porque la placa solo mostraba valores antiguos.
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.
Traducido del English por IA ·
¿Habilitaste I2C en raspi-config? Eso debería cargarlo al arrancar.
Did you enable I2C in raspi-config? That should load it at boot.
Traducido del English por IA ·
Sí, y también añadí yo mismo dtparam=i2c_arm=on en /boot/config.txt para estar seguro.
I did, and I also added dtparam=i2c_arm=on to /boot/config.txt myself to be sure.
Traducido del English por IA ·
¿Quizás poner time.sleep(30) al inicio del script para que el módulo tenga tiempo de cargarse?
maybe put time.sleep(30) at the start of the script so the module has time to load?
Traducido del English por IA ·
¿Qué versión del SO? Si es Bookworm, ese es tu error: ahora el archivo es /boot/firmware/config.txt, y /boot/config.txt ya no se lee (hay una nota en él que lo indica). Tu línea está en un archivo que nadie lee, y es posible que raspi-config haya sido revertido por algo más que cambiaste después.Lo que haría:
# /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
Y haz que el servicio sobreviva a un arranque lento en lugar de fallar una sola vez:
[Service]
Restart=on-failure
RestartSec=10
Rahul, un sleep funcionaría la mayoría de los días, pero Restart= cubre esto y cualquier otra condición de carrera en el arranque.Sobre los valores antiguos tras el corte de energía: añade una alarma de desconexión en el perfil del sensor. Así, una Pi muerta te dará una alarma en lugar de un gráfico que parece normal.
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.
Traducido del English por IA ·
¿Por qué raspi-config no escribe simplemente los dos archivos? Parece una trampa fácil.
Why does raspi-config not just write both files? Seems like an easy trap.
Traducido del English por IA ·
Megan, exacto. Bookworm, y mi línea estaba en el antiguo /boot/config.txt, que tiene un comentario al principio indicando que se había movido; nunca lo vi. Corregí el archivo correcto, añadí la línea modules-load y Restart=on-failure, desconecté la corriente dos veces y arrancó bien ambas veces. La alarma de desconexión también está configurada.
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.
Traducido del English por IA ·
Marcus, raspi-config sí escribe el valor correcto. La edición manual que hizo Emily fue la que quedó en el lugar equivocado.
Marcus, raspi-config does write the right one. Emily’s own manual edit was the one in the wrong place.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

