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

    Basic Telnet Connection Help

    Scheduled Pinned Locked Moved
    General Discussion
    4
    11
    1.0k
    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.
    • btmclainundefined
      btmclain
      last edited by btmclain

      Hi all,

      I am hoping to read basic telnet messages sent through M118. I am running my Duet in standalone mode and it is directly connected to my pc. I am trying to use the socket library in python to listen for messages, but I am not having any luck. My basic config.g file contains the following:

      global g = 0
      M586 P2 S1 R23
      M553 P255.255.255.0
      M552 S1 P192.168.2.80
      

      I am using the following macro to try to test the telnet messages:

      set global.g = 0
      
      while global.g < 20
      	M118 P4 S"message"
      	set global.g = global.g + 1
      	G4 S3
      

      And I am trying to use the following super basic Python script to listen:

      import socket
      import sys
      
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      
      server_address = ('localhost', 23)
      sock.bind(server_address)
      sock.listen(1)
      
      while True:
          print(sys.stderr)
          print('waiting for a connection')
          connection, client_address = sock.accept()
      

      If anybody could help me out I would definitely appreciate it. Thanks in advance!

      alankilianundefined dc42undefined 2 Replies Last reply Reply Quote 0
      • alankilianundefined
        alankilian @btmclain
        last edited by alankilian

        @btmclain
        I don't get what you're trying to do.

        Where are you running the python script? On your PC?

        If so, it's listening, but there's nothing that is going to try to connect to your PC.

        Maybe you want to run a python script on your PC that connects to the Duet's telent port?

        SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

        btmclainundefined 2 Replies Last reply Reply Quote 0
        • btmclainundefined
          btmclain @alankilian
          last edited by

          @alankilian Hi thanks for the quick reply. To be honest I am not really sure what I am doing.

          Yes I am running the python script from my PC.

          I was under the impression that the Duet would send a message to the specified port on my pc. I am obviously mistaken. Let me try to connect to a telnet port on the duet and see how that goes.

          alankilianundefined 1 Reply Last reply Reply Quote 0
          • btmclainundefined
            btmclain @alankilian
            last edited by

            @alankilian so I used the following line to try to connect to the machine:

            sock = socket.create_connection((duet_host, 23), timeout=10)
            

            I am getting this response: [WinError 10061] No connection could be made because the target machine actively refused it

            Is there a security setting within the duet that is causing this to happen?

            1 Reply Last reply Reply Quote 0
            • alankilianundefined
              alankilian @btmclain
              last edited by alankilian

              @btmclain

              Looking HERE
              I got this working:

              #!/usr/bin/env python3
              
              import socket
              
              HOST = '192.168.0.104'  # The server's hostname or IP address
              PORT = 23           # The port used by the server
              
              with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
                  s.connect((HOST, PORT))
                  data = s.recv(1024)
                  print('Received', repr(data))
                  data = s.recv(1024)
                  print('Received', repr(data))
              

              192.168.0.104 is the IP address of my duet and I got several "message" printed from Python.

              I'm not a Python guy, but you might get farther with this.

              SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

              btmclainundefined Mastermarkundefined 2 Replies Last reply Reply Quote 1
              • btmclainundefined
                btmclain @alankilian
                last edited by

                @alankilian That worked! Thank you very much for the help. I will run with it from here

                alankilianundefined 1 Reply Last reply Reply Quote 0
                • alankilianundefined
                  alankilian @btmclain
                  last edited by

                  @btmclain Excellent! Glad to be of service.

                  SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

                  1 Reply Last reply Reply Quote 0
                  • dc42undefined
                    dc42 administrators @btmclain
                    last edited by

                    @btmclain which Duet are you using, and which firmware version?

                    You can run a program such as Putty on the PC to test the Telnet connection.

                    Duet WiFi hardware designer and firmware engineer
                    Please do not ask me for Duet support via PM or email, use the forum
                    http://www.escher3d.com, https://miscsolutions.wordpress.com

                    btmclainundefined 2 Replies Last reply Reply Quote 0
                    • btmclainundefined
                      btmclain @dc42
                      last edited by

                      @dc42 We are using a Duet 3 MB 6HC with the latest firmware, 3.3 I believe? Alan's answer was perfect, it is exactly what I was looking for.

                      1 Reply Last reply Reply Quote 0
                      • btmclainundefined
                        btmclain @dc42
                        last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • alankilianundefined alankilian referenced this topic
                        • alankilianundefined alankilian referenced this topic
                        • Mastermarkundefined
                          Mastermark @alankilian
                          last edited by

                          @alankilian i know this topic is old but ive been looking into the same thing im trying to grab the macros from the duet but ive had no joy so far using python

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