100% found this document useful (1 vote)
14 views

Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi John Allwork - The full ebook version is just one click away

The document promotes the book 'Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi' by John Allwork, which covers creating Alexa skills and designing IoT devices with Raspberry Pi. It includes links to download the book and other related titles on ebookmass.com. The book is structured in two parts, focusing on Alexa communication and Raspberry Pi IoT applications.

Uploaded by

zrktleijer29
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
14 views

Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi John Allwork - The full ebook version is just one click away

The document promotes the book 'Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi' by John Allwork, which covers creating Alexa skills and designing IoT devices with Raspberry Pi. It includes links to download the book and other related titles on ebookmass.com. The book is structured in two parts, focusing on Alexa communication and Raspberry Pi IoT applications.

Uploaded by

zrktleijer29
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Visit ebookmass.

com to download the full version and


explore more ebook or textbook

Programming Voice-controlled IoT Applications with


Alexa and Raspberry Pi John Allwork

_____ Click the link below to download _____


https://ebookmass.com/product/programming-voice-controlled-
iot-applications-with-alexa-and-raspberry-pi-john-allwork/

Explore and download more ebook or textbook at ebookmass.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Programming the Raspberry Pi, Third Edition: Getting


Started with Python Simon Monk

https://ebookmass.com/product/programming-the-raspberry-pi-third-
edition-getting-started-with-python-simon-monk/

Hacking Electronics: Learning Electronics with Arduino and


Raspberry Pi, 2nd Edition Simon Monk

https://ebookmass.com/product/hacking-electronics-learning-
electronics-with-arduino-and-raspberry-pi-2nd-edition-simon-monk/

Raspberry Pi Electronics Projects for the Evil Genius 1st


Edition Norris

https://ebookmass.com/product/raspberry-pi-electronics-projects-for-
the-evil-genius-1st-edition-norris/

Arduino and Raspberry Pi Sensor Projects for the Evil


Genius 1st Edition Chin

https://ebookmass.com/product/arduino-and-raspberry-pi-sensor-
projects-for-the-evil-genius-1st-edition-chin/
Programming Kotlin Applications: Building Mobile and
Server-Side Applications With Kotlin Brett Mclaughlin

https://ebookmass.com/product/programming-kotlin-applications-
building-mobile-and-server-side-applications-with-kotlin-brett-
mclaughlin/

Integration of Mechanical and Manufacturing Engineering


with IoT R. Rajasekar

https://ebookmass.com/product/integration-of-mechanical-and-
manufacturing-engineering-with-iot-r-rajasekar/

Simple and Efficient Programming with C#: Skills to Build


Applications with Visual Studio and .NET 2nd Edition
Vaskaran Sarcar
https://ebookmass.com/product/simple-and-efficient-programming-with-c-
skills-to-build-applications-with-visual-studio-and-net-2nd-edition-
vaskaran-sarcar/

Simple and Efficient Programming with C# : Skills to Build


Applications with Visual Studio and .NET 2nd Edition
Vaskaran Sarcar
https://ebookmass.com/product/simple-and-efficient-programming-with-c-
skills-to-build-applications-with-visual-studio-and-net-2nd-edition-
vaskaran-sarcar-2/

Beginning Programming with Python For Dummies 3rd Edition


John Paul Mueller

https://ebookmass.com/product/beginning-programming-with-python-for-
dummies-3rd-edition-john-paul-mueller/
books
books books

Programming

Programming Voice-controlled IoT Applications • Dr John Allwork


Voice-controlled
IoT Applications Programming Voice-controlled
with Alexa and Raspberry Pi IoT Applications
with Alexa and Raspberry Pi
The book is split into two parts: the first part covers creating Alexa skills
and the second part, designing Internet of Things and Smart Home devices
using a Raspberry Pi.
tials
John Allwork graduated from
Sheffield University where he
import creden
The first chapters describe the process of Alexa communication, opening
an Amazon account and creating a skill for free. The operation of an Alexa developed an interest in computers

# constants
and gained his MSc at UMIST.

T%H:%M:%S.00Z
skill and terminology such as utterances, intents, slots, and conversations After two years working for ICL as
m - % d
are explained. Debugging your code, saving user data between sessions, a design engineer, he returned to
UTC_FORMAT = “ % Y - %
a z o n . c o m / a u t h/o2/token”
m
https://api.a
S3 data storage and Dynamo DB database are discussed. UMIST where he graduated with a
PhD in ‘Design and Development of
Microprocessor Systems’.
TOKEN_URI = “
In-skill purchasing, enabling users to buy items for your skill as well as

