Pathpilot Notification

Is there any way to utilize PP and underlying OS to notify program status on a mill/lathe?

Say either the program ends or there’s an optional stop
PP could pass that info on and some notification method could occur (email/text)

I’ve seen mention of this on the robot text message on completion (ZA6 youtube video by Tormach)

1 Like

Hello Paul,

Certainly is. I put together some notes on how to do it. It was back in 2019 so there might be some updates to the procedure but it should give you the general idea.

Christian

Adding Email notifications to Pathpilot

Note: Control-ALT-X opens a console window in PathPilot
Note: The Pathpilot/Linux CNC configuration files are in ~/tmc/configs

This procedure makes use of custom M1xx codes. Mcode 150 is defined which when called in a gcode program will result in file M150 being executed. This file makes a call to a mail program on the Pathpilot controller and sends an email to an external mail server (e.g. your ISP, gmail etc.). This procedure requires you to make changes to the Pathpilot controller to set up email sending. This only needs to be done once.

  1. Boot the Pathpilot controller

At the Tormach “splash screen” (the one with the image) press the ALT and SHIFT keys and keep depressed until the operating system work space comes up. Open a terminal window.

  1. Install mail program

Mail may not be installed by default. Enter the command mail to see if it is. If not you’ll need to install it with the following command:

sudo apt-get install mailutils

You may get a response that it can’t be installed, the system might indicate that you need to do a apt-get update or similar. Do this and repeat above.

Next install ssmtp. This is used so that you can communicate with an external mail server. Install sSMTP with the following command:

sudo apt-get install ssmtp

You’ll need to configure ssmtp to use your external server. Open the sstmp configuration and edit the file using vi. Vi is a text editor. Use command:

sudo vi /etc/ssmtp/ssmtp.conf

Once in vi press “i” to insert text. Configure the following lines with your mail credentials. The details below are examples. You’ll need to provide your own information.

root=YourAccount@gmail.com
mailhub:587=smtp.gmail.com
AuthUser=YourAccount@gmail.com
AuthPass=YourGmailPassword
UseTLS=YES
UseSTARTTLS=YES

Once finished press the “escape key”. Move to the bottom of the file and type “:wq” (no quotations) this will save your edits and exit.

Lastly you’ll want to link ssmtp to the mail command. Install heirloom-mailx with command:

sudo apt-get install heirloom-mailx

Now you can use the mail command to test if it works:

echo “mail body” | mail -s “test” you@youremail.com

You should see an email with the subject “test” in the inbox of the mail address you specified above. If you don’t see an email check the file /var/log/mail.log to see if the email has been sent.

  1. Install the M150 file

As mentioned above a custom mcode is used to trigger email notifications. In order to do this Pathpilot will look for a file with the same name as the mcode in ~/gcode/subroutines . The name is case sensitive so it must start with a capital letter M150. Also make sure there is no extension and whatever editor you use for modifications make sure it uses Unix style line/carriage returns otherwise the file will fail to execute.

A sample M150 is below.

For the Tormach PCNC Copy this file and place it in the ~/gcode/subroutines directory on the Pathpilot controller.

You can then use the editor on the controller to change the destination email address, subject or body text.

To modify the destination email edit the line “DESTINATIONEMAIL”

To modify the machine name edit the line “MACHINENAME”. This is handy if you have multiple machines. You’ll be able to tell which machine sent the notification in the subject.

The subject and body text are automatically generated depending on the Px value. You can modify what is sent by changing the applicable NOTSUBJECT and BODYTEXT variables.

You can change which default notification is sent if the P-value is omitted by changing NOTIFICATIONDEFAULT .

Note: You can test the execution of the file by entering the following commands:

bash -v ~/gcode/subroutines/M150

Press control-D (cntl-D) to exit.

You should see an email in the inbox of the email address you specified. You might have to change the permissions on the M150 file, it must be executable by all users, ie permissions set at least to 755 and maybe 777 to be ultra sure. Use ‘sudo chmod 755’ or ‘sudo chmod 755’ . If you don’t get an email triple check that you entered the correct email address :-).

Restart the Pathpilot controller so that the system can see the M150 file.

  1. Using M150

To send an email simply enter M150 Px (P1, P2, P3 or P4) on the Pathpilot MDI line or use M150 Px where ever you require an email to be sent.

M150 P1 indicates that the program has finished.
M150 P2 indicates that a tool change is required.
M150 P3 indicates that operator action is required.
M150 P4 can be user defined.

You can see more on using mcodes here:
http://linuxcnc.org/docs/html/gcode/m-code.html#mcode:m100-m199

The contents of the M150 file is below:
#!/bin/bash
#MCODE 150 Send email notifications
#Version: 20190103
#Variables
#---------

Machine name to be used in email.

MACHINENAME="Tormach PCNC "

P Value indicates the type of email notification

0 indicates “Unknown notification”

1 indicates “Machining Finished”

2 indicates “Toolchange Required”

3 indicates “User intervention required”

4 indicates “User specified”

NOTIFICATIONDEFAULT=1

Destination email address

DESTINATIONEMAIL=“notifications@kunstmade.com.au”

if no command line arg given

set to unknown

if [ -z $1 ]
then
NOTIFICATIONTYPE=$NOTIFICATIONDEFAULT
elif [ -n $1 ]
then

otherwise make first arg the notification type

NOTIFICATIONTYPE=$1
NOTIFICATIONTYPE=$( printf “%.0f” $NOTIFICATIONTYPE )
fi

if [ $NOTIFICATIONTYPE -eq 0 ]
then
NOTSUBJECT="Unknown Notification "
BODYTEXT=“The type of notification is unknown.”
elif [ $NOTIFICATIONTYPE -eq 1 ]
then
NOTSUBJECT="Program Finished "
BODYTEXT=“The gcode program has finished.”
elif [ $NOTIFICATIONTYPE -eq 2 ]
then
NOTSUBJECT="Tool change required "
BODYTEXT=“A tool change is required.”
elif [ $NOTIFICATIONTYPE -eq 3 ]
then
NOTSUBJECT="Operator intervention required "
BODYTEXT=“Operator intervention is required.”
elif [ $NOTIFICATIONTYPE -eq 4 ]
then
NOTSUBJECT="User Specified "
BODYTEXT=“User specified.”
else
NOTSUBJECT="Unknown Notification P$1 invalid "
BODYTEXT=“An invalid Px argument is used.”
fi

SUBJECT=$MACHINENAME
SUBJECT+=$NOTSUBJECT
DATE=$(date)
SUBJECT+=$DATE

3 Likes

Have a look at this Messaging plugin

Installation is very straightforward (see User plugins) and it can send notifications in response to system activity, so doesn’t require you to alter your program code. It’ll spot, for example, a tool change that’s been in progress for too long and message an operator.

All you need is a free gmail account.

1 Like

Appreciate the help @Christian_Groves & @David_Loomes.

After reviewing both options I went with the manual plugin mentioned in @David_Loomes links. After fumbling my way around linux I was able to get it to alert per the default triggers (machine status - end/stopped/etc). I have yet to mess with the custom g-code M68 option, but may look into that shortly.

This will be a wonderful improvement over my current process of setting timers or checking webcam for updates. Thanks!

Paul,
Thanks for that. Any problems at all, just get in touch and I’ll see if I can help.

David

1 Like