Amazon ALEXA Lists Exercise – Put’em on Paper…

4.3 Edge server PHP code

Your EDGE server must be able to run PHP code. I have a LAMP running latest PHP 7.0 and this tiny exercise script named edge_script_printer.php fits perfectly.

  • Server is exposed at my dyndns via HOSTNAME:443 with a self signed certificate.
  • Script is therefore available at https://$DYNDNSHOST$/edge_script_printer.php . Obviously, if you put this into another path, adapt the python glue code above.
  • Script has the following GET or POST parameters:
    • secret : same as above in Python script
    • listName : UTF8 URL encoded name for the list, 1-32 characters
    • listItems : URL encoded JSON list of items, e.g. ["tomatoes", "mozarella"] becomes  %5B%22tomatoes%22%2C%20%22mozarella%22%5D%C2%A0 . Note that on older PHP5 json implementations you cannot use an apostroph, but must use double quotes as shown here.

Aaaand here’s the EDGE server code, nothing fancy:

Note that you’re required to change two things:

  1. line 3: use your own secret here from above (python script).
  2. line 28: replace with your raspberry pis internal, static IP address or host name.

The script just passes on listName  and listItems  as-is to the internal print server and waits for a reply.

4.4 Testing

As an intermediate step, we can test at this point by uncommenting the five lines in the PHP script above.

  • Tell ALEXA to put tomatoes on your shopping list
  • Ask ALEXA to start „list printer“, this should result in a listName="shopping list"  and listItems=["tomatoes"]  dumped to the edge_script_printer_dump.txt  file.

You can use Amazon CloudWatch to track any errors in the Python Script.

4 Kommentare zu “Amazon ALEXA Lists Exercise – Put’em on Paper…”

1.   Kommentar von Tom
Erstellt am 09. Dezember 2018 um 22:40 Uhr.

Hi,
great post.
Could please tell which thermal printer you have used?
The amazon link isnt‘ working anymore.
Thanks

2.   Kommentar von McSeven
Erstellt am 10. Dezember 2018 um 20:27 Uhr.

hi, Thanks. The one I used isn’t available on Amazon anymore, but any USB receipt printer should work… Just look for what mike24’s ESC/POS library is supporting and buy one of those models… Best, Christoph

3.   Kommentar von Tom
Erstellt am 11. Dezember 2018 um 20:53 Uhr.

Thanks for the reply. This product list on github helps a lot.
One further question: Could you really delete the original shopping list with the skill? In your video you use the original „Einkaufsliste“ so you could also delete this one per API? In your code for the lambda it is „shopping list“ and not the original code snipped?

Danke und Gruß
Tom

4.   Kommentar von McSeven
Erstellt am 12. Dezember 2018 um 20:23 Uhr.

hi, well, the Einkaufsliste is used by the ALEXA language model. it translates into „shopping list“ in the skill. Therefore the difference… Cheers.

Einen Kommentar hinterlassen