alexa-pi / AlexaPi

Alexa client for all your devices! # No active development. PRs welcome # consider https://github.com/respeaker/avs instead
MIT License
1.33k stars 396 forks source link

Magicmirror - MM-AlexaPi - HTTPS #509

Closed pablousavilla closed 3 years ago

pablousavilla commented 3 years ago

Hi Team,

Thanks for the great software! It works amazingly!

Working with a MagicMirror, I did run into an issue when I set it in HTTPS. In that scenario, AlexaPi was not able to connect to it.

I manage to produce a work around by editing 2 files:

config.yaml under the group "magicmirror:", I added a new variable _mmsecure that can either be true or false and should have the same value as useHttps in Magicmirror's config.js

    mm_secure: true | false

depending on where you installed AlexaPi, you would need to find the file, for the default installation /opt/AlexaPi/src/alexapi/device_platforms/magicmirrorplatform.py

add:

    import ssl

search for _self.hb_timer = self._pconfig['hbtimer'] and append this right under it:

    self.secure = self._pconfig ['mm_secure']
    if self.secure:
        self.mm_prefix = "https://"
        self.mm_myssl = ssl.create_default_context();
        self.mm_myssl.check_hostname=False
        self.mm_myssl.verify_mode=ssl.CERT_NONE
    else:
        self.mm_prefix: "http://"

then change the assignment of the variable "address" to (there are 2 of them, change both):

    address = (self.mm_prefix + self.mm_host + ":" + self.mm_port + "/alexapi?action=AVSSTATUS&status=" + status)

Finally, you need to append some parameters to the call urlopen() in both ocurrances, to look like this:

    response = urlopen(address, context=self.mm_myssl).read()

And... that should do the trick.

I hope it works for you as it did for me!