Sunspot Home

Using Alexa to control my LAN devices

- more notes for backup and a bad memory - -
These notes will be upgraded at random times
This first hack is WORKING but not yet tidy, , , ,

Objective - Use Alexa to control IFTTT linked to the Maker Channel to send GET http requests
to CGI scripts running on a local Raspberry Pi webserver.
Then use the Raspberry Pi to perform actions on other LAN devices

Now that the Maker channel exists on IFTTT the possibilities to control home made IOT devices are now infinite !!!!

For example here is a wav file delivered to the Pi after asking Alexa for a report - see below for UK accent!

BUT - the Rasbian developers have thought up even more tricks to stop web page requests perform any actions of use to makers.
I thought I had tamed Jessie but the new Pixel "upgrade" has set me back again.
After many hours of Googling I am still not able to use an http CGI GET request to run a root bash script that does something to control a LAN device.
None of the tricks I used here work now.

So I built a back door with Blassic basic. (much simpler than Python if you do very simple things not very often - and have a personal memory problem)
I need to run root CGI scripts, I tried Apache2 but gave up.(sudo apt-get purge Apache2)

I tried Lighttpd and managed to get a simple cgi script to show a "hello world from CGI" web page.
However I could not link to root scripts using any of the ways that worked before.
I could run gpio because this does not need root. But I need root scripts !!!!

Eventually I found that I could run a Blassic program and this could save the string received as a GET payload to my ramdisk.
So I set up another Blassic program running from boot time as root to keep looping and reading the ramdisk text file containing the string command (and deleting it after use) .

Now we have the command string in the root environment and anything is possible again.

To test the GET method web server I re-modified a set of scripts I have used often (originals found in a Sweex router)

xxxxx.cgi
pg-default.sh
xxxxx.html
pg-gpio.sh
xxxxx.bas

This web address is seen after clicking on longreport
http://my_No-Ip_web_address_and_port_number/cgi-bin/xxxxx/xxxxx.cgi?page=gpio&string=longreport
the web page looks like this -

The address above is given to the Maker channel from Amazon Alexa via If This Then That (IFTTT)
Maker sends it to my No-Ip fixed address and has the same effect as my clicking on longreport

xxxxx.bas saves the text longreport to my ramdisk

alexa_actions.bas runs from boot time in a loop and reads the current Alexa request alexa_command$

OPEN "/var/www/ramdisk/alexa_link.txt" FOR INPUT AS #1 : INPUT #1,alexa_command$ : CLOSE #1

Data is grabbed by curl using bash scripts like
get_4b0_potpounds_latest.sh

The text to speech is created by Google using
speech100plus.sh (Many thanks to Dan Fountain)

My Alexa Dot feeds a cheap Chinese amplifier board from eBay and a couple of old Sony speakers
I plan to put all the above on Pi Zero and share the same amplifier. So my "Alexa" will reply with an American accent - but it is great text to speech !
I discovered that you can ask for an english accent - hear this
Change the us to GB here in speech100plus.sh
mpg123 -q "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=$NEXTURL&tl=En-GB"
For a longer pause after a full stop I cut the speech into sparate segments.


I joined IFTTT and read about secret keys to use the Maker channel - but saw no request for these

I go to https://ifttt.com/my_applets and find I am logged in. (a Cookie ?)
You will be asked to create an acount on that link if you have none.

I see

If you click on New Applet click the + and choose Alexa
For choose a trigger choose "Say a specific phrase"

When you get to Configure fill in


If You say "Alexa trigger office light on", then make a web request
What phrase? . . . . . office light on
URL . . . . . . . . . . . . . http://myaddressandporthere/cgi-bin/xxxxx/xxxxx.cgi?page=gpio&string=office_light_on
Method . . . . . . . . . . GET
Content Type - leave text/plain default
Body - none

I do not yet know what "Body" wants - leave it as is - IT WORKS!

 


Please email me if you want to swap notes

SUNSPOT HOME