s constants
certification and publication is outlined. Creating skills using AWS Lambda
# Token acces
He worked for several years in
and ASK CLI is covered, along with the Visual Studio code editor and technical support and as manager
n t i a l s . k e y [ ‘ CLIENT_ID’]
rede T’]
CLIENT_ID = c ‘CLIENT_SECRE
local debugging. Also covered is the process of designing skills for visual in electronics distribution, working
closely with Intel engineers and
e n t i a l s . k e y [
= cred
displays and interactive touch designs using Alexa Presentation Language.
CLIENT_SECRET
later designing Inmos Transputer
systems.
The second half of the book starts by creating a Raspberry Pi IoT “thing”
to control a robot from your Alexa device. This covers security issues and Having taught electronics at
s_to ken():
methods of sending and receiving MQTT messages between an Alexa Manchester Metropolitan University,
he retired in 2011 but retained
def get_acces
device and the Raspberry Pi.
his interest in electronics and
= {
token_params t_credentials
”,
programming. His other occupations
Creating a smart home device is described including forming a security consist of traveling, walking,
p e ” : “ c l i e n
profile, linking with Amazon, and writing a Lambda function that gets geocaching and spending time on “grant_ty a c t i ve_events”,
e x a : : p r o
“scope”: “al
triggered by an Alexa skill. Device discovery and on/off control is his allotment.

LIENT_ID,
demonstrated.
l i e n t _ i d ” : C
“c
Next, readers discover how to control a smart home Raspberry Pi display
n t _ s e c r e t ” : CLIENT_SECRET
from an Alexa skill using Simple Queue Service (SQS) messaging to “clie
switch the display on and off or change the color.
A node-RED design is discussed from the basic user interface right up to
}
configuring MQTT nodes. MQTT messages sent from a user are displayed Elektor International Media
on a Raspberry Pi. www.elektor.com
token_headers
= {
o n / j s o n ; c h a r set=UTF-8”
”: “applicati
A chapter discusses sending a proactive notification such as a weather “Content-Type
alert from a Raspberry Pi to an Alexa device. The book concludes by
}
explaining how to create Raspberry Pi as a stand-alone Alexa device.
I , h e a d e r s = t oken_headers
s
Dr John Allwork
ts.post(TOKEN
_UR
n s e = r e q u e
respo

SKU20400_COV_Programming Voice-controlled IoT Applications_v02.indd Alle pagina's 16-01-2023 11:08


● This is an Elektor Publication. Elektor is the media brand of
Elektor International Media B.V.
PO Box 11, NL-6114-ZG Susteren, The Netherlands
Phone: +31 46 4389444

● All rights reserved. No part of this book may be reproduced in any material form, including photocopying, or
storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this
publication, without the written permission of the copyright holder except in accordance with the provisions of the
Copyright Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licencing Agency
Ltd., 90 Tottenham Court Road, London, England W1P 9HE. Applications for the copyright holder's permission to
reproduce any part of the publication should be addressed to the publishers.

● Declaration
The Author and Publisher have used their best efforts in ensuring the correctness of the information contained in
this book. They do not assume, and hereby disclaim, any liability to any party for any loss or damage caused by
errors or omissions in this book, whether such errors or omissions result from negligence, accident, or any other
cause.
All the programs given in the book are Copyright of the Author and Elektor International Media. These programs
may only be used for educational purposes. Written permission from the Author or Elektor must be obtained before
any of these programs can be used for commercial purposes.

● British Library Cataloguing in Publication Data


A catalogue record for this book is available from the British Library

● I SBN 978-3-89576-531-5 Print


ISBN 978-3-89576-532-2 eBook

● F irst edition
© Copyright 2023: Elektor International Media B.V.
Editor: Alina Neacsu
Prepress Production: Jack Jamar | Graphic Design, Maastricht

Elektor is part of EIM, the world's leading source of essential technical information and electronics products for pro
engineers, electronics designers, and the companies seeking to engage them. Each day, our international team develops
and delivers high-quality content - via a variety of media channels (including magazines, video, digital media, and social
media) in several languages - relating to electronics design and DIY electronics. www.elektormagazine.com

●4
Contents

Contents

About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Chapter 1 Alexa History and Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14


1.1 Alexa voice service and AWS Lambda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2 Pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3 Alexa skills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4 Supported programming languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.5 Terminology – Invocation, Utterances, Intents and Slots . . . . . . . . . . . . . . . . . . 16
1.5.1 Alexa Wake word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.5.2 Invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.5.3 Utterances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.5.4 Intents and requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.5.5 Slots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.5.6 Interaction model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5.7 Endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5.8 Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.6 Skill Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.7 Session attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.8 Request and response JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.9 Blueprint skills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.11 References: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Chapter 2 Creating your Amazon Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23


2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2 Create your Amazon account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Your skills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.4 Hosting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Chapter 3 Creating an Alexa Skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28


3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.2 Your first skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

●5
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

3.2.1 The interaction model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29


3.2.2 Choose a method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2.3 The Invocation Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2.4 The Intents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2.5 The code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.3 Testing your skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.4 Skill I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.4.1 Skill request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.4.2 Skill response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.4.3 Speech Synthesis Markup Language (SSML) . . . . . . . . . . . . . . . . . . . . . . . 43
3.5 Code editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.5.1 Edit the HelloWorldIntentHandler code . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.5.2 Add some debug code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.6 Test your code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3.7 Utility code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3.8 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.9 Node.js differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.10 Node.js debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Chapter 4 Slots and Dialogs, Saving Session Data . . . . . . . . . . . . . . . . . . . . . . . . . . 52


4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.2 Slots in action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.3 Slot skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.3.1 Invocation Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.4 Skill flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.5 Add the intent to our skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.6 Evaluate your model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.6.1 The JSON editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.7 Accessing the slot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.8 The code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.8.1 Test your skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.9 Session attributes - saving slot values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.9.1 Remember their name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.10 Dialog delegation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4.11 The Birthday code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.12 Handling Yes and No intents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.13 Multiple Yes / No sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

●6
Contents

4.14 AMAZON.SearchQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.15 ASK SDK Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.16 Intent error logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.17 Language understanding NLU and Automatic speech recognition ASR . . . . . . . . 82
4.18 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

Chapter 5 S3 Storage and DynamoDB Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83


5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.2 Local storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.3 Persistent attributes, DynamoDB and S3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5.3.1 Code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.3.2 DynamoDB database storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.4 Request and response interceptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.5 DynamoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.6 S3 storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
5.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

Chapter 6 Certification and Publishing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99


6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6.2 Adding further languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6.3 Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
6.4 Availability and Beta Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
6.5 Beta Tester . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
6.6 Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
6.7 Submission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
6.8 Post Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
6.9 Analytics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
6.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
6.11 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

Chapter 7 Creating Skills with Lambda and ASK CLI . . . . . . . . . . . . . . . . . . . . . . . . 107


7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.1.1 AWS Lambda skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.2 ASK CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
7.3 Visual Studio code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
7.4 Local debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
7.4.1 Add Alexa debugger configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
7.4.2 Test your Alexa skill in VS code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

●7
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

7.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124


7.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

Chapter 8 Alexa Presentation Language – APL . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125


8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
8.2 APLA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
8.2.1 APLA components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
8.3 Datasources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.4 APLA datasource example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.5 Adding an APLA reprompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
8.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
8.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

Chapter 9 APL Visual Multimodal Responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136


9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
9.2 Creating an APL Visual Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
9.3 Visual Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
9.4. APL component example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
9.5 Using the Authoring Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
9.6 Integrating APL and code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
9.6.1 Check for screen support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
9.7 APL Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.7.1 Standard Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.7.2 Media Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.7.3 User-defined commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.7.4 Execute Commands directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.8 Responsive components and Alexa Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
9.9 Converting Text to speech – using Transformers . . . . . . . . . . . . . . . . . . . . . . . 151
9.9.1 Transformer APL design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9.9.2 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
9.9.3 Using the ExecuteDirective command . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
9.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.11 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

Chapter 10 Alexa In-skill Purchasing (ISP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158


10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
10.2 Create your ISP skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

●8
Contents

10.3 Accessing your ISP code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161


10.4 Retrieve in-skill products, get their information and purchase. . . . . . . . . . . . . . 164
10.5 Produce detail and purchase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
10.6 Purchase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
10.6.1 Failed Purchase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.6.2 Refunds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

Chapter 11 Progressive Response - Accessing the Internet . . . . . . . . . . . . . . . . . . . 179


11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.2 Steps to Send a Progressive Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.3 Progressive response example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.3.1 Code response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.4 asyncio, async and await - awaiting a web response . . . . . . . . . . . . . . . . . . . . 183
11.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

Chapter 12 Creating a Raspberry Pi IoT Thing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184


12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
12.2. Create a Raspberry Pi IoT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
12.2.1 a) Create our ‘Thing’ and its certificates . . . . . . . . . . . . . . . . . . . . . . . . 184
12.2.1 b) Thing’s endpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
12.2.1 c) Transfer the certificates to your Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
12.2.2 Create and run the Python code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
12.2.3 Send messages to your Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
12.2.4 Create an Alexa-Hosted Skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
12.2.5 Test the skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
12.3 Add intents to the Alexa skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
12.4 Control the robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
12.5 Add intent handlers to the skill code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
12.6 Modify your code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
12.6.1 Modify your Pi code - LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
12.6.2 Modify your Pi code - explorerhat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
12.7 Test your robot or LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
12.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

Chapter 13 Smart Home Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201


13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

●9
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

13.2 Alexa Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201


13.3 Login with Amazon (LWA) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
13.3.1 Create a security profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
13.4 Create your Smart Home Skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
13.5 Create a Lambda function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
13.6 Lambda skill code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
13.7 Test your Lambda function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
13.8 Link the function to the skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
13.9 Configure account linking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
13.10 Enable and Link the skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
13.11 Clean up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
13.12 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
13.13 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
13.14 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

Chapter 14 Controlling a smart home raspberry Pi with SQS . . . . . . . . . . . . . . . . . . 214


14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
14.2 Create an SQS Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
14.3 Raspberry Pi SQS code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
14.4 Create a Smart Home skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
14.5 Create the function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
14.6 Create a security profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
14.7 Configure the smart home skill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
14.8 Add the function code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
14.9 Test the function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
14.10 Discover your device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
14.11 Test from an Alexa device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
14.12 Clean up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
14.13 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
14.14 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

Chapter 15 IoT, Pi and Node-RED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225


15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
15.2 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
15.3 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
15.4 Running node-RED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
15.5 Node-RED user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

● 10
Contents

15.6 First flow design - Hello world . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228


15.7 Hardware I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
15.7.1 Add an input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
15.8 Using the Sense Hat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
15.9 Node-RED dashboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
15.10 Sense Hat output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
15.11 IoT - Receiving MQTT messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
15.12 Create a new IoT thing for MQTT communication. . . . . . . . . . . . . . . . . . . . . . 242
15.12.1 Subscribe to a topic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
15.13 Node-RED IoT Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
15.14 Receiving MQTT messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
15.15 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

Chapter 16 Proactive Events – Sending Raspberry Pi Alexa Notifications . . . . . . . . . 250


16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
16.2 The Lambda function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
16.3 Send a notification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
16.4 Code to get the access token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
16.5 Send the notification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
16.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
16.7 References: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261

Chapter 17 Raspberry Pi as a Stand-alone Alexa Device . . . . . . . . . . . . . . . . . . . . . 262


17.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
17.2 Raspberry Pi setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
17.3 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
17.3.1 Register your AVS device with Amazon . . . . . . . . . . . . . . . . . . . . . . . . . 263
17.3.2 Download and install the AVS SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
17.3.3 Run and authorize the sample app . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
17.4 Use the sample app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
17.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
17.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271

Chapter 18 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272


18.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273

● 11
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

About the Author

Dr. John Allwork was born in 1950 in Kent, England and became interested in electronics
and engineering at school. He went to Sheffield University on their BEng Electrical and
Electronic Engineering course. There he developed an interest in computers and continu-
ed his education on an MSc course in Digital Electronics and Communication at UMIST.
After two years working for ICL as a design, commissioning and test Engineer he returned
to UMIST where he graduated with a Ph.D. in ‘Design and Development of Microprocessor
Systems’.

He worked for several years in technical support and as a manager in electronics distribu-
tion, working closely with Intel Application Engineers and followed this with design work
using the Inmos Transputer systems.

Having taught at Manchester Metropolitan University he retired in 2011 but has kept up
his interest in electronics and programming as well as his other occupation of travelling,
walking, geocaching and spending time on his allotment.

● 12
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Introduction

This book is aimed at anyone who wants to learn about programming for Alexa devices
and extending that to Smart Home devices and controlling hardware, in particular the
Raspberry Pi.

It covers Alexa programming concepts from the basic concepts of Alexa Voice service, the
interaction model and the skill code which runs on AWS (Amazon Web Services) Lambda.

It takes the reader through all stages of creating skills to certification and publishing,
including writing skills that involve in-skill purchasing. It discusses different ways of crea-
ting skills, then moves on to creating visual skills using APL (Alexa Presentation Langua-
ge) for screen-based Alexa devices.

The book then moves on to cover different ways of controlling hardware including the
Internet of Things and Smart Home devices. There are interfaces with the Raspberry Pi
using MQTT and SQS communication, displaying on the Pi using Node-RED and Python
code.

Although mostly based on Python, Node.js examples or links are also provided. The full
code is provided in a separate document.

Please note that Alexa skill development, the developer console and APL versions have
changed since writing this book, so please bear with the author if there are slight diffe-
rences.

I do not pretend to know all there is about Alexa and Raspberry Pi programming – they
seem to advance faster than I can follow! I have a background in hardware and software
design. I am sure that there are areas where some programmers may be offended by my
code and that there may be better ways to write it, but I have written and tried all the
examples and know they work. I hope the examples will spur you on to find solutions to
your own problems. Should you need more information then please try the online help
and the Raspberry Pi or Alexa forums: alexa.design/slack is particularly good. There are
plenty of programmers out there willing to help solve your problems, often extremely
quickly; certainly faster than I would get back to you!

I wish to thank my friends for encouraging me, especially Dr. Hugh Frost, Andy Marsh
and Dr. John Nichols; the Alexa staff: in particular Jeff Nunn, Jeff Blankenburg and Ryan J
Lowe; helpers on the alexa.design/slack group, including Andy Whitworth; subscribers of
my YouTube and GitHub channels who have made encouraging comments; and the many
anonymous people on the internet, forums, blogs and websites who have answered many
questions, not just my own – keep up the good work. Not least of all I would like to thank
my wife Penny, for supporting me throughout.

And of course, you for buying the book!

● 13
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

Chapter 1 • Chapter 1 Alexa History and Devices

Alexa is the virtual voice assistant and Echo is the device.


The standard Amazon Echo device general release was in 2015. In 2019, newer versions
were released, with more rounded designs and better audio.
Amazon Echo Dot was released in 2016 with a smaller design than the standard Echo. Va-
rious releases and designs, including a kid’s version, have continued to the 5th generation
with a clock and improved LED display in 2022.

In 2017, Amazon released a combination of the Dot and Show, called the Echo Spot. In
the same year, the Echo Show was released and featured a slanted, 7-inch touchscreen,
camera and speaker. This later changed to a 10-inch screen (Echo Show 10), and more
recently, added a 360-rotating display.

The Echo Show 5 came in 2019, (2nd gen in 2021), as well as Echo Show 8 and an Echo
Show 15 in 2021 designed for wall mounting.

There are other devices too, including the Button, Flex, Input, Look and recently the Astro
robot.

Here are some of my devices (not including smart devices). From the top: Echo Show 8,
Fire TV stick, Echo Auto, my original Echo dot, and the Echo Spot.

● 14
Chapter 1 ● Alexa History and Devices

Even though many devices have a screen, you should always design for ‘voice first’.

1.1 Alexa voice service and AWS Lambda


Alexa Voice Service is Amazon’s cloud service that processes the audio, determines the
appropriate action (AVS) and returns a response to the device. For the skill to produce
the appropriate response, designers need to implement two major parts: the interaction
model and the skill code which runs on AWS (Amazon Web Services) Lambda.

The interaction model is what your users say and how they communicate with your skill.
AWS Lambda is a serverless, event-driven computing service that lets you run your code.
Lambda can be triggered by many AWS services and you only pay for what you use.

When a user interacts with an Echo device, AVS sends a request to the skill which is run-
ning on AWS Lambda. The skill replies with a response that is turned into a speech and/
or visual response back to the user.

1.2 Pricing
Although there are charges for AWS Lambda, the AWS Lambda free tier includes one
million free requests per month and 400,000 GB-seconds of compute time per month, as
well as 500 Mb storage. As you can see, this is more than enough for a beginner. For more
information, see https://aws.amazon.com/lambda/pricing/

For developers whose skills use more than this, Amazon provides Promotional Credits
which reward those who build cloud-hosted applications, software, or tools for sustaina-
bility-related work.
For FAQ see reference 1.

1.3 Alexa skills


There are a few different types of Alexa skills2. You may already have realized that a skill
communicating with an Alexa device is different from one switching on your lights or tel-
ling you there’s someone at your front door.

● 15
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

At the moment, there are 15 different types of Alexa skills.


The more common ones are:

Skill Function Skill Type Description


Automotive Pre-built and Custom Automotive applications
Custom Custom Voice and visual (APL) applications
Flash briefing Pre-built Provide news and short content information
Games Custom Voice and visual driven game skills
Music Pre-built Skills to control audio content
Smart Home Pre-built Skills to control smart home devices
Video Pre-built Control video devices and content

We’ll be concentrating on Custom skills. Blueprint pre-built skills are also available and
easy to develop but have reduced options for user experience. We’ll also study smart
home skills, of course.

1.4 Supported programming languages


AWS Lambda natively supports Java, Go, PowerShell, Node.js, C#, Python, and Ruby
code. This book will mainly use Python, but it also provides code snippets and links for
Node.js.

1.5 Terminology – Invocation, Utterances, Intents and Slots


As with learning anything new, there is new terminology to be understood. You will soon
meet (or may already have met) Invocation, Utterances, Intents and Slots.

1.5.1 Alexa Wake word


This is the word used to start your Alexa device listening to your command.
Currently, there are five wake words: ‘Alexa’ (the default), ‘Amazon’, ‘Echo’, ‘Computer’
and ‘Ziggy’. You can change these for your devices, but not invent new ones.

1.5.2 Invocation
The ‘invocation’ is the phrase used to trigger your skill, e.g.: ‘Alexa, open Johns’ weather
skill’ or ‘Alexa, launch my cooking skill’.

1.5.3 Utterances
Utterances are the phrases that your user says to make a request. There can be many
ways to achieve the same result, e.g.: What’s the time? What’s the time now? What time
is it? – you will have to think of as many possible ways that your user can interact with
your skill. Nevertheless, Alexa will build your model and try to find similar utterances.

All the possible ways to do this can be difficult to describe (considering, for instance, how
many different ways and types of pizza someone might order), so Amazon has recently
announced Alexa Conversations to help with this. For more information, see reference 3.

● 16
Chapter 1 ● Alexa History and Devices

1.5.4 Intents and requests


The utterances are linked to one intent in the code. For instance, all the ‘time’ utterances
would be linked to the same intent, e.g., GetTimeIntent, and this would trigger a GetTi-
meIntent function in our skill code.

There are two types of Intents:

• Built-in Intents
- Standard built-in intents: These are provided by default by Amazon that every skill
must have, e.g.: AMAZON.StopIntent, AMAZON.CancelIntent, AMAZON.Fallback-
Intent, etc. and include: AMAZON.YesIntent, and AMAZON.NoIntent, intents for
screen control (e.g., scroll up/ down/ left / right) and media intents (pause, repeat,
resume), and also an AMAZON.SendToPhoneIntent. You can see these when you
add an intent, and select “Use an existing intent from Alexa’s built-in library”
- The Alexa Skills Kit also provides a library of specific built-in intents and includes
intents such as Actor intents, Books, Calendar, LocalBusiness, Music, TV, Series,
WeatherForecast, etc.

These intend to add functionality to your skill without you having to provide any sample
utterances. For example, the WeatherForecast includes a search action (What is), an ob-
ject (WeatherForecast), location (London) and date (tomorrow) .
We won’t cover them in this book, see:

https://developer.amazon.com/en-US/docs/alexa/custom-skills/built-in-intent-library.html

• Custom Intents

These are created as required for the skill (e.g., GetTimeIntent)


If you use an Amazon template, the code for the built-in intents is provided for you.
There are three types of requests that the skill can send:

• A Launch request that runs when our skill is invoked (as a result of the user saying,
‘Alexa open …’ or ‘Alexa, launch ...’).
• An Intent request which contains the intent name and variables passed as slot values.
• A SessionEnded request, which occurs when the user exits the skill, or there is an
unmatched user’s response (although you may be able to trap this out with AMAZON.
FallbackIntent).

This information is all packaged and sent as a request (and returned as a response) as a
JSON file. We’ll look at the JSON code later.

1.5.5 Slots
A slot is a variable that contains information that is passed to an intent. The user might
say ‘What’s the time in London’. Here ‘London’ (or Paris or Rome) is passed as a slot
variable to the intent code.

● 17
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

Amazon provides built-in slot types, such as numbers, dates and times, as well as built-
in list types such as actors, colors, first names, etc. In the previous example, we could use
AMAZON.GB_CITY which provides recognition of over 15,000 UK and world-wide cities
used by UK speakers.

However, some of these slots are being deprecated (including AMAZON.GB_CITY in favour
of AMAZON.CITY), so check. The full list is covered at ‘List Slot Types:

https://developer.amazon.com/en-US/docs/alexa/custom-skills/slot-type-reference.html#list-slot-types

Alexa slot types fall into the following general categories:

• Numbers, Dates, and Times


• Phrases
• Lists of Items

Developers can create custom slots for variables that are specific to their skill.
When we define our utterances, slots are shown in curly braces: {city}, e.g.:

Example:

Intent GetTimeIntent
Utterance What is the time in
Slot {city}

Utterances can have many slots and slot types.

The GetTimeIntent will trigger a function in your skill (which you might sensibly call Get-
TimeIntentFunction).

Slots are used to pass data from your VUI (voice user interface) to your program. As an
example, we might have an Alexa skill that asks for your name.

The VUI might go like this:

User: “Alexa, Open What’s my name”


(Invoke the skill – the launch request executes)
Alexa: “Welcome, please tell me your name”
User: “My name is John” (“John” is passed in a slot to myName intent)
Alexa: “Hello John”
(Your intent picks John from the slot passed to it and responds)

● 18
Chapter 1 ● Alexa History and Devices

At this point, the slot data is lost unless you save it. You can save data in a temporary
folder but more often data is stored in session attributes, you will find out later.

1.5.6 Interaction model


The combination of the utterances and their related intents and slots make up the inter-
action model. This needs to be built by the developer console, and in doing so Alexa may
recognize further utterances similar to those you have defined.

1.5.7 Endpoints
The endpoint is where your code is hosted. You can choose an Amazon-hosted, AWS
Lambda ARN (Amazon Resource Name) site or host it yourself on an HTTPS site that you
manage.

If you choose an AWS site, it will give you an ID beginning arn:aws:lambda and look
like: arn:aws:lambda:<region>:function:<functionID>. You skill also has an ID looking
something like this: amzn1.ask.skill.a0093469-4a50-4428-82e6-abcde990fgh3.

1.5.8 Regions
If using an AWS-hosted site, you should host your code in a region near to your user.
We’ll see that there are lots of regions, but for some skills currently only North Virginia
is available.

1.6 Skill Sessions


The period that your skill runs for is called a session. A skill session begins when a user
invokes your skill and Alexa sends your skill a request. Your skill receives the request and
returns a response for Alexa to speak to the user.

If the shouldEndSession parameter is ‘true’ the skill terminates, otherwise, the session
remains open and expects the user to respond. If no user input occurs, a reprompt is
sent if included in the code. If the user still doesn’t respond (after about 8 seconds), the
session ends 4.

Skill connections and progressive responses may override these rules. For example, if
a skill has to get further information from another source, e.g., when your taxi will be
available, or pizza delivered.

1.7 Session attributes


Session attributes are used to hold data during a session, for example, your user’s name.
When the session finally ends, the data is lost. To prevent this from happening, data can
be stored permanently in persistent attributes. This can be held in a DynamoDb database
which is provided as one of the AWS services and easily accessed using an Alexa-Hosted
Skill. With an Alexa-Hosted Skill, you can build your model, edit your code and publish
your skill all from within the developer console.

● 19
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

1.8 Request and response JSON


We saw in the figure above how the request is sent from the user (Alexa Voice Service)
to your code and how the response is returned from your code.
This data is passed in a JSON format. JSON (JavaScript Object Notation) is a lightweight
data-interchange format. It is easy for humans to read and write and easy for machines
to parse and generate” 5

The basic JSON request contains information on the active session, the context, the sys-
tem information on the application (ID), user, deviceID, and the request itself:

{
“version”: “1.0”,
“session”: {
( ..session parameters)
}
“context”: {
( ..information on the Alexa device)
}
“System”: {

“request”: {
“type”: “IntentRequest”,
“requestId”: “amzn1.echo-api.request.745d…9a”,
“locale”: “en-GB”,
“timestamp”: “2022-04-14T09:27:01Z”,
“intent”: {
“name”: “HelloWorldIntent”,
“confirmationStatus”: “NONE”
}
}
The reply JSON contains is the response speech and reprompt, as well as the state
of the EndSession and session attributes.
{
“body”: {
“version”: “1.0”,
“response”: {
“outputSpeech”: {
“type”: “SSML”,
“ssml”: “<speak>Welcome, you can say Hello or Help.</speak>”
},
“reprompt”: {
“outputSpeech”: {
“type”: “SSML”,
“ssml”: “<speak>Welcome, you can say Hello or Help.</speak>”
}
},

● 20
Chapter 1 ● Alexa History and Devices

“shouldEndSession”: false,
“type”: “_DEFAULT_RESPONSE”
},
“sessionAttributes”: {},
“userAgent”: “ask-python/1.11.0 Python/3.7.12”
}
}

The response can get more complicated if there is a dialog session occurring (i.e., if the
program hasn’t enough information to complete the intent request and has to ask for
more).

We’ll look at the information passed in the JSON request and response and how to extract
it in a later chapter.

1.9 Blueprint skills


Alexa provides blueprint skills, where you can ‘fill in the blanks’ to make your skill. These
are worth looking at for some fun and information presenting skills.

The current categories are: At home, Kids recommended, Learning and knowledge, Fun
and Games, Storyteller, Greetings and Occasions, Communities and Organizations, and
Business 6. We won’t cover them here.

● 21
Programming Voice-controlled IoT Applications with Alexa and Raspberry Pi

1.10 Summary
We’ve seen how the Alexa devices have developed from the original voice-only device to
screen-based and robot devices, how the Alexa Voice service works and looked at termin-
ology – Invocation, Utterances, Intents and Slots. Finally, we looked at a skill session and
how data is passed and saved during a session and between sessions.

In the next chapter, we’ll see how to set up an Alexa account before moving on to our
first Alexa skill.

1.11 References:
1. https://aws.amazon.com/lambda/faqs/
2. https://developer.amazon.com/en-US/docs/alexa/ask-overviews/list-of-skills.html
3. https://www.youtube.com/watch?v=1nYfRvg976E
4. https://developer.amazon.com/en-US/docs/alexa/custom-skills/
manage-skill-session-and-session-attributes.html
5. https://www.json.org/json-en.html
6. https://blueprints.amazon.com

● 22
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Other documents randomly have
different content
“Got a little cold and the company doctor told me to
stay out for a while,” answered the whittler, gravely.
“What’s on your mind today, anything in particular?”

“I want to tell you something,” said Jimmie Carson,


sitting down on the edge of the box as Terry made room
for him. “You know that old man over in the cabin? The
man named Vancouver?”

“Yes, I know who he is. Why?”

“Well, what do you think, Mr. Mackson? He isn’t lame at


all!”

Terry stopped his whittling abruptly and looked keenly


at Jimmie. “How do you know that?” he demanded.

“I heard the Hydes say so,” was the reply. “They are
going over there tonight and kill him or something!”

The whittling ceased for good. “The Hydes!” ejaculated 181


Terry. “How did they know?”

“Listen, I was over at the Hydes with my father this


morning,” said the boy, his eyes serious and grave.
“While Pop was talking to old man Hyde I heard the
sons talking in the barn. They didn’t know that I was
right outside on our wagon, and I heard them plainly.
They said that one of them had seen the man sneak
into his cabin late last night, and they found out that he
wasn’t any cripple. Seems that one of the Hydes was
driving home from some place and he saw the ghost
sneak into the cabin. Then he looked in under a window
and saw the ghost get back into his chair, so they knew
that old man was playing ghost. Can you imagine that,
Mr. Mackson?”
“No, I can’t,” returned Terry gravely.

“So they said they was going to go to the cabin tonight


and just about kill that old man. I thought at first I’d tell
Pa, but I was scared to, so I come up here to tell you
fellows about it. I don’t think that old man ought to be
hit by those big bully Hydes, do you?”

“No, sir,” said Terry, with emphasis. “Jimmie boy, I’m


glad you told me this. Come along to the colonel; we
must tell him.”

The colonel was keenly interested in the news. “Thank 182


you for telling us this, my boy,” he smiled down at the
rugged lad. “This old man is a wicked fellow to go
around scaring people out of their wits, but just as you
say he shouldn’t be hit by those Hydes. Mr. Mackson,
pass the word to the special patrol to be ready to go
with me to the cabin as soon as darkness comes
tonight.”

“Very well, Colonel,” said Terry. “I’m glad you are going
along, because I feel that this is likely to be a fairly
tough situation.”

They left the tent and Terry went to hunt up the other
boys, first swearing little Jimmie to secrecy. “Don’t
breath a word of it,” he told the boy. “We want to save
this old man from a severe beating and we also want to
capture him for his part in the business that has been
going on around here. So it will be the best thing if you
keep very quiet about it.”

“I will, Terry,” promised the lad.

The others soon knew what was expected of them. Just


before they started out they met in the tent of the
colonel.

“Mr. Vench and Mr. Douglas, I want you to start right 183
away for Rideway and get the sheriff,” ordered the
colonel. “We can’t arrest this man ourselves, but he
must do it. It may be that we shall have trouble with
the Hydes, and anyway, the sheriff is always saying that
we interfere with his affairs on the Ridge. You may have
trouble with the sheriff, but if you do just tell him that
your colonel requests him to come to the cabin.”

“Very well, sir,” Douglas responded, and he and Vench


went out.

“We will take side arms with us,” said the colonel,
buckling on a revolver belt. “We won’t have to use
them, I trust, but at least we’ll be prepared.”

When the others of the Ghost Patrol had equipped


themselves they set out with the colonel for the cabin
over the hill. Those in the camp saw them go and much
speculation went around as to the purpose of the
expedition. The camp itself was in order for any
emergency, with double guards posted and the major in
charge.

Vench and Douglas had obtained a good start and they


felt it would not be long before they returned with the
sheriff, if he could be persuaded to come. The others
swung on toward the little cabin at a rapid pace,
topping the rise and bearing down on it.

“Somebody’s at home,” Don said, as they came in sight.


“There are lights in the windows.”

“Yes, but look! There are the Hydes!” cried Terry,


pointing.
Into the patch of light from one of the small windows a 184
burly figure stepped and another joined it. A third figure
proclaimed the father. There was a word of planning
between them and then one of the sons raised his foot
and kicked the window deliberately out. With that action
he jumped right through the opening and landed in the
room. A moment of silence followed and then the front
door was opened. Promptly the father and the other son
walked in and the door was shut.

“Just in time,” proclaimed the colonel, grimly. “Let us


hustle, boys.”

They ran down the rest of the slope, the doughty


colonel in front, and came to the cabin in a short time.
The colonel threw himself against the door, which had
not been very well secured, and it opened under his
impact. Followed by Don, Terry, Jim and Jordan, the
colonel shot into the room.

In one corner crouched the supposed invalid, his face


pale and his hands grasping a stout stick. Facing him,
with brutal expressions on their surly faces, stood the
Hydes. The oldest son held a heavy horsewhip in his
hands, and it was evident that he was just going to use
it when the cadet party burst in.

At sight of the cadets the expressions on their faces 185


changed. Surprise gave way to eager gladness on the
face of the old man and spiteful anger on the faces of
the Hydes. As yet no blow had fallen and the relief party
was in the nick of time.

“What do you want here?” the father said, a snarl in his


voice.
“We want that man, for playing the part of a ghost and
stampeding our horses,” said the colonel evenly. “And
we want to see to it that you don’t touch that man with
your whip.”

“You do, heh?” grunted the son with the whip. “You all
can have this old man if you want him, but you can’t
stop us from whipping the daylights out of him. This is
the dog that burned our barn down.”

“I know all about that,” nodded the colonel. “But you


won’t horsewhip him. You can turn him over to the
proper authorities; in fact, I have already sent for the
sheriff and he will be here any minute now. But you
can’t take the law into your own hands, not while we
are here, certainly.”

“Look here, you soldier captain, or whatever you are!”


bellowed the senior Hyde. “You mind your own
business. Putting this fellow in jail won’t do us any
good, and we’re going to beat the hide off him. You
keep out. Josh, go ahead and wallop him.”

The Hyde boy raised his whip but the colonel reached 186
up, jerked it from his hand and threw it into a far
corner. The Hydes grew red and clenched their fists.

“Let’s give them a good beating, Pa,” said the younger


son, and he advanced. But the colonel drew his revolver
and covered the three of them. The other cadets
dropped their hands to the butts of their guns.

“Come a step nearer me and I’ll shoot you right through


the leg,” promised the colonel, simply.

The threat stopped them in their tracks. Sullenly they


fell back, hatred showing in their faces. The old man
whooped faintly.

“That’s handling them,” he said, stirring eagerly. The


colonel looked at him.

“You stay where you are, too, Mr. Vancouver,” he said.


“We’ll have to turn you over to the law for punishment.”

“I ain’t the only one in this game,” blustered the old


man.

“We know all about Mr. Maul,” said the colonel. The
Hydes snapped to attention.

“Maul!” cried the father, harshly. “Old Maul is dead!”

“Old Maul is very much alive,” retorted the colonel. “He 187
is the one who is directing this whole campaign. Did you
think this old man was doing it for fun? He has been
paid by Maul to keep this thing going, and he planned
to burn you out of your house pretty shortly.”

“Then you ought to let us whip this sneaking skunk!”


shouted the elder Hyde.

“Brutality won’t do any good,” returned the headmaster.

“Here comes the sheriff,” announced Jordan, as a heavy


step was heard outside the door.

The door opened to admit the sheriff, followed by Vench


and Douglas. The two cadets looked grave and a trifle
angry and the sheriff was his usual blustering self.

“What’s going on here?” he roared, looking around. His


angry eyes fastened themselves on the colonel. “I hear
that you requested me to come up here. Requested me!
Who are you, sir? I never saw you in my life!”

“I never saw you either,” retorted the unmoved colonel.

“What is the trouble here, anyway?” sneered the sheriff.

The trouble was explained by the colonel, but the sheriff 188
shrugged his shoulders. “I think you would have done
well to have minded your own business, sir,” said the
officious man. “This man needs a sound horsewhipping.
If it had been your house he burned you would be the
first one to whip him. What am I supposed to do?”

“You will arrest the old man and put him where he will
be safe,” said the colonel. “As for the Hydes, you can’t
do anything but send them home.”

“Look here, colonel, are you giving me orders!” bellowed


the loud sheriff, his face a dull red. “If you are, I won’t
even listen to them. Where you get the nerve to order
me around is more than I can see. I’ve got half a mind
to run you in for pointing a revolver at the Hydes.”

“Sheriff,” said the colonel, hotly. “I’ll tell you what I’m
going to do with you. I’m going to let the world know
how a ghost terrorized the Ridge here for years, right
under your nose, and you never found out who it was.
I’m going to relate how my boys discovered the whole
thing, and if you ever get another job with responsibility
to it, I don’t know what the people of this county are
thinking of!”

There was a total silence in the room while the colonel


and the sheriff glared at each other. The whole frame of
the sheriff shook with suppressed rage and his breath
came fast. Calmly the colonel looked him straight in the
eye. But the sheriff was beaten and he knew it.

Instead he vented his fury upon the Hydes. “Get out of 189
here and get home,” he snarled. “Don’t ever let me
catch you in any trouble again as long as I’m sheriff on
this Ridge! You, Peter Vancouver, come here while I put
the handcuffs on you.”

190
18
The Last of the Ghost

The Hydes had slunk off and were lost in the darkness.
The sheriff had handcuffed Peter Vancouver and now
they were on their way to the local jail in Rideway. After
putting the light out the colonel and the members of the
Ghost Patrol left the cabin and started over the trail to
camp.

“I’m very glad we got there in time to prevent any


serious injury to that old man,” remarked the colonel, as
they walked on. “Did you boys have any trouble with
that sheriff?”

“A little bit, sir,” Douglas replied. “He made a lot of noise 191
when we explained things to him. But he did come
finally, though he talked so much and made so much
noise on the way up that Vench and I felt like rolling
him in the mud!”

“I guess it was about time that somebody talked to


him,” the colonel said. “The people around here are
curious. They haven’t made any effort to run down this
ghost and they take abuse from this great blustering
sheriff. But I guess this ghost angle of things is about
over.”

“All that remains now is to catch Maul,” Jordan reminded


him.
“Yes, and we’ll see to it that steps are taken to do that,”
the headmaster promised.

The sky was pitch black, and not a star in sight. A


leaden sky threatened rain and the absence of the
moon and the friendly stars made the world below very
dark indeed. Fortunately for them the cadets knew the
road fairly well, and they approached the camp through
the bushes without having altered their course enough
to puzzle them.

“We will be hailed in about a moment,” said the colonel.


They were close to the outpost where the sentry was on
duty, and they advanced boldly, waiting for the call.

But none came. They reached the line of patrol that the
sentry was supposed to make, but they did not run
across the man who should have been patrolling. In
bewilderment they stopped.

“This is very queer,” murmured the colonel. “What can 192


have happened?”

Terry moved forward and struck his foot against


something soft. Without loss of time he dropped to his
knees, feeling before him with his hands. The sharp
intake of his breath drew their attention.

“What is it?” the colonel asked, quickly.

“Here is the sentry, tied up tighter than a bundle,” was


the startling reply. “Something’s fishy around here.”

The others clustered around and a match was struck.


They found Cadet Innes, the sentry, lying on his back,
bound around with coarse but strong cord. He seemed
to be all right otherwise, but perfectly speechless with a
thick gag in his mouth. By the way his eyes snapped
they judged that he had plenty to say. When the grunts
of surprise were over they went to work and soon
relieved him of the ropes and the gag.

“Be quiet, on your lives, men!” was his first word, after
he had licked his dry lips. “The man who tied me up is
in the camp, up to something.”

“Any idea who it was, Mr. Innes?” the colonel whispered.

“No, sir. A man all in black jumped me and did it in a 193


hurry. Muzzled me with one hand and took away my
gun with the other. It happened before the Officer of
the Guard got around, in fact he is due here now.”

“You say the man went toward the camp?” was the
colonel’s next question.

“Yes, sir, and he carried a can of kerosene with him,”


was the startling reply. The others wasted not another
minute, but jumped to their feet.

“Be very quiet as you approach the camp,” ordered the


colonel, leading the way through the bushes toward the
camp.

They approached silently and looked at the camp. It


seemed deserted. Three fires showed up red before the
tents, but the cadets were in their beds. On the other
side of the camp the Officers of the Guard could be
heard as he spoke shortly to a sentry. Otherwise there
seemed to be no movement or life in the place.

Don reached over and pulled the colonel’s arm. Close to


the supply wagons a darker shadow showed, and the
faint sound of liquid bubbling out of a can could be
heard. All of the hidden watchers caught the
significance of it at once and crouched down to wait
until the man should have come nearer them.

Then, something happened that changed their plans


abruptly.

A match was struck. The flare of the tiny blaze showed 194
a set, stern face. The man at the supply wagon bent
forward with the match.

Cadet Vench was little. He was also fast and happened


to be the nearest one to the stooping man. In three
strides Vench left the shelter of the trees, sprang into
the air, and landed like a monkey on the back of the
man, who had started to straighten up at the sound of
Vench’s steps. They both went down, the match
dropped on some oil-soaked cloth, and a fierce blaze
jumped up in a twinkling.

As Jim afterward said, he staked all on the size of his


feet. He landed with both shoes on the cloth, snuffed
the blaze out with a single stroke, and saved the supply
wagons and the entire camp.

Now all was action. A sentry near by had fired the


alarm. Vench and the unknown man were staging a
furious wrestling match on the ground beside the
wagons as the others dashed up and came to his help.
Someone threw more fuel on the nearest fire, Major
Rhodes ran up with his revolver in hand, and the whole
camp, more or less dressed, came running after him. In
the new light which the fire showed they saw Vench and
the colonel drag the man to his feet.

“Just got you in time,” said the colonel, holding the man
in a tight grip. “Am I right when I say your name is
probably Maul?”

“Yes, my name is Jackson Maul,” was the reply, given in 195


a deep voice. He gazed in haughty silence around at the
gaping cadets.

“I’ll ask you to spend the rest of the night with us in our
guard tent, Mr. Maul,” said the colonel, his revolver in
his hand. “I may as well tell you that your ghost game is
up, and the ghost of the Ridge safe in the county jail. I
think you’ll find yourself in pretty heavy trouble for
attempting to fire our camp.”

No reply was offered by the man who called himself


Maul and they took him away, where a tent could serve
as his place of imprisonment. Major Rhodes himself took
the responsibility of watching him for the rest of the
night. It was some time before the excited cadets went
back to their beds. An examination showed them that
the camp had been soaked in oil at a number of points,
and had fire been applied to any of these places they
would have been totally wiped out. It would have been
a lucky thing if they had all escaped with their lives had
the camp been fired.

On the following morning the man Maul was marched to 196


Rideway and locked in jail with the man he had paid to
play ghost. The full story now spread around the town
and the Ridge people found out how they had been
terrorized for years by the last of the Maul family in his
effort to drive the Hydes away. With this capture of the
two men the mystery of the ghost of Rustling Ridge
came to an end, and from that time forward the
inhabitants had nothing more to fear after dark. In time
the two men and the clerk Rose were all given prison
terms for mischief with malicious intent. The Hydes kept
out of trouble from that time forward and the loud
sheriff of the Ridge became softer in his speech, at least
as long as the cadets were in the neighborhood. A
number of the county newspapers gave high praise to
the cadets and to Benson, the night telephone operator,
for public-spirited duty.

Soon after these events the colonel called Rowen into


his tent. He had been very much displeased with the
conduct of the cadet, but as he reflected that things had
now settled down, it would be wise to forget the whole
thing, he felt sure. So he spoke mildly enough to the
cadet, but he was surprised when the sulky one flared
back at him.

“Never mind, Colonel Morrell, I don’t want to talk about


anything!” was the astonishing statement. “I’m going
home right away. Everything has been pushed against
me during this whole encampment and I’m sick of it! I
don’t want anything more to do with the cadet corps!”

“Very well, Mr. Rowen,” returned the colonel, still mildly. 197
“You say everything has been pushed against you. But
you would not believe Mercer’s word about the ghost
starting the stampede. Now we have the word of the
ghost himself that he started it and that Jim called out
to him. Then, against orders, you took your revolver
with you and shot it off at an improper time. Under
those circumstances, do you still feel that you had
everything against you on this camping trip?”

“I feel that I have had enough of this school and this


trip,” said Rowen. “I guess I could have more fun with
my own friends in a summer camp where a fellow didn’t
have to do so much unnecessary work. I’m going
home.”
Mr. Rowen did go home. No one was really sorry to see
him go, for his surly temper had never made him
popular in any way.

From that time onward the summer slipped along


without unusual incident. It was a delightful and happy
vacation, full of swinging action and invigorating fun,
and when the time came to break camp all of the boys
were a little bit sorry.

“Back to school again,” said Don, as they struck tents.

“Yes, and our time is getting limited,” said Terry,


seriously. “We haven’t a whole lot more time left to us in
our school life.”

“Right you are,” Jim agreed. “Next year Don will be


senior captain of the school.”

Before the morning was over the cadet battalion was 198
marching toward the school, leaving Rustling Ridge and
its many exciting memories behind them.
A Descriptive Catalog of
FALCON BOOKS FOR BOYS

THE MERCER BOYS’ CRUISE IN THE


LASSIE

by Capwell Wyckoff

When Don and Jim Mercer and their buddy Terry


Mackson set out in their sloop, Lassie, for a visit to
Mystery Island, they were in search of adventure and
fun. But they quickly found they were getting more than
they bargained for—real danger, a skirmish with marine
bandits, and a fight for their lives. This is a thrilling
adventure story of three modern boys—with action and
excitement on every page.

THE MERCER BOYS AT WOODCREST

by Capwell Wyckoff

The mystery of Clanhammer Hall, at Woodcrest Military


Academy, interested Don and Jim Mercer and their
friend Terry Mackson from the moment of their arrival at
Woodcrest. But their curiosity about the old, empty
building faded into the back of their minds as they
became involved in the mysterious disappearance of
their headmaster, Colonel Morrell, whom they had never
seen. With initiative and ingenuity the Mercer boys,
aided by Cadet Vench, did a little detective work and
uncovered a fantastic story of crime.

THE MERCER BOYS’ MYSTERY CASE

by Capwell Wyckoff

When Cadets Don and Jim Mercer and their friend Terry
Mackson were ordered by Colonel Morrell of Woodcrest
Military Academy to gather together all the school
trophies, they were able to find all except one—the cup
awarded to the class of 1933. What had happened to
the cup was a mystery the boys were determined to
solve. And little by little Don and Jim uncovered a
strange story and unraveled a mystery that had puzzled
school authorities for years. The Mercer boys uphold the
honor of Woodcrest against a conspiracy of silence and
dishonor.

THE MERCER BOYS ON A TREASURE


HUNT
by Capwell Wyckoff

Don and Jim Mercer were prepared to spend a dull


vacation at home when Professor Scott invited them to
Lower California and a search for Spanish treasure. But
their adventure was not all fun, for Don, Jim, and their
friend Terry Mackson soon found themselves involved
with a band of ruthless men determined to salvage the
treasure for themselves and to stop at nothing to do it.
Don and Jim fought for their lives in a series of startling
adventures which make this story of buried treasure an
absorbing and exciting tale.

THE MERCER BOYS WITH THE COAST


GUARD

by Capwell Wyckoff

When floods forced Woodcrest Military Academy to


close, Don and Jim Mercer found themselves facing a
dull two months at home. That was why they eagerly
accepted the chance to visit a coast guard station.

Don and Jim were anxious to participate in the thrilling


rescues off Daggerpoint Rock and in the difficult beach
patrols. But they didn’t bargain for a mystery which led
them from one thrilling adventure to another until they
finally solved it.

The Mercer Boys with the Coast Guard is a fast-paced,


exciting story every boy will enjoy.
CALL TO ADVENTURE

edited by Robert Spiers Benjamin

Here is adventure of every kind! Fishing for the broad-


bill swordfish in Catalina waters, an airplane crash in the
Andalusian desert, a trip around Cape Horn, a shipwreck
in the Indian Ocean, a walrus hunt, an encounter with
cannibals, an attack by a bear from the ice floes of
Greenland to the matted jungles of the South Sea
Islands, these men of adventure sail and hunt and fight
with a courage and abandon that will transport every
reader to another, more exciting world.

THE SPIRIT OF THE BORDER—by Zane


Grey

Zane Grey’s famous novel of the old West when Indian


raids were an everyday affair and the guns of the scouts
smoked in a perpetual trail of vengeance against the
savages. Joe Downs went West, eager to join the scouts
in their exciting life. His brother Jim followed him, to
convert the Indians. They found themselves up against
the aroused Indians, led by the renegades Simon and
Jim Girty, in a war to the death.

A popular condensation of a thrilling story based on


historic fact, by the best of all Western writers.
THE LAST TRAIL—by Zane Grey

The Last Trail is the thrilling story of Helen Sheppard,


beautiful newcomer to the Wilderness, and Jonathan
Zane, one of the last of the bordermen. Bordermen did
not fall in love: theirs was the job of tracking down
renegade white men and enemy Indians so that the
settlers might lead safe and peaceful lives. But when
Helen was kidnapped by the renegades, Jonathan
discovered how much he loved her; and he and his
friend Wetzel set out on a trail of vengeance and
destruction.

For the adventure and thrill of frontier life, The Last Trail
is hard to equal in the literature of the West. Zane Grey
has told his story with mastery and realism, and readers
will love this exciting story from the pen of a master
storyteller.

ON THE FORTY-YARD LINE—by Jack


Wright

Jim Davis, the most popular man on the Grayson


campus, was determined to make the football team. His
roommates Bob Clark and Chub Garver were already
football man and cheerleader respectively. It was easy
for Jim to become Coach Kelso’s star passer, but it
wasn’t so easy to stay on the team. First, there was the
secret between Professor Burke and Jim; second, there
was Weldy Gray, who was out to ruin Jim at any cost.
On the Forty-Yard Line is a story filled with the
excitement of football, and the courage and loyalty of
three pals who fight with equal abandon for their school
and for each other.

THE STRIKE-OUT KING—by Julian de


Vries

From the moment Larry Murdock is chosen as regular


pitcher for the Carson College nine, to the thrilling
seconds of the big game with Northern State when
Larry battles against almost overwhelming odds, The
Strike-Out King is an action-packed story of the
diamond that will appeal to the sports-loving instinct of
every American boy. An absorbing book no reader will
be able to put aside until the last word of the last page
has been read.

THE WINNING BASKET—by Duane


Yarnell

Honest, eager-eyed Ben Mason was in seventh heaven


when he was admitted to Clearview Academy. He had
been there only a day when they discovered he was not
from a rich, influential family—and Ben was out. How
Ben got back into Clearview, and how he fought the
antagonism of the student body and the conspiracies of
his enemy Jack Lassiter make an absorbing story filled
with drama. Every boy will root for Ben as he fights on
the basketball court for the school that didn’t want him.

THROUGH FOREST AND STREAM:


ADVENTURE IN THE MOUNTAINS—by Duane
Yarnell

When Ted and Pudge went to the All-American camp, it


was for a summer of good fun. Then they discovered
that they were really entered in a contest—a contest
involving $50,000 for the college of the boy who won it.
Ted just had to win that prize, both to keep baseball at
College Tech and to insure his father’s job as baseball
coach. How he engaged in a deadly fight with wolves
and was entombed in an old mine shaft with a ferocious
bear are only two of the many adventures he had.

Ted Moran wins out in a breathless story of heroism and


resourcefulness that will thrill its readers.

OVER THE HURDLES—by Emmett Maum

Any boy who has thrilled to the shot of the starting gun
and the crunch of spiked shoes on cinders will enjoy the
story of Larry Craven, for whom the cinder track was
the path of fame from Maywood College to the Olympic
games. But all was not smooth going for Larry, for he
had many obstacles to surmount and he had enemies
who plotted against him. How he won out over his
difficulties makes an exciting and vivid sports story.

BOYS’ BOOK OF SEA BATTLES

by Chelsea Curtis Fraser

Truth can be more exciting than fiction, as these


fourteen stirring sea battles from the pages of history
prove. From the days of Sir Francis Drake, when life on
the sea was a constant battle between the Spanish and
the English, to the Battle of Leyte, sea fights have
determined the destiny of men and nations. In these
pages you will find Commodore John Paul Jones, Lord
Nelson, Oliver Perry, Admiral David Farragut, and
Dewey, together with the dramatic stories of the
Constitution and the Guerrière, the Monitor and the
Merrimac, and the sea battles of World Wars I and II.

BOYS’ BOOK OF FAMOUS SOLDIERS

by J. Walker McSpadden

War transforms ordinary men into the heroes of the


battlefield, and the story of their exploits and brilliant
strategy is more exciting than any tale of fiction. The
Boys’ Book of Famous Soldiers brings together the
stories of thirteen immortals of history: Washington,
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like