Git Product home page Git Product logo

Comments (5)

MitchBradley avatar MitchBradley commented on June 12, 2024

The websocket port number is 1 more than the http port, so if the http port is at its default value of 80, you will need to connect on port 81 for the websocket.

After that you can send Grbl commands like over a serial connection.

from fluidnc.

hamidb avatar hamidb commented on June 12, 2024

Thanks for the info.
I tried and I was able to establish a connection. But I am still not able to get the steppers move.
Here is my new attempt:

import websocket
import _thread
import time

def on_message(ws, message):
    print('in message ', message)

def on_error(ws, error):
    print('error: ', error)

def on_close(ws, close_status_code, close_msg):
    print("### closed ###")

def on_open(ws):
    def run(*args):
      ws.send('$HX\n')
      time.sleep(1)
      ws.close()
      print("thread terminating...")
    _thread.start_new_thread(run, ())

if __name__ == "__main__":
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp("ws://10.88.111.15:81",
                              on_open=on_open,
                              on_message=on_message,
                              on_error=on_error,
                              on_close=on_close)
    ws.run_forever()

And here is the log:

--- request header ---
GET / HTTP/1.1
Upgrade: websocket
Host: 10.88.111.15:81
Origin: http://10.88.111.15:81
Sec-WebSocket-Key: UOnb7DZkNEkQVYO6FMqXVQ==
Sec-WebSocket-Version: 13
Connection: Upgrade


-----------------------
--- response header ---
HTTP/1.1 101 Switching Protocols
Server: arduino-WebSocketsServer
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Accept: Uwdjp+mfNTLrZjyYd6gwT9WJwFM=
-----------------------
++Rcv raw: b'\x89\x00'
++Rcv decoded: fin=1 opcode=9 data=b''
++Sent raw: b'\x81\x84,\xad1&\x08\xe5i,'
++Sent decoded: fin=1 opcode=1 data=b'$HX\n'
++Sent raw: b'\x8a\x80pF(\xd6'
++Sent decoded: fin=1 opcode=10 data=b''
++Rcv raw: b'\x81\x0cCURRENT_ID:0'
++Rcv decoded: fin=1 opcode=1 data=b'CURRENT_ID:0'
in message  CURRENT_ID:0
++Rcv raw: b'\x81\x0bACTIVE_ID:0'
++Rcv decoded: fin=1 opcode=1 data=b'ACTIVE_ID:0'
in message  ACTIVE_ID:0
++Sent raw: b"\x88\x82'\x10\xd8\xf4$\xf8"
++Sent decoded: fin=1 opcode=8 data=b'\x03\xe8'
### closed ###

from fluidnc.

MitchBradley avatar MitchBradley commented on June 12, 2024

I found a bug in the websocket handling. The bug is now fixed in the WebSockets branch.

Here is simple test showing it basically working.

PS C:\Users\wmb\Documents\GitHub\fluidterm> python
Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import websocket
>>> ws = websocket.WebSocket()
>>> ws.connect("ws://192.168.2.150:81")
>>> ws.send("$\n")
8
>>> print(ws.recv())
CURRENT_ID:0
>>> print(ws.recv())
ACTIVE_ID:0
>>> print(ws.recv())
PING:0
>>> print(ws.recv())
PING:0
>>> print(ws.recv())
b'[HLP:$$ $+ $# $S $L $G $I $N $x=val $Nx=line $J=line $SLP $C $X $H $F $E=err ~ ! ? ctrl-x]\nok\n'
>>>

from fluidnc.

hamidb avatar hamidb commented on June 12, 2024

Thanks for the fix. I confirm that it solved the issue for Linux as well.

from fluidnc.

MitchBradley avatar MitchBradley commented on June 12, 2024

Fixed by #142

from fluidnc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.