RouvenE Posted October 10, 2015 at 11:13 AM Posted October 10, 2015 at 11:13 AM Hi, Derzeit betreibe ich die Tinkerforge-Wetterstation per Raspberry Pi 2. Nun habe ich das System neu aufgesetzt, dabei diesmal aber statt Rapsbian Wheezy das neuere Raspbian Jessie hergenommen. Brick/d/v sind installiert. Starte ich "python /home/pi/tinkerforge/wetter.py" (Wetterstation-Standard-Beispiels-Script), so funktioniert alles wunderbar. Um nun das Skript beim Start des RPi zu laden, habe ich zwei Varianten getestet (was zuvor unter Wheezy tadellos funktionierte): 1) sudo crontab -e, dort eingetragen: @reboot /usr/bin/python /home/pi/tinkerforge/wetter.py 2) sudo nano /etc/rc.local, dort eingetragen: python /home/pi/tinkerforge/wetter.py & Obwohl ich mit selben Befehlen das Script starten kann, funktioniert nicht der Autostart mit obigen Lösungswegen... Ein User eines anderen Forums hat dies getestet und folgendes festgestellt: "/usr/log/brickd.log[script]2015-10-10 12:02:44.221968 <I> <network.c:373> Added new client (N: 127.0.0.1:60812, T: plain-socket, H: 17, A: disabled) 2015-10-10 12:02:44.306278 <I> <client.c:220> Client (N: 127.0.0.1:60812, T: plain-socket, H: 17, A: disabled) disconnected by peer[/script]" Mir ist absolut nicht klar, warum sich a) das Skript manuell starten lässt, nicht aber automatisch und b) alles unter Raspbian Wheezy problemlos funktionierte... Weiß jemand Rat ? Quote
remotecontrol Posted October 10, 2015 at 12:42 PM Posted October 10, 2015 at 12:42 PM Ändere den Startbefehl mal nach python /home/pi/tinkerforge/wetter.py >/tmp/wetter.log 2>&1 & Dann steht evtl. in /tmp/wetter.log etwas drin, wenn ein Fehler kommt. Schreibt Dein Skript Daten in eine Datei? Wenn ja: wie sprichst Du die an (absolut / relativ)? Beim Start eines Skriptes aus den root-crontab oder init.d ist zu beachten: - Environment-Variablen sind nicht gesetzt (auch kein $HOME) - Arbeitsverzeichnis ist in der Regel "/" (root-Verzeichnis) Quote
RouvenE Posted October 10, 2015 at 02:19 PM Author Posted October 10, 2015 at 02:19 PM Ich liste mal die Logdatei auf... INFO:root:Weather Station: Start Press key to exit Traceback (most recent call last): File "/home/pi/tinkerforge/wetter.py", line 167, in <module> input('Press key to exit\n') EOFError: EOF when reading a line Habe ich in rc.local eingebaut... Nutze ich statt dem sudo-crontab doch den Benutzer-crontab, so startet das Skript auch nicht. Muss ich Pfade setzen ? Wenn ja, wie ? Quote
RouvenE Posted October 10, 2015 at 05:12 PM Author Posted October 10, 2015 at 05:12 PM Kann denn keiner der Linux-/Pythonexperten helfen? Quote
remotecontrol Posted October 10, 2015 at 05:31 PM Posted October 10, 2015 at 05:31 PM Das Problem ist, dass Du auf Benutzereingaben wartest, darum diese Fehlermeldung. EOFError: EOF when reading a line Das liegt daran, dass <stdin> bei cron und inittab nicht verfügbar sind, die Dateien sind per Default mit keinem Terminal verbunden. Du müsstest in Deinem Hauptprogramm eine Endlosschleife einbauen, sowas in der Art anstelle des "input()": import time while 1: time.sleep(10) Damit läuft das Skript endlos (wacht zwar alle 10 Sekunden auf, schläft dann aber wieder). Beenden kannst Du es dann aber nur noch mit einem "kill" bzw. wenn Du es von Hand startest mit Ctrl-C (so die Theorie, Python nutze ich sonst nicht). Quote
RouvenE Posted October 10, 2015 at 06:00 PM Author Posted October 10, 2015 at 06:00 PM #!/usr/bin/env python # -*- coding: utf-8 -*- import socket import sys import time import math import logging as log log.basicConfig(level=log.INFO) from tinkerforge.ip_connection import IPConnection from tinkerforge.ip_connection import Error from tinkerforge.brick_master import Master from tinkerforge.bricklet_lcd_20x4 import LCD20x4 from tinkerforge.bricklet_ambient_light import AmbientLight from tinkerforge.bricklet_ambient_light_v2 import AmbientLightV2 from tinkerforge.bricklet_humidity import Humidity from tinkerforge.bricklet_barometer import Barometer class WeatherStation: HOST = "localhost" PORT = 4223 ipcon = None lcd = None al = None al_v2 = None hum = None baro = None def __init__(self): self.ipcon = IPConnection() while True: try: self.ipcon.connect(WeatherStation.HOST, WeatherStation.PORT) break except Error as e: log.error('Connection Error: ' + str(e.description)) time.sleep(1) except socket.error as e: log.error('Socket error: ' + str(e)) time.sleep(1) self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, self.cb_enumerate) self.ipcon.register_callback(IPConnection.CALLBACK_CONNECTED, self.cb_connected) while True: try: self.ipcon.enumerate() break except Error as e: log.error('Enumerate Error: ' + str(e.description)) time.sleep(1) def cb_illuminance(self, illuminance): if self.lcd is not None: text = 'Illuminanc %6.2f lx' % (illuminance/10.0) self.lcd.write_line(0, 0, text) log.info('Write to line 0: ' + text) def cb_illuminance_v2(self, illuminance): if self.lcd is not None: text = 'Illumina %8.2f lx' % (illuminance/100.0) self.lcd.write_line(0, 0, text) log.info('Write to line 0: ' + text) def cb_humidity(self, humidity): if self.lcd is not None: text = 'Humidity %6.2f %%' % (humidity/10.0) self.lcd.write_line(1, 0, text) log.info('Write to line 1: ' + text) def cb_air_pressure(self, air_pressure): if self.lcd is not None: text = 'Air Press %7.2f mb' % (air_pressure/1000.0) self.lcd.write_line(2, 0, text) log.info('Write to line 2: ' + text) try: temperature = self.baro.get_chip_temperature() except Error as e: log.error('Could not get temperature: ' + str(e.description)) return # \xDF == ° on LCD 20x4 charset text = 'Temperature %5.2f \xDFC' % (temperature/100.0) self.lcd.write_line(3, 0, text) log.info('Write to line 3: ' + text.replace('\xDF', '°')) def cb_enumerate(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type): if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \ enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE: if device_identifier == LCD20x4.DEVICE_IDENTIFIER: try: self.lcd = LCD20x4(uid, self.ipcon) self.lcd.clear_display() self.lcd.backlight_on() log.info('LCD 20x4 initialized') except Error as e: log.error('LCD 20x4 init failed: ' + str(e.description)) self.lcd = None elif device_identifier == AmbientLight.DEVICE_IDENTIFIER: try: self.al = AmbientLight(uid, self.ipcon) self.al.set_illuminance_callback_period(1000) self.al.register_callback(self.al.CALLBACK_ILLUMINANCE, self.cb_illuminance) log.info('Ambient Light initialized') except Error as e: log.error('Ambient Light init failed: ' + str(e.description)) self.al = None elif device_identifier == AmbientLightV2.DEVICE_IDENTIFIER: try: self.al_v2 = AmbientLightV2(uid, self.ipcon) self.al_v2.set_configuration(AmbientLightV2.ILLUMINANCE_RANGE_64000LUX, AmbientLightV2.INTEGRATION_TIME_200MS) self.al_v2.set_illuminance_callback_period(1000) self.al_v2.register_callback(self.al_v2.CALLBACK_ILLUMINANCE, self.cb_illuminance_v2) log.info('Ambient Light 2.0 initialized') except Error as e: log.error('Ambient Light 2.0 init failed: ' + str(e.description)) self.al = None elif device_identifier == Humidity.DEVICE_IDENTIFIER: try: self.hum = Humidity(uid, self.ipcon) self.hum.set_humidity_callback_period(1000) self.hum.register_callback(self.hum.CALLBACK_HUMIDITY, self.cb_humidity) log.info('Humidity initialized') except Error as e: log.error('Humidity init failed: ' + str(e.description)) self.hum = None elif device_identifier == Barometer.DEVICE_IDENTIFIER: try: self.baro = Barometer(uid, self.ipcon) self.baro.set_air_pressure_callback_period(1000) self.baro.register_callback(self.baro.CALLBACK_AIR_PRESSURE, self.cb_air_pressure) log.info('Barometer initialized') except Error as e: log.error('Barometer init failed: ' + str(e.description)) self.baro = None def cb_connected(self, connected_reason): if connected_reason == IPConnection.CONNECT_REASON_AUTO_RECONNECT: log.info('Auto Reconnect') while True: try: self.ipcon.enumerate() break except Error as e: log.error('Enumerate Error: ' + str(e.description)) time.sleep(1) if __name__ == "__main__": log.info('Weather Station: Start') weather_station = WeatherStation() if sys.version_info < (3, 0): input = raw_input # Compatibility for Python 2.x input('Press key to exit\n') if weather_station.ipcon != None: weather_station.ipcon.disconnect() log.info('Weather Station: End') An welcher Stelle würdest Du es einfügen ? Ich frage mich, warum das alles unter Raspbian Wheezy nicht notwendig war. Das lief problemlos... Wenn es hilft, wäre das ja super. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.