Build an open future with us.

Invest in Mycroft and become a community partner.

Picroft + Google Voice AIY : button & light websocket issue?


#1

Hi,

I have an issue with the button led of the Google Voice AIY.

I have got 3 different results after a new install or reboot:

  • blinking when listening which seems the normal form of operation
  • blinking all the time, not funny if your device is in your bedroom :smile:
  • off, not funny too

The first sign of led lightning occurs with “Starting up Mycroft service”.
There are different threads on button and lights but none on this issue.
Did someone work on this ?

I look at /home/pi/lights.py and find this (sorry for losing identation):

def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")

Then at the end :

if name == “main”:
websocket.enableTrace(True)
ws = websocket.WebSocketApp(“ws://localhost:8181/core”,
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.run_forever()

So, I connected to my device with ws, asked for time and read this :

{“type”: “recognizer_loop:record_end”, “context”: null, “data”: {}}
{“type”: “recognizer_loop:wakeword”, “context”: null, “data”: {“utterance”: “hey mycroft”, “session”: “ebd6dee7-6b92-448c-9cfc-fd02cd02faec”}}
{“type”: “recognizer_loop:utterance”, “context”: {“ident”: “1538292862.464371-842722306”, “client_name”: “mycroft_listener”}, “data”: {“lang”: “en-US”, “utterances”: [“what time is it”], “session”: “ebd6dee7-6b92-448c-9cfc-fd02cd02faec”}}
{“type”: “mycroft-date-time.mycroftai:handle_query_time”, “data”: {“target”: null, “confidence”: 1.0, “mycroft_date_time_mycroftaiQuery”: “what”, “mycroft_date_time_mycroftaiTime”: “time”, “intent_type”: “mycroft-date-time.mycroftai:handle_query_time”, “utterance”: “what time is it”, “tags”: [{“from_context”: false, “start_token”: 0, “end_token”: 0, “entities”: [{“match”: “what”, “data”: [[“what”, “fallback_wolfram_alpha_mycroftaiGive”], [“what”, “mycroft_date_time_mycroftaiQuery”], [“what”, “mycroft_configuration_mycroftaiGetKeyword”], [“what”, “mycroft_ip_mycroftaiquery”], [“what”, “mycroft_configuration_mycroftaiWhat”]], “confidence”: 1.0, “key”: “what”}], “match”: “what”, “key”: “what”}, {“from_context”: false, “start_token”: 1, “end_token”: 1, “entities”: [{“match”: “time”, “data”: [[“time”, “mycroft_date_time_mycroftaiTime”]], “confidence”: 1.0, “key”: “time”}], “match”: “time”, “key”: “time”}]}, “context”: {“target”: null, “client_name”: “mycroft_listener”, “ident”: “1538292862.464371-842722306”}}
{“type”: “mycroft.skill.handler.start”, “data”: {“name”: “TimeSkill.handle_query_time”}, “context”: {“target”: null, “client_name”: “mycroft_listener”, “ident”: “1538292862.464371-842722306”}}
{“type”: “speak”, “data”: {“expect_response”: false, “utterance”: “zero nine thirty four”}, “context”: {“target”: null, “client_name”: “mycroft_listener”, “ident”: “1538292862.464371-842722306”}}
{“type”: “enclosure.mouth.events.deactivate”, “data”: {}, “context”: null}
{“type”: “enclosure.mouth.display”, “data”: {“clearPrev”: false, “xOffset”: 0, “yOffset”: 0, “img_code”: “HIAAAAAAAAAAAAAA”}, “context”: null}
{“type”: “enclosure.mouth.display”, “data”: {“clearPrev”: false, “xOffset”: 24, “yOffset”: 0, “img_code”: “HIAAAAAAAAAAAAAA”}, “context”: null}
{“type”: “enclosure.mouth.display”, “data”: {“clearPrev”: false, “xOffset”: 7.0, “yOffset”: 0, “img_code”: “EIMHEEMHAA”}, “context”: null}
{“type”: “enclosure.mouth.display”, “data”: {“clearPrev”: false, “xOffset”: 11.0, “yOffset”: 0, “img_code”: “EIMBEBMHAA”}, “context”: null}
{“type”: “enclosure.mouth.display”, “data”: {“clearPrev”: false, “xOffset”: 15.0, “yOffset”: 0, “img_code”: “CIICAA”}, “context”: null}
{“type”: “enclosure.mouth.display”, “data”: {“clearPrev”: false, “xOffset”: 17.0, “yOffset”: 0, “img_code”: “EIEFEFMHAA”}, “context”: null}
{“type”: “enclosure.mouth.display”, “data”: {“clearPrev”: false, “xOffset”: 21.0, “yOffset”: 0, “img_code”: “EIMBABMHAA”}, “context”: null}
{“context”: null, “data”: {“side”: “b”}, “type”: “enclosure.eyes.blink”}
{“context”: null, “data”: {}, “type”: “recognizer_loop:audio_output_start”}
{“context”: null, “data”: {“until”: 1538292868.2138433, “code”: “3”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292868.3378432, “code”: “0”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292868.4618433, “code”: “2”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292868.5858433, “code”: “2”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292868.6685433, “code”: “3”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292868.7512434, “code”: “0”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292868.8339434, “code”: “3”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292868.9114432, “code”: “3”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292868.9889433, “code”: “2”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292869.0664432, “code”: “3”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292869.1439433, “code”: “0”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292869.2679434, “code”: “5”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292869.3919432, “code”: “6”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {“until”: 1538292869.5159433, “code”: “2”}, “type”: “enclosure.mouth.viseme”}
{“context”: null, “data”: {}, “type”: “recognizer_loop:audio_output_end”}
{“type”: “enclosure.mouth.reset”, “data”: {}, “context”: null}
{“type”: “enclosure.mouth.events.activate”, “data”: {}, “context”: null}

No message from lights.py .

I added this :

def on_message(ws, message):
print("==== message ====")

without any success.

It seems that for some reason lights.py became inactive.

Looking at /home/pi/button.py , I read this :

or better: add it to your autorun.sh like this:
python /home/pi/lights.py </dev/null &>/dev/null &
# just before:
# else
# # running from a SSH session
# echo “Remote session”
# fi

Adding this line in auto-run.sh is not necessary because it’s already in /home/pi/custom_setup.sh .


#2

Hi there @henridbr, thank you very much for reporting this.
Unfortunately I don’t have an AIY kit to replicate this so I’m going to shout out in Picroft chat channel and see if anyone else is experiencing the same symptoms on their AIY kit.


#3

Hi,

As I have said it earlier the button lights up when the device is starting services.

I am using Tjoen Mycroft with Google AIY Voice kit disk image.

Basically it’s an old install (0.9.14). With it the button lights up correctly.

After a hard reboot, the Raspberry loads the last update to 18.8.2 and then the button doesn’t light up…

I wrote a print inside lights.py and I check that on the wake word lights.py is called but the button doesn’t light.


#4

Hi @KathyReid and @tjoen

Some steps more in troubleshooting this issue.
This custom_setup.sh:

echo “Connect walkman of usb stick for music”
sudo mount /dev/sda1 /media/Walkman

#start button code
python /home/pi/lights.py </dev/null &>/dev/null &
echo “Start bouton and light”

During each boot, I had an error about a walkman device, so at first I comment the lines in custom_setup.sh. And I comment also the errors redirections in the line about lights.py:

During next boot, just before the echoed “Start bouton and light”, I get this error:

Import error: no module named websocket

So, the error occurred in the first line of lights.py

import websocket
import time
import itertools
import threading
import time
import RPi.GPIO as GPIO
import json
import subprocess

At this point I am :swimming_man: in my ocean of ignorance !
At least I know why I didn’t read errors from the light button.

It did not occured with 09.0.14 version. Picroft is now with Mycroft-core 18.8.3

Thank you for helping.


#5

mycroft-pip install websocket

That command should do the trick.


#6

Thank you @j1nx

I didn’t try that before because I receive data in my browser from: ws://192.168.0.13:8181/core
But as I know very few, it is worth to try.

mycroft-pip install websocket
Collecting websocket
Downloading https://files.pythonhosted.org/packages/f2/6d/a60d620ea575c885510c574909d2e3ed62129b121fa2df00ca1c81024c87/websocket-0.2.1.tar.gz (195kB)
100% |████████████████████████████████| 204kB 2.6MB/s
Collecting gevent (from websocket)
Downloading https://files.pythonhosted.org/packages/10/c1/9499b146bfa43aa4f1e0ed1bab1bd3209a4861d25650c11725036c731cf5/gevent-1.3.7.tar.gz (4.6MB)
100% |████████████████████████████████| 4.6MB 1.2MB/s
Requirement already satisfied: greenlet in /opt/venvs/mycroft-core/lib/python3.4/site-packages (from websocket) (0.4.15)
Building wheels for collected packages: websocket, gevent
Running setup.py bdist_wheel for websocket … done
Stored in directory: /home/pi/.cache/pip/wheels/35/f7/5c/9e8243838269ea93f05295708519a6e183fa6b515d9ce3b636
Running setup.py bdist_wheel for gevent … \

After reboot I get the same error.

Looking at the enclosure.log, there are some errors recorded at the boot time:

17:33:21.335 - mycroft.messagebus.client.ws:on_error:76 - ERROR - === ConnectionRefusedError(111, ‘Connection refused’) ===
Traceback (most recent call last):
File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_app.py”, line 168, in run_forever
host=host, origin=origin)
File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_core.py”, line 266, in connect
self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options))
File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_http.py”, line 63, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_http.py”, line 116, in _open_socket
raise err
File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_http.py”, line 105, in _open_socket
sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
17:33:21.360 - mycroft.messagebus.client.ws:on_error:83 - ERROR - Exception closing websocket: > Exception(“Uncaught ‘error’ event.”,)
17:33:21.383 - mycroft.messagebus.client.ws:on_error:76 - ERROR - === ConnectionRefusedError(111, ‘Connection refused’) ===
Traceback (most recent call last):

  • File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_app.py”, line 168, in run_forever
    host=host, origin=origin)
  • File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_core.py”, line 266, in connect
    self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options))
  • File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_http.py”, line 63, in connect
    sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
  • File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_http.py”, line 116, in _open_socket
    raise err
  • File “/opt/venvs/mycroft-core/lib/python3.4/site-packages/websocket/_http.py”, line 105, in _open_socket
    sock.connect(address)
    ConnectionRefusedError: [Errno 111] Connection refused
    17:33:21.388 - mycroft.messagebus.client.ws:on_error:83 - ERROR - Exception closing websocket: Exception(“Uncaught ‘error’ event.”,)

