AstroPrint / AstroBox

AstroBox allows you to control your 3D Printer wirelessly
https://www.astroprint.com/products/p/astrobox-software
GNU Affero General Public License v3.0
158 stars 47 forks source link

Remote ON/OFF switch of the printer #86

Open havanakuba opened 8 years ago

havanakuba commented 8 years ago

I'm using my raspberry pi, and I came with idea to add a button to web interface to turn off your printer after finish print or printer lights during print this can be done easily on raspberry via relay connected to gpio

robermeyer commented 7 years ago

I also need the ability to turn ON/OFF my printer(s) before and after a print.
I have 2 delta printers so I would like to be able to turn either one ON/OFF remotely.
Concurrently maybe turn ON/OFF a light per printer for the camera on demand. How about an exhaust fan. I see this is almost a year old and not assigned to anybody and no milestone. Obviously if nobody starts on it, it will never get done. What can be done to get this started?

havanakuba commented 7 years ago

I was thinking to use this cheap relays. My DIY skils are very good (due to what I do for living) but my python programming skills are not that great. But improving every day if I have some time left.

fullsizerender

havanakuba commented 7 years ago

You can get those as 1,2,4,8 channels, so you can control whatever you want.

havanakuba commented 7 years ago

Some parts of Script from this video can be implemented.

robermeyer commented 7 years ago

What video? I agree that the hardware exists. I was thinking SSR myself but either would work. The SSR one is available already with a plug attached. Just need to get it into the GUI so its useful. In some cases you want to turn things ON/OFF with print status. Other times it would be a simple button ON/OFF peripheral. I would be happy with button ON/OFF remote for a start.

havanakuba commented 7 years ago

https://www.youtube.com/watch?v=OQyntQLazMU

havanakuba commented 7 years ago

He is using php script run from webbrowser

robermeyer commented 7 years ago

Very nice. Now how do we get it into AstroPrint? Since I can't have a bunch of jumper wires laying around we would need a connector to attach to the Raspberry-Pi.

havanakuba commented 7 years ago

I have made connection tape using dupont connector an 6 core tape img01

havanakuba commented 7 years ago

I have used: GPIO 4 as in1 GPIO 3 as in2 GPIO 2 as in3 GPIO 17 as in4 gpio_pins copy

havanakuba commented 7 years ago

img_9919

havanakuba commented 7 years ago

And created 8 scripts based on the one from the video Two (on, off) for each relay channel

scripts
havanakuba commented 7 years ago

Here are the scripts I created

I new to github, python and coding. I feel it should be done in the different way. Sorry for that. If someone can point me what I`m doing wrong, Really appreciate some help.

scripts.zip

robermeyer commented 7 years ago

Great work. How do we get it into AstroPrint?

On Tue, Feb 21, 2017 at 1:24 PM, Havana Kuba notifications@github.com wrote:

Here are the scripts I created

I new to github, python and coding. I feel it should be done in the different way. Sorry for that. If someone can point me what I`m doing wrong, Really appreciate some help.

scripts.zip https://github.com/AstroPrint/AstroBox/files/791518/scripts.zip

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AstroPrint/AstroBox/issues/86#issuecomment-281485301, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKy3iAjG-vHHOC6GV-MUCKIk6psYbAhks5re1XwgaJpZM4Hom1O .

-- Rich

robermeyer commented 7 years ago

@CoDanny CoDanny
Is it possible for this to get moving some how? I am confident many users would appreciate the feature.

havanakuba commented 7 years ago

You encourage me to get this project moving, I did all of this today. :)

havanakuba commented 7 years ago

