Welcome! Log In Create A New Profile

Advanced

Notification on print completion

Posted by unromeo21 
Notification on print completion
October 10, 2016 09:51AM
Is there any way I can implement some sort of notification / automation using a Duet and a Raspberry Pi when a print is completed ?
I currently have the Duet connected over Ethernet with a Raspberry, the Pi acting as a WebCam streamer and wifi bridge for the Duet. I would like to know what possibility is for me to get a notification message from the Duet so that the Raspberry knows when a print is completed and do other stuff (send e-mail, execute SSH script, etc). Maybe using Telnet ?

Thanks.

Edited 1 time(s). Last edit at 10/10/2016 09:51AM by unromeo21.
Re: Notification on print completion
October 10, 2016 10:13AM
Just thinking out loud. Could you connect one of the digital pins from the Duet header to the GPIO on the Pi and monitor it to go high from the Pi. Then add something like this to your end gcode.

;Set Pin high in end gcode.
M42 P67 S1 ; Digial pin 67 on (physical pin 32 on header.)
G4 P1000   ; wait 1000 msec (= 1 sec)
M42 P67 S0 ; pin off


There's a little binary on Pi for working with the GPIO stuff that might be a good starting point - [projects.drogon.net]


DC42 Kossel 330mm x 2meters
My Thingiverse Creations
Re: Notification on print completion
October 10, 2016 10:23AM
Another way would be for the RPi to log on to the Duet, send it rr_status requests via http, and watch for the printer status field in the response to go form Printing to Idle.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: Notification on print completion
October 11, 2016 05:51AM
So, if anybody else is interested in such automation , I came up with a simple solution. No extra hardware required, and programming is really simple.

Here is the basic workflow:

The Pi connects at specific intervals to the Duet over telnet (port 21) and issues a M27 Command. When it reads the word "byte", it knows that the printing is still in progress, else when it reads the word "Not", it knows that the printer is Idle. I added a status variable so it will trigger actions only when this status changes.

expect is required and must be installed (apt-get install expect)

Here is the script:

#!/usr/bin/expect
set timeout 20
set ip [lindex $argv 0]
set password [lindex $argv 1]

spawn telnet $ip
expect "password:"
sleep .1;
send "$password\r";
sleep 1;
expect "successful!"
sleep 1;
send "M27\r"
sleep 1;
expect  {
 "byte" {    ### if M27 reports printing in progress, than ...
        send "exit\r"
        sleep .1;
        spawn cat status    ###check last status
        expect  {
        "0"     {
                exec echo 1 > status ### if last status is 0 , than change to 1 and inform user
                send_user "Printing started!"
                }
        "1"     {
                send_user "Printing in process"  ### if last status is 1, it means that we already printing, do nothing
                }
                }
        }
 "Not"  {     ### if M27 reports "Not printing" or idle, than ... 
        send "exit\r"
        spawn cat status  ### check last status
        expect  {
        "1"     {
                exec /home/pi/./finished.sh  ### if last status was 1 (printing) than execute finished.sh script 
                send_user "Printing finished!"
                exec echo 0 > status   ### write new status
                }
        "0"     {     ### if last status was 0 , it means that no printing was started or finished actions were already executed. 
                send_user "No Print started yet!"
                }
                }
        }
        }

This script will be run at specific intervals using cron. User is free to choose how often.

Tried to keep it simple and basic.. it can be expanded and improved. It works in my case.
Re: Notification on print completion
October 11, 2016 06:48AM
Nice solution, I think you might want to add a lock file so that you don't get multiple notifications, create it the first time the printing starts and remove it once printing finishes and you've sent the alert. Otherwise won't you just keep getting printing finished alerts?


DC42 Kossel 330mm x 2meters
My Thingiverse Creations
Re: Notification on print completion
October 11, 2016 07:34AM
Quote
DADIY
Nice solution, I think you might want to add a lock file so that you don't get multiple notifications, create it the first time the printing starts and remove it once printing finishes and you've sent the alert. Otherwise won't you just keep getting printing finished alerts?

That's the "spawn cat status" for. It checks for a status file, and it triggers action only when the status changes. Everything is in there.. If status is unchanged, it doesn't run any script, just prints a message on stdout.

Edited 1 time(s). Last edit at 10/11/2016 07:37AM by unromeo21.
Re: Notification on print completion
October 11, 2016 08:32AM
Perfect! Expect is not a language I've ever had the need to use but I think I will install it on one of my debian boxes and give this a go could be very useful.

EDIT:

Just installed expect and set up your script, but I'm thinking of putting this in cron and letting it run every minute and then I will use boxcar to push a message to my iPhone/watch. But I don't want lots of telnets being run when the printer is off so I've wrapped the call to your script with a little check for the printer being on.

#Check Printer is up before attempting to connect.
ping -W1 IP -c 1 >/dev/null 2>&1
if [ $? = 0 ]
then
  echo Printer Up
  /path/to/script/watchprinter.sh IP Password

else
  echo Printer down.
fi

Edited 2 time(s). Last edit at 10/11/2016 10:08AM by DADIY.


DC42 Kossel 330mm x 2meters
My Thingiverse Creations
Re: Notification on print completion
October 11, 2016 09:54AM
Yeah, that's a good idea. I did not needed this as my Raspberry is running only when the printer is running (on the same power rail) and the printer connects to the network through my PI acting as a wifi bridge.
Sorry, only registered users may post in this forum.

Click here to login