[closed] Picroft + Google Voice AIY : button & light

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 .

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.

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.

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.

mycroft-pip install websocket

That command should do the trick.

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.

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

Thank you @j1nx

It’s probably the way to search.

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.

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

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

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…

1 Like

Hi @Dominik

You save my day !
Please provide me your files.

you can find the files here: https://github.com/domcross/PiCroft-AIY.git

please note that I had these running under Picroft 18.02 (see instruction in lights.py). For 18.08 there is a new startup mechanism and I did not take the time yet to figure out how to get it running there.

Hi @Dominik, @KathyReid,

Thank you for the files.
I felt myself stupid when seeing the difference between them is the “print”.

It didn’t solve the issue :face_with_raised_eyebrow:.

I am beginning with Python and I learn every day.
I read somewhere that import failure occurs when the file is not in the python path.
When I check for python path I get this:

pi@picroft:/ $ python -m site
sys.path = [
. ‘/’,
. ‘/usr/lib/python2.7’,
. ‘/usr/lib/python2.7/plat-arm-linux-gnueabihf’,
. ‘/usr/lib/python2.7/lib-tk’,
. ‘/usr/lib/python2.7/lib-old’,
. ‘/usr/lib/python2.7/lib-dynload’,
. ‘/usr/local/lib/python2.7/dist-packages’,
. ‘/usr/lib/python2.7/dist-packages’,
. ‘/usr/lib/pymodules/python2.7’,
]
USER_BASE: ‘/home/pi/.local’ (exists)
USER_SITE: ‘/home/pi/.local/lib/python2.7/site-packages’ (doesn’t exist)
ENABLE_USER_SITE: True

Mycroft is upgraded to 18.8.3 but it seems that it is always looking for Python 2 libraries.
I am investigating that but ideas are welcome !

I am looking into this and trying to understand the code @Dominik provided. I were thinking the right way to go were making a skill that did the stuff. But I am not a great programmer and I have to learn as I go.
But as far as I understand the mycroft cmponents it is easy to hock into events in a skill. And when that is posible the only thing missing is to read button and turn on and of light. First part i think I managed but second part gives me headace :wink:

My not working code is on my GitHub https://github.com/andlo/picroft-google-aiy-voicehat-skill

And now I think the skill actual is working….It turns on light when listning, and if button is short pressed he starts listning, and if long press he stops whatever is going on.

msm install https://github.com/andlo/picroft-google-aiy-voicehat-skill gives me following error:

Could not find a version that satisfies the requirement time (from -r /opt/mycroft/skills/picroft-google-aiy-voicehat-skill.andlo/requirements.txt (line 2)) (from versions: ) No matching distribution found for time (from -r /opt/mycroft/skills/picroft-google-aiy-voicehat-skill.andlo/requirements.txt (line 2))

it seems like there is no pip-package with name “time”…

Ohhh sorry - ill remove that :slight_smile:

I did change it, and also did a rename of the repo - it is now at