now php script for all channels need to be write, the problem is I don`t know php :(

robermeyer commented 7 years ago

It looks like the code is mostly JavaScript, so PH is not going to help.

On Tue, Feb 21, 2017 at 2:20 PM, Havana Kuba notifications@github.com wrote:

now php script for all channels need to be write, the problem is I don`t know php :(

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AstroPrint/AstroBox/issues/86#issuecomment-281500824, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKy3triu3g-BrLloNl2AmaGy2lE48XGks5re2MogaJpZM4Hom1O .

-- Rich

CoDanny commented 7 years ago

@robermeyer This isn't something that most of our users are even able to do. I agree though that some of our most advanced users will appreciate this. We can't add this functionality to the core platform but will certainly add it as a plugin when the plugin interface is ready

robermeyer commented 7 years ago

What's the time frame for plugin interface?

CoDanny commented 7 years ago

It's planned but we have other things to develop first. At this point I can't give you a date.

robermeyer commented 7 years ago

That's not encouraging. In our engineering, planned without a date usually means it not going to happen until somebody new comes in and changes priorities. Sounds like you are the guy the set priorities.

On Wed, Feb 22, 2017 at 11:53 AM, Daniel Arroyo notifications@github.com wrote:

It's planned but we have other things to develop first. At this point I can't give you a date.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AstroPrint/AstroBox/issues/86#issuecomment-281783475, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKy3sbUB2fDnz_GXT03iEveaFkWRQG1ks5rfJJOgaJpZM4Hom1O .

-- Rich

CoDanny commented 7 years ago

@robermeyer Yes, I am (one of them). I'm the company's CTO. It doesn't mean it won't get done. Having a plugin API is important, we realize that it will let others contribute to the product and alleviate some of the problems and limitations that our most advanced users are facing.

It's just that other things in the core product are currently in development. We're a small team and can't do everything at once. Note that the team not only works on the AstroBox but also on the AstroPrint Cloud (astroprint.com) and a few other companion apps to be released soon.

havanakuba commented 7 years ago

Hi for now I`m using this temporary solution called WEBIOPi

https://github.com/doublebind/raspi

robermeyer commented 7 years ago

For the cost of a Raspberry Pi and an AC SSR interface, its probably just a DIY project to turn ON/OFF the printer separately. It was nice having a remote interface that would go through the firewall. If I wait for this PlugIN to develop I will probably be working on my 4D printer by then and won't need it anymore. I have 2 printers so I will need 2 Raspberry PI's anyway. Whats one more :-)

I will look into the WEBIOPI myself. Thanks for the tip.

On Wed, Feb 22, 2017 at 2:22 PM, Havana Kuba notifications@github.com wrote:

Hi for now I`m using this temporary solution called WEBIOPi

https://github.com/doublebind/raspi

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AstroPrint/AstroBox/issues/86#issuecomment-281824257, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKy3mzoP0-IV_v7JBrNE2F7bKhEhfo3ks5rfLUqgaJpZM4Hom1O .

-- Rich

havanakuba commented 7 years ago

I have made custom interface to switch on/off light in my printer on raspberry pi 3 with installed astroprint on it. install python and gpio

sudo apt-get install python-dev sudo apt-get install python-pip3 sudo apt-get install python-rpi.gpio

then fallow https://github.com/doublebind/raspi

then sudo nano /etc/webiopi/config in [HTTP] change port to 8080 this step it is not essential will work without change. uncomment and change path in doc-root = /home/pi/www/

make www directory in /home /pi

using filezilla copy index.html to /home/pi/www ch1.zip ch4.zip

sudo /etc/init.d/webiopi start - to start sudo /etc/init.d/webiopi stop - to stop sudo /etc/init.d/webiopi status - to check status

sudo update-rc.d webiopi defaults - add to autostart

havanakuba commented 7 years ago

img_0083 img_0084

havanakuba commented 7 years ago

img_9927 img_9921

Austinthemighty commented 7 years ago

nice, currently i am working on a heated encloser. In order to get the current info from astroprint i am using lxml to pull the data from the web page

sabbiolino80 commented 7 years ago

What about a custom gcode to switch the relays, with a parameter to select which one and a second parameter to specify on or off

sabbiolino80 commented 7 years ago

Similar to M107 to switch the fan

MikeDabrowski commented 7 years ago

Alright guys take a look (here)[https://github.com/foosel/OctoPrint/wiki/Controlling-a-relay-board-from-your-RPi]. Changes are done to config.yaml. I did that on astro but it is not enough - the buttons does not show in right menu. So I went to /AstroBox/src/astroprint/templates/app.jinja2 (no idea what language is that - ruby?) and duplicated buttons used for shutdown and reboot. Now I think js is controlling that buttons so I'm gonna go through app.js (16k lines... yahhh) unless someone does have better idea.

Probably we could use that scripts @havanakuba wrote. I think php can't be directly inserted into that jinja files. Also I don't know if js alone can manipulate gpio. Easies way would be to invoke gpio mode 7 out somehow.

I used octoprint set up as in that link I gave here but I had issues in maintaining connection to printer itself. (relay works very nicely, I'm using 1ch one). So far astro is maintaining connection. Hope we will come up with something together.

Edit: just pasted unminified js and at the very end there is this code. I don't know how it is doing system commands like restart astrobox.

AstroBoxApp = Backbone.View.extend({
        el: "body",
        eventManager: null,
        appMenu: null,
        socketData: null,
        utils: null,
        router: null,
        connectionView: null,
        unreachableView: null,
        turnOffModal: null,
        printerProfile: null,
        events: {
            "click button.turn-off": "turnOffClicked",
            "click button.reboot": "rebootClicked",
            "click a.launch-ap": "launchAstroPrint"
        },
        initialize: function() {
            this.socketData = new SocketData;
            this.appMenu = new AppMenu;
            this.utils = new Utils;
            this.router = new AppRouter;
            this.connectionView = new ConnectionView({
                socket: this.socketData
            });
            this.printerProfile = new PrinterProfile(initial_printer_profile);
            this.eventManager = Backbone.Events;
            this.socketData.connectionView = this.connectionView;
            this.socketData.connect(WS_TOKEN);
            this.listenTo(this.socketData, "change:printing", this.reportPrintingChange);
            this.listenTo(this.socketData, "change:online", this.onlineStatusChange);
            this.listenTo(this.socketData, "change:box_reachable", this.onReachableChanged)
        },
        turnOffClicked: function() {
            this.turnOffModal || (this.turnOffModal = new TurnoffConfirmationModal);
            this.turnOffModal.open()
        },
        rebootClicked: function() {
            this.rebootModal || (this.rebootModal = new RebootConfirmationModal);
            this.rebootModal.open()
        },
        reportPrintingChange: function(b,
            c) {
            c ? (this.$(".quick-nav").hide(), this.setPrinting(), this.router.navigate("printing", {
                replace: !0,
                trigger: !0
            })) : (this.socketData.set({
                printing_progress: null,
                print_capture: null,
                paused: !1
            }, {
                silent: !0
            }), this.$(".tab-bar .left-small").show(), this.$(".quick-nav").show(), this.router.navigate("control", {
                replace: !0,
                trigger: !0
            }))
        },
        selectQuickNav: function(b) {
            var c = this.$(".quick-nav");
            c.find("li.active").removeClass("active");
            b && c.find("li." + b).addClass("active")
        },
        onlineStatusChange: function(b, c) {
            c ? this.$("#app").addClass("online").removeClass("offline") :
                this.$("#app").addClass("offline").removeClass("online")
        },
        onReachableChanged: function(b, c) {
            "reachable" != c ? setTimeout(_.bind(function() {
                "unreachable" == this.socketData.get("box_reachable") && (this.unreachableView || (this.unreachableView = new UnreachableView), this.router.selectView(this.unreachableView))
            }, this), 1E3) : this.unreachableView && this.unreachableView.hide()
        },
        setPrinting: function() {
            this.$(".tab-bar .left-small").hide();
            this.$(".quick-nav").hide()
        },
        launchAstroPrint: function(b) {
            b.preventDefault();
            initial_states.userLogged ? this.launchingAp || (this.launchingAp = !0, $.getJSON(API_BASEURL + "astroprint/login-key").done(function(b) {
                location.href = "https://www.astroprint.com/account/loginKey/" + b.login_key
            }).fail(function() {
                location.href = "https://www.astroprint.com/account/login"
            }).always(_.bind(function() {
                this.launchingAp = !1
            }, this))) : location.href = "https://www.astroprint.com/account/login"
        }
    });
MikeDabrowski commented 7 years ago

OK its in js

doTurnoff: function() {
            $.ajax({
                url: API_BASEURL + "system",
                type: "POST",
                data: {
                    action: "shutdown"
                },
                success: _.bind(function() {
                    setTimeout(_.bind(function() {
                        this.$el.addClass("done");
                        this.$el.find(".icon-off").removeClass("blink-animation")
                    }, this), 6E3)
                }, this),
                error: _.bind(function() {
                    this.$el.find(".icon-off").removeClass("blink-animation");
                    noty({
                        text: "There was an error starting turn off sequence.",
                        timeout: 5E3
                    })
                }, this)
            })
        }

Does it mean that js can control system?

robermeyer commented 7 years ago

Nice research MikeDabrowski

On Mon, Apr 10, 2017 at 2:22 PM, MikeDabrowski notifications@github.com wrote:

OK its in js

doTurnoff: function() { $.ajax({ url: APIBASEURL + "system", type: "POST", data: { action: "shutdown" }, success: .bind(function() { setTimeout(.bind(function() { this.$el.addClass("done"); this.$el.find(".icon-off").removeClass("blink-animation") }, this), 6E3) }, this), error: .bind(function() { this.$el.find(".icon-off").removeClass("blink-animation"); noty({ text: "There was an error starting turn off sequence.", timeout: 5E3 }) }, this) }) }

Does it mean that js can control system?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AstroPrint/AstroBox/issues/86#issuecomment-293082926, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKy3sqgZN5hE22H40hkdN9fNlP4SAr1ks5rup18gaJpZM4Hom1O .

-- Rich

MikeDabrowski commented 7 years ago

Ok, I fetched source code and looked it through. Good news its rather python doing system commands than js. Bad news I have no experience in python for web and have no idea where to place relevant command.

So if any of the creators could drop some hints which file to edit to place python code or system instructions we'd be very glad. Its very small change actually. @CoDanny ?

Austinthemighty commented 7 years ago

for python web programming it's basically HTML programming wrapped in python code

MikeDabrowski commented 7 years ago

Yea, but which file to edit and how to make html button perform system level action?

Austinthemighty commented 7 years ago

take a look at this https://bitbucket.org/fotosyn/fotosynlabs/raw/9d78640ca4ef8ffcea12194b8528b52ccad8b426/BerryCam/berryCam.py it may help, but not by much and this http://web2py.com/ http://web2py.com/books/default/chapter/29/13#One-step-production-deployment there https://www.instructables.com/id/Simple-and-intuitive-web-interface-for-your-Raspbe/

i havent done any web python stuff but here is some stuff on it

robermeyer commented 7 years ago

This is perfect. I just need one 3.3Volt IO to turn power on and off. $19.99 kit.
http://www.powerswitchtail.com/Pages/PSTKKit.aspx $25.99 assembled http://www.powerswitchtail.com/Pages/default.aspx image

With Octoprint supporting it already, this would seem very trivial for one of the AstroPrint Gurus.
With the adaptor available its a no brainer.

MikeDabrowski commented 7 years ago

@robermeyer Man its an overkill, simple relay module is for 1.3USD approx on ebay, works great just pay attention if its 3.3 or 5v. Problem is in astrobox not supporting custom switches. I have no time to dig deeper and other issues preventing me from using astrobox. But maybe during summer I will try to do something about it

robermeyer commented 7 years ago

I am looking for something with no exposed 110Volts. Simply connecting 2 wires to the RASpi and your ready to go. Safe and reliable. Those jumper wires on that $1.30 board don't work for me. The Youtube videos show how unreliable those jumpers are with having to debug such a trivial interface. Those $1.30 relay boards don't have a grounded plug or socket or protective case. That is fine for proof of concept. I already know it works. I want a production version 🙂 You have to have the Plug, Socket and case to make it useful and not dangerous. I have kids that like to touch shiny stuff! $20.00 is cheap if AstroPrint had 10-20 lines of code to turn it ON/OFF. I just bought another RASPi to install OCTOPRINT. I will see how well this works with this power box. AstroBox may be better in some ways but in others they are moving very slow right now.

On Fri, Apr 21, 2017 at 12:05 PM, MikeDabrowski notifications@github.com wrote:

@robermeyer https://github.com/robermeyer Man its an overkill, simple relay module is for 1.3USD approx on ebay, works great just pay attention if its 3.3 or 5v. Problem is in astrobox not supporting custom switches. I have no time to dig deeper and other issues preventing me from using astrobox. But maybe during summer I will try to do something about it

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AstroPrint/AstroBox/issues/86#issuecomment-296279854, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKy3gl9cYZN_wYwJ8n43-vColNqrhuRks5ryP3vgaJpZM4Hom1O .

-- Rich

kodacy commented 7 years ago

Fell the same need, and agree that this option should be made available has soon has possible, since it is such a simple procedure that can have so many applications (energy save, light and appliances related to the print control).

raptordemon commented 6 years ago

Hi has any progress been made on this?

CoDanny commented 6 years ago

@raptordemon No, at the moment we're busy with other things. When the AstroBox API is released this will be possible by the community

loadedsith commented 4 years ago

PSU toggling support is one of 2 plugins that made me make the conversion back to OctoPi. I miss my Astrobox, please support this sort of plugin.

jlopfri921 commented 2 years ago

PSU toggling support is one of 2 plugins that made me make the conversion back to OctoPi. I miss my Astrobox, please support this sort of plugin.

Post AstroBox GPIO turn on/off printer 3D