a blog of ideas and improvements for tormach cnc mills
articles | for sale | about | contact


EMAIL AND SMS TXT NOTIFICATIONS IN GCODE. FOR FREE.

REV 3, MAR 28 2023 | ORIG, MAR 25 2023 | CHANGELOG

FOR THE GEEKS

 

You will call a python or perl script located in /home/operator/tmc/configs/tormach_mill/nc_subs, via M101 through M199.

(actually, it can go in /gcode/subroutines which is a ton easier)

Tormach already has an M100 in that location that I don't want to mess with, though I don't think it's in use. They have advised it definitely is in use so just start with M101.

The script will send a message via SMTP to the email or email-to-text address of your choice. Pass arguments via P and Q values in the gcode. IF statements in the script will allow multiple custom messages. Annoyingly, you can only pass integers via P and Q, afaik.

The Python script seems to run out of the box. PERL runs, but (gmail) requires Net::SMTP::SSL and I forget if I had to install it or not. If I did, I also had to install cpan first.

Use Gmail and create an independent App Password. Your normal Gmail password won't work.

The format is:

M101 P# Q#

where P is an optional integer, Q is an optional integer. IF statements can be assigned to the arguments for custom messages. See actual code farther below.

Example:

M101
or
M101 P1
or
M101 P2
or
M101 P1 Q1
or
M101 P3 Q5
or
M102
or
M103

In this specific case, P would be the subject line of the email and Q would be the body.

You can also just write individual M commands instead (M101, M102, M103), instead. Same difference.

I wrote a script below that injects your gmail credentials into the python script so all you have to do is copy it over.

FOR THE REST OF US

 

Everyone wants to receive notifications via gcode, but no one has written a clear, concise guide. Until now.

This is is a multi step process, but none of it is too difficult, nor is it harmful to the controller. But, you will be digging behind the scenes of the Pathpilot user interface.

You know what G0, M3, G54 do. Now, you're going to be using a new command called M101 (really M101 all the way up to M199).

M101 is literally a custom command and, in this case, it's going to be an actual file (like your .nc files) of code, either written in Python or PERL.

This is going to allow you to have gcode written like this:

G0 Z5
M3 S5000
M101            #    SEND EMAIL THAT SPINDLE IS ON
G0 X1Y1Z0
G1 F10 Z-.1
M102            #    SEND EMAIL THAT MACHINE HAS ENTERED A CUT
G1 X5
G0 Z5
M5
M103            #    SEND EMAIL THAT CYCLE IS COMPLETE

For operator intervention, you can always pause the code after the email with M01.

Instead of sending a txt message, which requires API's and money, we will be sending an email instead. You CAN send an email-to-text, but it's definitely more reliable to send an email-to-email and your phone will ping the same anyhow, providing you have email set up on your phone. See disclaimers below.

This guide will assume you're using Gmail. Gmail is one of the few providers that allow third-party SMTP sending for free. That part isn't important to understand. What is, is that it will work and everyone has access to it. You don't need to use this account for anything other than sending the notifications. But you do have to have one.

Thanks to the following posts for helping me turn this idea into reality:

Also, David Loomes has (with permission) used my code and idea to implement his own integration with UI hooks. His method should have the ability to survive PathPilot upgrades.

STEP 1 - GET A GMAIL ACCOUNT, TURN ON TWO STAGE VERIFICATION AND MAKE AN APP PASSWORD

 

If you don't have a gmail account yet, go get one.

Two Stage Verification must be turned on, which is annoying, so you may want to get a separate gmail just for this.

Turn it on via http://account.google.com.

After you do, you have to make what they're calling an App Password. Google used to have something called "Use Less Secure Apps" (which is exactly what it sounds like), but removed that a while back. Most guides of this nature haven't been updated, but it's just as easy.

You'll just create a separate password for those same "less secure" apps that is independent of your main password. Your normal Gmail password won't work.

You're going to need that custom password, so leave the window open, or copy it somewhere. After you close that screen, you can't see it again (you can just create a new one if necessary).

STEP 2a - COPY THAT GMAIL ADDRESS AND PASSWORD INTO CODE - THE EASY WAY

 

NEW: I have written a script that will enter all your details for you. Then, all you have to do is copy it onto your controller.

You don't have to use this option. You can still do it all manually, but this is a lot easier.

NOTE: Yes, by filling out the below form you are giving me your information.

No, I don't care about it and it's deleted immediately after the script is run.

Fill out the details below and click Generate Script. It will download one file, minstall.sh. Place this in the /gcode directory on your machine.

Again, this is all optional. Read the rest of the guide and do it that way if you want. Probably a good idea to read it all anyhow.

 Your new Gmail address:
Your new App Password:
The recipient email (or email-to-text) address:

If you downloaded the generated script, copy it to your machine (into your /gcode folder), open a terminal window in PathPilot via CTRL+ALT+X (possibly CTRL+ALT+T, google it).

Then, in the terminal window type

cd gcode

then type

chmod +x ./minstall.sh

then type

./minstall.sh

The ./ is required. After the script runs, you're all done. Just reboot the machine. And read the rest of the article.

STEP 2b - COPY THAT GMAIL ADDRESS AND PASSWORD INTO CODE - THE MANUAL WAY

 

