Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote ON/OFF switch of the printer #86

Open
havanakuba opened this issue Mar 3, 2016 · 46 comments
Open

Remote ON/OFF switch of the printer #86

havanakuba opened this issue Mar 3, 2016 · 46 comments

Comments

@havanakuba
Copy link

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

@havanakuba havanakuba changed the title Remote ON/OFF switch of the 3d printer Remote ON/OFF switch of the printer Mar 3, 2016
@robermeyer
Copy link

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
Copy link
Author

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
Copy link
Author

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

@havanakuba
Copy link
Author

Some parts of Script from this video can be implemented.

@robermeyer
Copy link

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
Copy link
Author

@havanakuba
Copy link
Author

He is using php script run from webbrowser

@robermeyer
Copy link

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
Copy link
Author

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

@havanakuba
Copy link
Author

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

@havanakuba
Copy link
Author

img_9919

@havanakuba
Copy link
Author

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

scripts

@havanakuba
Copy link
Author

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
Copy link

robermeyer commented Feb 21, 2017 via email

@robermeyer
Copy link

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

@havanakuba
Copy link
Author

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

@havanakuba
Copy link
Author

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

@robermeyer
Copy link

robermeyer commented Feb 21, 2017 via email

@CoDanny
Copy link
Contributor

CoDanny commented Feb 22, 2017

@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
Copy link

What's the time frame for plugin interface?

@CoDanny
Copy link
Contributor

CoDanny commented Feb 22, 2017

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

@robermeyer
Copy link

robermeyer commented Feb 22, 2017 via email

@CoDanny
Copy link
Contributor

CoDanny commented Feb 22, 2017

@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
Copy link
Author

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

https://github.com/doublebind/raspi

@robermeyer
Copy link

robermeyer commented Feb 22, 2017 via email

@havanakuba
Copy link
Author

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
Copy link
Author

img_0083
img_0084

@havanakuba
Copy link
Author

img_9927
img_9921

@Austinthemighty
Copy link

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
Copy link

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
Copy link

Similar to M107 to switch the fan

@MikeDabrowski
Copy link

MikeDabrowski commented Apr 10, 2017

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
Copy link

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
Copy link

robermeyer commented Apr 11, 2017 via email

@MikeDabrowski
Copy link

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
Copy link

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

@MikeDabrowski
Copy link

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

@robermeyer
Copy link

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
Copy link

@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
Copy link

robermeyer commented Apr 21, 2017 via email

@kodacy
Copy link

kodacy commented Apr 26, 2017

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
Copy link

Hi has any progress been made on this?

@CoDanny
Copy link
Contributor

CoDanny commented Jan 2, 2018

@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
Copy link

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.

@AstroPrint AstroPrint deleted a comment from robermeyer May 25, 2020
@jlopfri921
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants