Jump to content

UM3 API and CORS


frejete

Recommended Posts

Posted · UM3 API and CORS

Hello,

I wanted to write a quick dashboard that would show the video feed, the loaded materials and the printer status (free, printing with completion percentage, need to remove the finished print) for our Ultimaker 3 printer at the office so that everyone can see at a glance what's up without standing up from their desk or launching Cura.

This would be pretty simple with a simple HTML and Javascript webpage but I can't call the API because of CORS restrictions. I don't really want to install a server with a server side script to proxy my calls to the API.

Would it be possible to add unrestricted CORS headers to the API server

Access-Control-Allow-Origin: *

, or have JSONP support?

  • Link to post
    Share on other sites

    Posted · UM3 API and CORS

    hi frejete,

    All the read information requests should not be locked down or require authentication.

    So a pure information page can be done easily.

    Changing things about the printer will require authentication though.

    We'll want something like this for ourselves as well but then having some login would still be required, we don't want to make an inherently unsecure machine, like some internet of things machines are these days.

    Besides that you can even use the username password prompt you get right now with proper authentication data if you want to... (requires some Linux knowledge or python scripting).

    your browser can save it for you even if it is some unreadable string...

  • Link to post
    Share on other sites

    Posted · UM3 API and CORS

    CORS with * disables all authentication, and thus breaks our authentication implementation. We could set it for pages that do not require authentication, but that gets a bit more complex pretty fast.

    However, maybe a better deal for all of us. We currently don't have a dashboard implementation scheduled yet. But I do want a landing page. So I wouldn't mind including your dashboard implementation in the next firmware release as just the default landing page.

  • Link to post
    Share on other sites

    • 1 month later...
    Posted · UM3 API and CORS

    A screen with the temperature graph, camera feed, printer status and maybe log data would be ideal. Especially when you have multiple printers that are not close to your desk. All of these things are now scattered over multiple pages and cura.

  • Link to post
    Share on other sites

    Posted · UM3 API and CORS

    I'm also trying to build a dashboard, in SharePoint, so I don't have the ability to enable CORS on the server. It would be great if the API had the ability to return JSONP to get around this.

  • Link to post
    Share on other sites

    Posted · UM3 API and CORS

    There is a way to add CORS support to the printer without breaking authentication. You do not need to respond with the

    Access-Control-Allow-Origin : *

    header instead you can reply with an Access-Control-Allow-Origin header that copies the request Origin (which will always be provided if it matters for CORS). I added the following code to /usr/share/griffin/griffin/interface/http/server.py and it now allows CORS:

    # At the end of __init__:
    
            # Add CORS support
            self.after_request(Server.allow_cors)
    
    # At the end of Server:
    
        @staticmethod                                           
        def allow_cors(response):                                    
            if "Origin" in flask.request.headers:                                                                                
                response.headers["Access-Control-Allow-Origin"] = flask.request.headers["Origin"]
                response.headers["Vary"] = "Origin"
            return response                              

    Then you have to restart the HTTP server with 

    systemctl restart griffin.interface.http

    or just restart the machine.

     

    It would be nice if this showed up in the next firmware update so we don't have to go into developer mode to do it.

     

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
      • Ultimaker Cura 5.6 stable released
        Cura now supports Method series printers!
         
        A year after the merger of Ultimaker and MakerBotQQ, we have unlocked the ability for users of our Method series printers to slice files using UltiMaker Cura. As of this release, users can find profiles for our Method and Method XL printers, as well as material profiles for ABS-R, ABS-CF, and RapidRinse. Meaning it’s now possible to use either Cura or the existing cloud-slicing software CloudPrint when printing with these printers or materials
        • 48 replies
    ×
    ×
    • Create New...