Conecting to the mycroft web client

Trying to connect mycroft to the mycroft webclient by following these steps :


But facing
Traceback (most recent call last):
File “/home/abc/mycroft-core/.venv/lib/python3.6/site-packages/tornado/web.py”, line 1390, in _execute
result = self.prepare()
File “/home/abc/mycroft-core/.venv/lib/python3.6/site-packages/tornado/web.py”, line 2103, in prepare
raise HTTPError(self._status_code)
tornado.web.HTTPError: HTTP 404: Not Found
Installed tornado packages in the virtual enviroment, still facing the same issue.

Looks like that github has not been updated in a year, there has been substantial development to the mycroft core since then including the upgrade to python 3 support and support for python 2.# being discontinued. I suspect this is the source of your problem. What is it that you are trying to achieve? Maybe someone in the community can assist or point you in the right direction.

He pops in every now and then, maybe file an issue on the repo?

1 Like

Thank you for your help, I’m trying to give my bot a better user interface(very basic) by using a web client. Any other web clients that I can possibly use?
Or possibly use the port number in the config file (mycroft-core/mycroft/configuration) to use html5 to send and receive messgaes. Will that work?

@sarthak444
@KathyReid would be a good place to start as she is up to speed on all things Mycroft, if she doesn’t know she will probably know who will.:wink:

1 Like

I don’t have a lot of experience with using websockets with Mycroft, however I am documenting the MessageBus at the moment. It operates on port 8181 if that is any help?

1 Like

Here is a working websocket code sample, If it is helpful for your documents. I will be interested too in your documents once they are pulled together.

2 Likes

I do it like this:

    from websocket import create_connection, WebSocket
    from mycroft.messagebus.message import Message
    def connectToWebsocket(self):
            uri = 'ws://localhost:8181/core'
            ws = create_connection(uri)
            utt = '{"context": null, "type": "recognizer_loop:utterance", "data": {"lang": "en-us", "utterances": ["hello human, how are you?"]}}'
            ws.send(utt)
            ws.close()
2 Likes

We now have the Message Bus documented here;

3 Likes

Yeah, got it working. The answer was in the config file…
Thank you anyway!

1 Like

But I still get replies in json format(on the webserver) while my goal is to attain a UI similar to this (https://www.youtube.com/watch?v=J8NGy9UwkPI)

you need to register an event handler:

self.add_event('speak', self.yourHandler) # this will call the function/method yourHandler everytime a speak-event is triggered

def yourHandler(self, message):
    response = message.data.get("utterance") # this extracts the utterance from the event
    print(response) # prints the utterance part from the Event in CLI

hope this helps

2 Likes

I have a couple of what are probably very stupid questions.

  1. Does this have to run on the Mark I itself? I tried running the code that @pcwii provided, and it seems to work, but fails in the end. A quick nmap shows that port 8181 (from @KathyReid) isn’t open. Only port 22.

  2. On the Mark I, doing a straight up pip install of the websocket library fails because it doesn’t think pip is installed. pip is there, but in the Mycroft core virtual environment. If I just do an apt-get install python-pip, it’s wanting me to install a host of things, and I’m trying not to hose up my Mark I. Is it safe to do an apt-get install pip on these things?

I apologize in advance for these questions. I admit that I’m mucking around in things that are outside of my comfort zone and over my head for the most part. I appreciate your patience.

Never apologise for questions!

Are you able to post the error messages you get and we can dig a little deeper?

Sure, but the errors are pretty uninteresting. I’m using the code @pcwii posted last week exactly other than updating IP information to actually point to my Mark I. That’s here:

When I execute that code, I get this output after quite some time:

Traceback (most recent call last):
File “test.py”, line 22, in
send_message(‘speak, hello’)
File “test.py”, line 17, in send_message
ws = create_connection(url)
File “/usr/local/lib/python2.7/dist-packages/websocket/_core.py”, line 494, in create_connection
websock.connect(url, **options)
File “/usr/local/lib/python2.7/dist-packages/websocket/_core.py”, line 217, in connect
options.pop(‘socket’, None))
File “/usr/local/lib/python2.7/dist-packages/websocket/_http.py”, line 120, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
File “/usr/local/lib/python2.7/dist-packages/websocket/_http.py”, line 186, in _open_socket
raise error
socket.error: [Errno 110] Connection timed out

I don’t think it’s anything to do with the code, which seems pretty straight forward. I did do an nmap of the system, and the only open port is showing as 22, and if the MessageBus operates on 8181 I’m not sure how it would establish a connection from outside of the Mark I.

From what I can see here, the code is executing under Python 2.7 - is this on Linux or another type of Mycroft device?

It’s on my main computer, which is running Mint 19. It is running under Python 2.7, but the results are the same if I run it with Python 3.6, which I also have installed.

Traceback (most recent call last):
  File "test.py", line 22, in <module>
    send_message('speak, hello')
  File "test.py", line 17, in send_message
    ws = create_connection(url)
  File "/home/mike/.local/lib/python3.6/site-packages/websocket/_core.py", line 494, in create_connection
    websock.connect(url, **options)
  File "/home/mike/.local/lib/python3.6/site-packages/websocket/_core.py", line 217, in connect
    options.pop('socket', None))
  File "/home/mike/.local/lib/python3.6/site-packages/websocket/_http.py", line 120, in connect
    sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
  File "/home/mike/.local/lib/python3.6/site-packages/websocket/_http.py", line 186, in _open_socket
    raise error
  File "/home/mike/.local/lib/python3.6/site-packages/websocket/_http.py", line 170, in _open_socket
    sock.connect(address)
TimeoutError: [Errno 110] Connection timed out

I’m trying to connect to a Mark I unit, but port 8181 doesn’t seem open.

Silly question, is ssh enabled on the Device - ie have you used the button on the top to enable ssh - it seems like a silly question but I often forget to do it after a reimage.

Yea, ssh is life. There is no living without ssh. :smile:

1 Like

Hearing you!

OK, I’m not sure what the issue is here. What does a traceroute trace show?