If you don't do any of that, follow the rest of the guide instead:

Now that you have your gmail address and independent password, you need to paste them into some code I've written below.

There are both python and perl options here. I know perl a lot better than I know python, but the python "just worked" when I tried and perl typically requires screwing around.

You're editing four lines of code and they are marked. Click the link below.


Python | PERL
 

Copy that code into notepad (try to use a basic editor like notepad), edit the lines and save it as M101 (capital M, no file extension). I know Windows dislikes users not entering extensions, so if you can't figure that part out, we'll fix it later and you can name it whatever. Protip: To force it to save without an extension, wrap it in quotes: "M101"

STEP 3 - COPY THAT CODE ONTO MILL

 

You have to get this code onto your machine somehow. Thumb drive, WiFi, whatever you use to get your gcode on the machine will work.

You'll probably place it among all your other gcode files, which is fine for now, but we'll have to move it to the correct location.

STEP 4 - MOVE THAT CODE TO PROPER LOCATION WITH PROPER FILENAME

 

You're standing in front of your machine with PathPilot open and at the ready. You've copied your code over to the machine.

Now comes the part that a lot of you haven't yet done and are afraid to. We have to step past PathPilot into the Linux back end. If you're not already aware, PathPilot is just a random program running on any old computer, which is running Linux.

We won't be do anything drastic or damaging and even if you do mess something up, Tormach provides easy methods to restore the machine. We're really not modifying a single thing. We're adding one file to one directory. That's it.

The following is specific to MY machine, which is a 2020-era 1100M running Linux Mint. This step may be different for you. Get into the FB Group and ask if you get stuck here. Google or ask how to get to a terminal window in your flavor of Linux.

In my case, press CTRL+ALT+X, which will bring up a terminal window. Here, type     mate-panel     and press enter.

You should see a desktop interface, or at least a Start Menu will pop up, similar to Windows.

Click the menu button (Linux's version of the Start button) and type or find gedit, which is like Notepad.

Go to     File | Open     and find the Python code we modified earlier. If you put it with the rest of your gcode, it will be in     Home | Operator | Gcode

After it's open,     File | Save As     and browse out to the completely obscure location:     home | operator | tmc | configs | tormach_mill | nc_subs
(or home | operator | gcode | subroutines)

This location is probably different for lathes, routers, plasma, etc.

Save it as M101 (it MUST be a capital M, with no extension). I'm using M103, but same deal.

NOTE:

If you edited your M101 file on a Windows machine, it will probably not be Linux-compatible (Linux treats new paragraph lines differently). There are a few ways to fix this. Here's one way:

1. Via your terminal window, install the small script dos2unix via:

sudo apt-get install dos2unix

2. Then type dos2unix M101

STEP 5 - MAKE YOUR FILE EXECUTABLE

 

Go back to the Menu button and find File Browser, by typing it, though it may already be on the screen somewhere.

Browse to that same location, which, again, is /home/operator/tmc/configs/tormach_mill/nc_subs (or /home/operator/gcode/subroutines)

Find your M101 (I'm using M103 in the photos but it's the same thing) and right click on it. Go down to Properties.

Click the Permissions tab and check Allow executing file as program.

Close out of that window and go back into PathPilot. It'll be one of the tabs at the bottom, just like in Windows.

Shut down the controller like you always do. This is required because PathPilot loads the M files at boot. Right now, it doesn't know the file exists.

STEP 6 - TIME TO TEST

 

Reboot, home and zero the machine. Create, or find a simple gcode file.

If you can't read Gcode, copy the following:

G20
G1 F50 X1
M101 P1
G1 F50 X0

Run that and see what happens. It should move your X axis 1", send an email saying Op 1 is done and move back to X0.

If it did, great, now you can move on to customizing the code, if you want.

For instance, in the code you copied, if you type M101 P2, you'll get an Op 2 complete email.

If you type M101 P3, you'll get a Cycle complete email.

If you type M101, you'll get a default message email.

You can edit the lines back in the code to adjust to your tastes.

STEP 7 - SEND ACTUAL TXTS (MAYBE)

 

You came here to send txts, not emails. Well, it has limitations. Here's what I've found out.

If you have verizon, you can send (and receive) texts via phonenumber@vtext.com (example 4402165555@vtext.com).

If you have Boost, you can send them via phonenumber@sms.myboostmobile.com (example 1234567890@sms.myboostmobile.com).

Most carriers have their own version of this. Google for yours.

HOWEVER, Verizon seems to block gmail. All of my @gmail addresses fail, but my work ones go through (even if I'm using Google Workspace, which I am). For instance, Nick@tormachtips.com would work, if I was using Google Workspace (which is their Gmail client on your own domain).

My Boost number allows Gmail.

So, what does this mean?

If your phone is Verizon, texts aren't going to work unless you have another email host you can use. Emails still will though. So just let your phone ping emails instead. Or, get a Google Workspace account.

CHANGELOG

  March 28 2023: Made the bash script do all the work, so now you're just copying one file over and running it.

March 27 2023: Wrote a PERL script that injects your gmail credentials into the python script and readies it for download. Also wrote a bash script that will copy the M101 file over and make it executable.

March 25 2023: Original article.