I don’t know if it’s the same issue or 2 different issues.


#7

Hmmm, then I am out of ideas as well. My guess is that it has to do with the move from python2 to python3.


#8

Thank you @j1nx

It’s probably the way to search.


#9

Some of the things that come to mind;

  • The error here is about closing the websocket, not necessarily opening the websocket. Obviously the issue is that Mycroft can’t connect to the websocket, but I think it’s because it can’t start because it can’t exit successfully.

  • I’m not sure where the websocket exit / cleanup code is, but that would be my guess as to the root cause.


#10

Thanks @KathyReid

There are 3 files: lights.py, button.py, mbus.py in this order.

The ws connection and exit are controlled by mbus.py

#! /usr/bin/env python
# python mbus.py localhost “mycroft.stop”

import sys
from websocket import create_connection
uri = ‘ws://’ + sys.argv[1] + ‘:8181/core’
ws = create_connection(uri)
print "Sending " + sys.argv[2] + " to " + uri + “…”
if len(sys.argv) >= 4:
data = sys.argv[3]
else:
data = “{}”

message = ‘{“type”: "’ + sys.argv[2] + ‘", “data”: "’+ data +’"}’
result = ws.send(message)
print “Receiving…”
result = ws.recv()
print “Received ‘%s’” % result
ws.close()

It seems correct as I am able to understand that.

I checked that websocket-client is installed:

mycroft-pip install websocket-client
Requirement already satisfied: websocket-client in /opt/venvs/mycroft-core/lib/python3.4/site-packages (0.32.0)
Requirement already satisfied: six in /opt/venvs/mycroft-core/lib/python3.4/site-packages (from websocket-client) (1.10.0)

Why I get from lights.py an “Import error: no module named websocket” ?

I know that you are busy but if someone could check this, knowing that it seems working fine with version core 9.0.14 . These files are stored in tjoen’s repositery: there


#11

Unfortunately I don’t have an AIY hat I’m afraid :frowning:


#12

The files in @tjoen’s repository are for Python 2.x. I have adapted them for 3.x and got them running with Mycroft 18.02. If interested I can provide the files here…


#13

Hi @Dominik

You save my day !
Please provide me your files.