Can't seem to get events to work


#1

What is the problem?
I added some scripts to my config.yaml (in ~/.octoprint/config.yaml) to be called when certain print events happen, but they never get called.
What did you already try to solve it?
I made sure the script was working correctly by running it normally.
I also tried resetting the raspberry pi (I have the stock octoprint image, and octoprint is version 1.3.7, according to the 'about Octoprint" in the settings menu).
I looked up some examples from other people, but mine looks the same to me.
Additional information about your setup
Here is what I added to the bottom of my config.yaml file:

events:
  enabled: True
  subscriptions:
  - event: PrintStarted
    command: /home/scripts/toggleLights.py 1
    type: system
  - event: PrintDone
    command: /home/scripts/toggleLights.py 2
    type: system
  - event: PrintFailed
    command: /home/scripts/toggleLights.py 3
    type: system
  - event: PrintCancelled
    command: /home/scripts/toggleLights.py 4
    type: system

Then this is the script that should run (and works when I run it normally):

#! /usr/bin/python
import sys
import time
print "Lights would have been toggled!"

f = open("/home/pi/test"+ str(time.time()) + ".txt",'w')
f.write("test!\n");
f.write(str(sys.argv));
f.close();

Thanks!


#2

I'm not used to seeing a space after the shebang. Maybe this version instead which specifically asks for v2:

#!/usr/bin/env python2

Also, I note that I have three python installs on my own Raspi:

/usr/bin/python (v2.7.13 this appears to be the globally-available version)
~/oprint/bin/python (v2.7.13 this appears to be OctoPrint's virtual environment
~/OctoPrint/venv/bin/python (v2.7.13 since I develop)


#3

Yeah, so I can certainly take out the space and try it, but I've been putting the space in forever. When I run it on command line I just do ./toggleLights and it works fine. I'll also try ~/oprint/bin/python too. It's weird that nothing happens. Is there a way to find debug information? Like what happens if it can't find a script I ask it to run? Is there a log that would say something?


#4

Is there a reason you're not explicitly just using python as the command as in these examples?

docs

  python /home/scripts/toggleLights.py 1

Note: their example refers to home-centric locations for the scripts, as in ~/growl.py but you have your scripts loaded in a place that suggests there's a user named scripts. Does the pi user have access to another user's home folder? Probably not.

Assuming that scripts is another user, you could run some commands to add rights so that pi has access to it... only I think I'd just put the scripts somewhere else like ~/scripts instead.


#5

Wow. You're totally right. Stupid mistake. I'll try that right away. Pretty sure that's it. it was supposed to be /home/pi/scripts. I'm an idiot. Sorry about that. Hopefully it works now.


#6

I'm a software development instructor, does it show? :laughing:

Make sure to mark that reply if it solved your problem. Thanks.


#7

That was great! Thanks! Also, while I have you here, is there a place to see logs? Somewhere something tried to run the script and couldn't find it. Does octoprint record logs of that somewhere? I looked through the logs in ~/.octoprint/logs/, but none of them mentioned anything about errors when trying to use this event. They just said there were 4 registered events.


#8
  • Programmatically, it's here
  • Physically from an ssh session, you'd be interested in ~/.octoprint/logs/octoprint.log
  • From the web interface, they're available in Settings -> Logging

In theory, you could go to the web interface I just mentioned, choose the + button and add octoprint.util.commandline with DEBUG and it may start collecting data into a new log which indicates what's happening when it reaches out to run scripts.


#9

Excellent. Thanks so much!