Ausgelagert aus RPI3 - Crontab soll Shell-Skript aufrufen
Hallo liebe Raspi Freunde!
Mein Problem ist zwar etwas anders als das von ukognos55, zielt aber in die gleiche Richtung (das gleiche Thema):
Ich habe einen Raspi 3B, an dem ich einen BME280 via I2C als Temperaur-, Luftdruck- und Luftfeuchtesensor angeschlossen habe.
Für diesen Sensor habe ich folgendes Programm geschrieben.
#!/usr/bin/python3
import smbus
import bme280
import time
import math
import mod_DB_Insert as DBaction
# ---------- Konstanten deklarieren ----------
tpk1 = 241.2
tpk2 = 4222.03716
tpk3 = 17.5043
# ---------- Variablen initialisieren --------
Datum = time.strftime("%Y-%m-%d")
Uhrzeit = time.strftime("%H:%M")
# ---------- I2C-Bus konfigurieren ----------
port = 1
address = 0x76
bus = smbus.SMBus(port)
# Einlesen der Daten
t, p, h = bme280.readBME280All()
# Berechnung des Taupunktes (dewpoint)
d = (tpk1*math.log(h/100)+((tpk2*t)/(tpk1+t)))/(tpk3-math.log(h/100)-((tpk3*t)/(tpk1+t)))
temp = '{:2.1f}'.format(t)
pres = '{:4.1f}'.format(p)
humi = '{:3.1f}'.format(h)
dewp = '{:2.1f}'.format(d)
# Store to DB
Datenbank = 'WetterDB'
SQLstatement = 'INSERT INTO tbl_Luft (Datum, Uhrzeit, Temperatur, Feuchtigkeit, Druck, Taupunkt) VALUES ("%s", "%s", "%s", "%s", "%s", "%s")' % (Datum, Uhrzeit, temp, humi, pres, dewp)
DBaction.DBinsert(SQLstatement, Datenbank)
# Troubleshooting
#data = bme280.readBME280All()
#print (data)
#print(time.strftime("%d.%m.%Y %H:%M:%S"))
#print ('Temperatur: {0:0.1f} °C'.format(t));
#print ('Luftdruck: {0:0.1f} hPa'.format(p));
#print ('Luftfeuchtigkeit: {0:0.1f} % RH'.format(h));
#print ('Taupunkt: {0:0.1f} °C'.format(d));
Alles anzeigen
Es soll die Werte alle 5 Minuten in eine Datenbank schreiben.
Führe ich das Programm manuell aus (via IDLE) funktioniert das super (und auch reproduzierbar).
Lasse ich nun dieses Programm via crontab alle 5 Minuten ausführen funktioniert die zwar auch,
aber eben nicht stabil. Nach einer unregelmäßigen Anzahl an Stunden stoppt die Ausführung des Jobs (mal 30, mal 7, manchmal 12 Stunden) dann plötzlich.
Wenn ich dann den Sensor kurz vom Raspi trenne funktioniert wieder alles ( für die nächsten 8..., 12..., x Stunden), usw. usf..
Ich habe noch andere Programme, die via crontab ausgeführt werden, die laufen aber stabil weiter.
pi@poseidon:~ $ crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0,5,10,15,20,25,30,35,40,45,50,55 * * * * python3 /home/pi/Projekte/Wetterstation/Luft_cron.py
*/1 * * * * python3 /home/pi/Projekte/Wetterstation/Wind_cron.py
0,30 * * * * python3 /home/pi/Sensoren/Regen/Regen_cron.py
0,30 * * * * python3 /home/pi/Projekte/Ems_Pegel/Ems_Pegel_cron.py
pi@poseidon:~ $
Alles anzeigen
Hat jemand von euch eine Idee, woran das liegen könnte?
Welche Troubleshooting-Möglichkeiten habe ich denn bei einem Raspi?
Gibt es irgendwelche Logfiles insbesondere für den cron-Dienst oder I2C-Schnittstelle, die ich prüfen könnte?
Wichtiger Hinweis:
Ich bekomme seit einiger Zeit die Meldung "Low voltage warning. Please check your power supply.
Diese Meldung kann ich nicht nachvollziehen. Ich habe extra ein neues Netzteil mit 3 A gekauft und weniger Sensoren in Betrieb als "früher" mit den Pi Zero.
Neben dem BME280 ist noch ein AS3935 Blitzsensor, ein Regensensor, ein Anemometer und ein Windrichtungssensor angeschlossen (letzterer mit eigener Stromversorgung).
Achja und die CPU-Temperatur schwankt zwischen 57 °C und 62 °C.
Vielen Dank schon mal für euer Feedback und beste Grüße
U32