Closed FriedCircuits closed 10 years ago
I was able to capture the error output when run as cron
Traceback (most recent call last):
File "/home/pi/piminer/PiMiner.py", line 6, in
For future reference, seems like something to do with cron which can do odd things. So going to look for another way to start it on boot as root.
I never had such problems. To be honest, I've never tried to start DS18B20 from a cronjob. For your case a cronjob is anyway not the best way to go. Instead of cronjob use a init script. Place something like this in your /etc/init.d:
!/bin/sh
### BEGIN INIT INFO
# Provides: DAEMON_NAME
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: DESCRIPTION
# Description: DESCRIPTION
### END INIT INFO
DIR=/path/to/your/daemon
DAEMON=$DIR/daemonscript.py
DAEMON_NAME=MYDAEMON
# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_USER=root
# The process ID of the script when it runs is stored here:
PIDFILE=/var/run/$DAEMON_NAME.pid
. /lib/lsb/init-functions
do_start () {
log_daemon_msg "Starting system $DAEMON_NAME daemon"
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON
log_end_msg $?
}
do_stop () {
log_daemon_msg "Stopping system $DAEMON_NAME daemon"
start-stop-daemon --stop --pidfile $PIDFILE --retry 10
log_end_msg $?
}
case "$1" in
start|stop)
do_${1}
;;
restart|reload|force-reload)
do_stop
do_start
;;
status)
status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
I hope I could help! :beers:
Just wanted to let you know the init scripts works great.
Hi,
I wanted to see if you have come across a problem when you start a python program that uses DS18B20 on boot.
I have a crontab that is set to on reboot to start my python program.
The problem is when it init the library it fails. But if I run it manually with sudo at the command line it works fine.
it fails on sensor=DS18B20()
I can't see the error when it runs from cron so I have no idea what is happening.
Any ideas?
Thanks.
Edit: Sometimes I get this File "/home/pi/piminer/ds18b20/init.py", line 87, in _get_sensor return path.join(DS18B20.BASE_DIRECTORY, DS18B20.SLAVE_PREFIX + self._id, DS18B20.SLAVE_FILE) TypeError: cannot concatenate 'str' and 'NoneType' objects