Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    execonmcode mailgun script

    Scheduled Pinned Locked Moved
    DSF Development
    1
    1
    134
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • oozeBotundefined
      oozeBot
      last edited by oozeBot

      I threw this together as a poor man's notification system until either we have time to build something better or someone else does (wink wink).

      If you don't know, Mailgun is an email service which allows you to send emails automatically through their API. I believe you do have to have your own domain to get it working. It's relatively cheap (1000 emails costs $.80 US) and we use it for our mailing list, etc.. so expanding it for this was a no-brainer.

      As I stated in the title, this requires execonmcode. It also uses M-JPEG streamer for the attached snapshot.

      I chose M5545 for my custom code. Here is the service file:

      [Unit]
      Description=Duet API listener for Mailgun
      After=duetcontrolserver.service
      Requires=duetcontrolserver.service
      
      [Service]
      ExecStart=/usr/local/bin/execonmcode -mCode 5545 -command "./scripts/mailgun.sh %%C %%Z %%P %%L"
      Restart=always
      RestartSec=10
      
      [Install]
      WantedBy=multi-user.target
      

      And the script:

      #!/bin/sh
      # Mailgun Mailer
      # Usage: ./mailgun.sh Current_Layer Current_Z_Height Current_Percentage Total_Layers
      # Example: ./mailgun.sh "20" "4.0" "55.5" "36"
      # gCode: M5545 C"20" Z"4.0" P"55.5" L"36"
      #  C=Current_Layer
      #  Z=Current_Z_Height
      #  P=Current_Percentage
      #  L=Total_Layers
      
      sudo wget http://localhost:8080/?action=snapshot -O snapshot.jpg
      
      curl -s --user 'api:<your-mailgun-api>' \
        https://api.mailgun.net/v3/<your-domain>/messages \
        -F from='<your-alert-email-alias>' \
        -F to='<your-actual-email-address>' \
        -F subject='Status update: '$3'%' \
        -F text='The current job is on layer '$1' of '$4', at z-height '$2', and is '$3'% complete.' \
        -F attachment=@snapshot.jpg
      
      rm snapshot.jpg
      

      I am using Simplify3D as my Slicer. In my layer change script, I have the following:

      {IF "[current_layer]%10==0"}M5545 L"[current_layer]" Z"[current_Z_position]" P"[progress]" T"[total_layer_count]"
      

      This tells Simplify3D to put the M5545 command in the code every 10 layers. Change the "10" to whatever works best for you..

      A sample mCode is:

      M5545 C"20" Z"4.0" P"55.5" L"36"
      

      This produces an email containing the following with attached snapshot.

      • Subject: Status update: 55.5%
      • Body: The current job is on layer 20 of 36, at z-height 4.0, and is 55.5% complete.
      1 Reply Last reply Reply Quote 1
      • First post
        Last post
      Unless otherwise noted, all forum content is licensed under CC-BY-SA