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

    CustomHttpEndpoint script not working

    Scheduled Pinned Locked Moved
    DSF Development
    4
    15
    695
    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.
    • j.dewitundefined
      j.dewit
      last edited by

      Fresh install on the PI:

      Board: Duet 3 MB6HC (MB6HC)
      DSF Version: 3.4.1
      Firmware: RepRapFirmware for Duet 3 MB6HC 3.4.0 (2022-03-15)

      After Running the CustomHttpEndPoint the http status code returned after the request is 500.

      When closing the script a 404 error is returned, so routing seems to work. But the request is not properly handled.

      I have also tried to create a custom HTTP endpoint using the c# library but there I am also running into the same issue.

      jay_s_ukundefined 1 Reply Last reply Reply Quote 0
      • jay_s_ukundefined
        jay_s_uk @j.dewit
        last edited by

        @j-dewit i don't believe SBC mode supports HTTP calls like rr_status yet. this is coming in 3.5
        you need to use this rest API https://github.com/Duet3D/DuetSoftwareFramework/wiki/REST-API

        Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

        1 Reply Last reply Reply Quote 0
        • j.dewitundefined
          j.dewit
          last edited by

          @jay_s_uk The feature is for SBC:

          https://github.com/Duet3D/DuetSoftwareFramework#customhttpendpoint

          This should grant me an option to create a custom HTTP endpoint for custom sofware.

          jay_s_ukundefined 2 Replies Last reply Reply Quote 0
          • jay_s_ukundefined
            jay_s_uk @j.dewit
            last edited by

            @j-dewit oh, i missed that one. sorry

            Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

            1 Reply Last reply Reply Quote 0
            • jay_s_ukundefined
              jay_s_uk @j.dewit
              last edited by

              @j-dewit one for @chrishamm then

              Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

              j.dewitundefined 1 Reply Last reply Reply Quote 0
              • j.dewitundefined
                j.dewit @jay_s_uk
                last edited by

                @jay_s_uk Thanks, I am trying to figure out where DSF puts it's logs on the SBC. But so far no luck on debugging.

                Falcounetundefined 1 Reply Last reply Reply Quote 0
                • Falcounetundefined
                  Falcounet @j.dewit
                  last edited by Falcounet

                  @j-dewit said in CustomHttpEndpoint script not working:

                  @jay_s_uk Thanks, I am trying to figure out where DSF puts it's logs on the SBC. But so far no luck on debugging.

                  You can get logs using sudo journalctl -xe -u duetcontrolserver

                  I used CustomHttpEndPoint using the dsf-python library without issue. Here is an example.

                  j.dewitundefined 1 Reply Last reply Reply Quote 1
                  • j.dewitundefined
                    j.dewit @Falcounet
                    last edited by j.dewit

                    @falcounet I will try that example perhaps I have more luck with that one. Are you running the same firmware or a newer version?

                    I did manage to get the faul that is occuring:

                    Sep 07 10:54:39 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Connections[39] Connection id "0HMKGLC886QRH" accepted.
                    Sep 07 10:54:39 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Connections[1] Connection id "0HMKGLC886QRH" started.
                    Sep 07 10:54:59 duet3 DuetWebServer[665]: DuetWebServer.Services.ModelObserver[0] New number of custom HTTP endpoints: 0
                    Sep 07 10:54:59 duet3 sudo[3741]: pam_unix(sudo:session): session closed for user root
                    Sep 07 10:55:03 duet3 sudo[3813]:       pi : TTY=pts/0 ; PWD=/opt/dsf/bin ; USER=root ; COMMAND=./CustomHttpEndpoint
                    Sep 07 10:55:03 duet3 sudo[3813]: pam_unix(sudo:session): session opened for user root by pi(uid=0)
                    Sep 07 10:55:04 duet3 DuetWebServer[665]: DuetWebServer.Services.ModelObserver[0] New number of custom HTTP endpoints: 1
                    Sep 07 10:55:04 duet3 DuetWebServer[665]: DuetWebServer.Services.ModelObserver[0] Registered HTTP GET endpoint via /machine/custom-http-endpoint/demo
                    
                    
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[6] Connection id "0HMKGLC886QRH" received FIN.
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Connections[39] Connection id "0HMKGLC886QRI" accepted.
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Connections[1] Connection id "0HMKGLC886QRI" started.
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Connections[10] Connection id "0HMKGLC886QRH" disconnecting.
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7] Connection id "0HMKGLC886QRH" sending FIN because: "The client closed the connection."
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Hosting.Diagnostics[1] Request starting HTTP/1.1 GET http://10.0.0.2/machine/custom-http-endpoint/demo - -
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[2] All hosts are allowed.
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1000] No candidates found for the request path '/machine/custom-http-endpoint/demo'
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware[2] Request did not match any endpoints
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Connections[2] Connection id "0HMKGLC886QRH" stopped.
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: DuetWebServer.Authorization.SessionKeyAuthenticationHandler[8] AuthenticationScheme: SessionKey was successfully authenticated.
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HMKGLC886QRG", Request id "0HMKGLC886QRG:00000005": An unhandled exception was thrown by the application. System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (13): Permission denied /run/dsf/custom-http-endpoint/demo-GET.sock    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)    at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)    at DuetWebServer.Middleware.HttpEndpointConnection.Connect(String socketPath) in /home/christian/Duet3D/DuetSoftwareFramework/src/DuetWebServer/Middleware/HttpEndpointConnection.cs:line 31    at DuetWebServer.Middleware.CustomEndpointMiddleware.InvokeAsync(HttpContext context) in /home/christian/Duet3D/DuetSoftwareFramework/src/DuetWebServer/Middleware/CustomEndpointMiddleware.cs:line 97    at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Server.Kestrel.Connections[9] Connection id "0HMKGLC886QRG" completed keep alive response.
                    Sep 07 10:55:49 duet3 DuetWebServer[665]: Microsoft.AspNetCore.Hosting.Diagnostics[2] Request finished HTTP/1.1 GET http://10.0.0.2/machine/custom-http-endpoint/demo - - - 500 0 - 31.3982ms
                    

                    So the first thing is strange since it is telling that no endpoint is matched. And then there is a permission error on the unix socket that is created.

                    1 Reply Last reply Reply Quote 0
                    • j.dewitundefined
                      j.dewit
                      last edited by

                      Upping the permissions on the /run/dsf/custom-http-endpoint/demo-GET.sock solves the issue.

                      I am running the test scrips as root, perhaps it is better to use a different user? Or is there soms sort of permission mismatch during the installation?

                      chrishammundefined 1 Reply Last reply Reply Quote 0
                      • chrishammundefined
                        chrishamm administrators @j.dewit
                        last edited by

                        @j-dewit Ideally the HTTP endpoint application should run as dsf user but pi may work, too. It is possible to run it as root but then you need to adjust the permissions of the UNIX socket file so that the dsf user/group can access it.

                        Duet software engineer

                        j.dewitundefined 2 Replies Last reply Reply Quote 1
                        • j.dewitundefined
                          j.dewit @chrishamm
                          last edited by

                          @chrishamm That makes sense, just tested with the pi user, but that also is giving permission errors.

                          Perhaps it is a good idea to update the documentation how to properly run these testing scripts.

                          1 Reply Last reply Reply Quote 0
                          • j.dewitundefined
                            j.dewit @chrishamm
                            last edited by

                            @chrishamm

                            I tried running the script as a service with the dsf user. But now the DuetControlServer is dropping the connection due to missing permissions.

                            Sep 07 14:23:25 duet3 DuetControlServer[3666]: [error] IPC#67: Failed to find plugin permissions for pid #6017
                            Sep 07 14:23:25 duet3 DuetControlServer[3666]: [warn] IPC#67: Terminating connection due to insufficient permissions
                            

                            I am running a stand-alone c# application on the pi and don't want to use the plugins 'yet' due to easy-er debugging. What is the best way to get these permissions working?

                            Falcounetundefined 1 Reply Last reply Reply Quote 0
                            • Falcounetundefined
                              Falcounet @j.dewit
                              last edited by

                              @j-dewit It may be AppArmor restricting access.
                              You may probably need ot set it in complain mode for debugging purposes or temporarily disable it (from the DSF config) to check if that's your issue.

                              chrishammundefined 1 Reply Last reply Reply Quote 0
                              • chrishammundefined
                                chrishamm administrators @Falcounet
                                last edited by chrishamm

                                @falcounet there is no apparmor profile for DSF tools so I doubt it. But I'll check if I can make file permissions for HTTP endpoints simpler in the next DSF version.

                                Duet software engineer

                                j.dewitundefined 1 Reply Last reply Reply Quote 0
                                • j.dewitundefined
                                  j.dewit @chrishamm
                                  last edited by

                                  @chrishamm I got the service working by running as root user using a umask 0000. That way the created socket is readable by dsf user.

                                  There must be a better way to do this, but sadly I am not an expert on user management in linux.

                                  But for development this works.

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post
                                  Unless otherwise noted, all forum content is licensed under CC-BY-SA