Last active
November 3, 2019 16:09
-
-
Save TheEmpty/9919fae4b427f551217c596d6fe3923a to your computer and use it in GitHub Desktop.
Octoprint Slack Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Suggested: add this to your crontab to run @daily. This deletes all snapshots last modified a week ago. | |
find /home/pi/oprint/lib/python2.7/site-packages/octoprint/static/img/SNAP_* -mtime +7 -exec rm -fr {} \; | |
$ crontab -e | |
@weekly find /home/pi/oprint/lib/python2.7/site-packages/octoprint/static/img/SNAP_* -mtime +7 -exec rm -fr {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this to your ~/.octoprint/config.yaml | |
# You will need to `sudo service octoprint stop`, edit, and then `sudo service octoprint start` | |
# If you do it with OctoPrint running, it will override/delete your changes when it shutsdown. | |
# Octoprint does also not reload this file while it's running. | |
events: | |
enabled: true | |
subscriptions: | |
- command: /home/pi/print-finished.sh {file} | |
event: PrintDone | |
type: system |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############# | |
# CONFIGURE # | |
############# | |
HOST="https://YOUR_PUBLIC_HOSTNAME" | |
STATIC="/home/pi/oprint/lib/python2.7/site-packages/octoprint/static" # change this if you're not using Octo*Pi* | |
SLACK_WEBHOOK_URL="REPLACE_WITH_YOURS" | |
SLACK_USERNAME="OctoPrint" | |
SLACK_ICON_URL="$HOST/static/img/logo.png" | |
SLACK_TEXT_BEFORE_FILENAME="Print completed: " | |
############## | |
# CALCULATED # | |
############## | |
FILE=$(basename $1) | |
DATE=$(date "+%s") | |
IMAGE_NAME="SNAP_$DATE.png" | |
IMAGE_URL="$HOST/static/img/$IMAGE_NAME" | |
# Takes a snapshot and stores it in the "static" directory for Octoprint. | |
curl -o $STATIC/img/$IMAGE_NAME "http://localhost:8080/?action=snapshot" | |
# Sends a slack notification with a URL to the snapshot. | |
curl -X POST -H "Content-type: application/json" --data "{\"username\": \"$SLACK_USERNAME\", \"icon_url\": \"$SLACK_ICON_URL\", \"attachments\": [{\"fallback\": \"Completed Print\", \"text\": \"$SLACK_TEXT_BEFORE_FILENAME $FILE\", \"image_url\": \"$IMAGE_URL\"}]}" $SLACK_WEBHOOK_URL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE=$1 | |
# Script gets called when gcode is finished being sent. | |
# This doesn't mean that the printer has finished the | |
# last gcode instruction. Waiting a few seconds should | |
# be fine and the last gcode should have been completed. | |
sleep 3 | |
# Change working directory to where this file is stored. | |
# This assumes print-finished.sh and notifiy-slack.sh are in the same place. | |
# If you're just copy/pasting this, put these in your home directory. | |
cd "$(dirname "$0")" | |
./notify-slack.sh "$FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment