<<

Dongwon Lee Internet of Things: Smart Home System

Metropolia University of Applied Sciences Bachelor of Engineering Electronics Bachelor’s Thesis 13 February 2019

Abstract

Author Dongwon Lee Title Internet of Things: Smart Home System

Number of Pages 33 pages + 1 appendices Date 13 February 2019

Degree Bachelor of Engineering

Degree Programme Electronics

Professional Major

Instructors Janne Mäntykoski, Senior Lecturer

The aim of this project was to design and implement a smart home system that can turn on or off LEDs, read temperature and humidity from DHT11 sensor. This is an example of application of Internet of Things to control hardware with voice command.

To implement this project, a DHT11 sensor for measuring temperature and humidity, LEDs, Raspberry Pi 3 to connect hardware, and Ngrok server working as a tunnel between Raspberry Pi and hardware were used. The thesis can be generally divided into two parts; The theoretical part deals with definition and history of Internet of Things and gives an overview of several products applied Internet of Things. The practical part describes the process of making the system.

This system can control turning on and off LEDs, and read temperature and humidity from the sensor by using Amazon Alexa Voice Service. The project can be used for further developments by adding other sensors. There are numerous applications which can be done by using some sensors and Raspberry Pi. It is helpful to under- stand the basic concept of Internet of Things and Smart Home System.

Keywords IoT, Raspberry Pi, Smart Home, Amazon, Alexa

Contents

List of Abbreviations

1 Introduction 1

2 Fundamentals of Internet of Things 2

2.1 Definition and History of Internet of Things 2 2.1.1 Definition 2 2.1.2 History 2 2.2 Trend and Characteristics of Internet of Things 3 2.2.1 Intelligence 4 2.2.2 Network Architecture 5 2.2.3 Size Considerations 5 2.2.4 Space Considerations 5 2.2.5 Complexity 6 2.2.6 A Solution for “basket of remotes” 6 2.3 Application for Smart Home 7 2.3.1 Amazon Echo 7 2.3.2 HomePod 8 2.3.3 SmartThings 10

3 Components for Implementing Internet of Things 11

3.1 Hardware 11 3.1.1 Raspberry Pi 11 3.1.2 DHT11 Temperature Sensor 13 3.2 Software 15 3.2.1 Raspbian for Raspberry Pi 15 3.2.2 Ngrok 16 3.2.3 Flask-Ask 17

4 Process for Building Smart Home System 18

4.1 Overview 18 4.2 Installing Required Software 18 4.2.1 Setting up a Web Server on Raspberry Pi 18 4.2.2 Installing Flask-Ask 19 4.2.3 Installing Adafruit Library 19

4.3 Registering the Raspberry Pi to Amazon Alexa Skills 21 4.4 Installing Hardware Components 23 4.5 Demonstrating Alexa Skills 24

5 Conclusion 26

References 28

Appendices Appendix 1. Source Code for Controlling Hardware, JSON Code for Alexa Skill

List of Abbreviations

IoT Internet of Things

IP Internet Protocol

UbiComp Ubiquitous Computing

PerCom Pervasive Computing and Communication

RFID Radio-Frequency Identification

D2D Device to Device

WWW World Wide Web

SOA Service-Oriented Architecture

IETF Internet Engineering Task Force

6LoWPAN IPv6 over Low-power Wireless Personal Area Network

MQTT Message Queuing Telemetry Transport

IPv6 Internet Protocol version 6

CoAP Constrained Application Protocol

SDN Software Defined Network

SoC System-on-Chip

FOB Free On Board

OS Operating System

CPU Central Processing Unit

GPU Graphics Processing Unit

RAM Random Access Memory

SD Secure Digital

GPIO General-Purpose Input and Output

I2C Inter-Integrated Circuit

8P8C 8 Position 8 Connect

PIXEL Pi Improved X-Window Environment Lightweight

LXDE Lightweight X11 Desktop Environment

HTTP HyperText Transfer Protocol

HTTPS HyperText Transfer Protocol over Secure Socket Layer

URL Uniform Resource Locator

TCP Transmission Control Protocol

1

1 Introduction

The Internet of Things, which is generally called as IoT, is becoming an essential tech- nology for 21st century. The IoT gives things IP address which enables communication between things and people, or among things. It becomes more and more practical thanks to the development of technologies, such as short-distance wireless communi- cation, that are required for implementing the IoT.

The IoT can be utilised in consumer, commercial, industrial, and infrastructure aspects. For instance, it can be applied at self-driving cars that are connected to the Internet and able to provide safe and comfortable driving. It also promotes one’s health by providing heartbeat and amount of workout through applications, such as S Health or Apple Health developed by Samsung and Apple respectively, and wearable devices, such as Samsung Gear or Apple Watch, since these applications and wearable de- vices should exchange data through the IoT.

Due to this advantage of IoT, it is decided to make a smart home system using Ama- zon Alexa, which is a virtual assistant and controls smart devices for home automation system. The smart home device can turn LEDs on and off, and read temperature and humidity data from a sensor by voice commands. The sensor and LEDs are connected to Raspberry Pi 3 Model B, which contains General-Purpose Input and Output (GPIO) pins. This device would work as a basic model of smart home system.

The device consists of Raspberry Pi 3 Model B, which is used to connect sensor and LEDs, DHT11 sensor, which reads temperature and humidity data, Flask-Ask, which is a development tool for implementing Alexa, Ngrok, which is a web server that connects Raspberry Pi and Alexa server.

This thesis is going to deal with fundamentals of IoT, introduction about components that are used for the project, and procedures to make the device. Instructions are also included to set up and operate each element. It contains the results with some pictures, conclusions, and a few suggestions for more practical use.

2

2 Fundamentals of Internet of Things

2.1 Definition and History of Internet of Things

2.1.1 Definition

The Internet of things (IoT) is defined as a connection of home appliances, vehicles, and others embedded with software, electronics, sensors, actuators, and connectivity which make them connect, collect and exchange data.[1]

2.1.2 History

The definition of the Internet of things has changed because of combination of various technologies, real-time analytics, machine learning, commodity sensors, and embed- ded systems. To implement the IoT, traditional fields of embedded systems, wireless sensor networks, control systems, automation (including home and building automa- tion), and others are used.[2]

The basic idea of a bundle of smart devices was discussed in 1982, with a modified Coke machine at Carnegie Mellon University becoming the first Internet-connected ap- pliance,[3] which was able to report its inventory and check whether newly loaded drinks were cold.[4] In 1991, it was mentioned in "The Computer of the 21st Century", ubiqui- tous computing written by Mark Weiser, in addition to academic venues like UbiComp (Ubiquitous Computing) and PerCom (Pervasive Computing and Communication) pro- duced the latest concept of IoT.[5] In 1994, Reza Raji described the concept in IEEE Spectrum as "(moving) small packets of data to a large set of nodes, so as to integrate and automate everything from home appliances to entire factories".[6] From 1993 to 1997, several companies made a proposal for smart system, such as Novell's NEST or Microsoft’s Work. At the World Economic Forum at Davos in 1999, this idea became more obvious when Bill Joy introduced Device to Device (D2D) communication as an element of his "Six Webs" framework.[7]

In 1999, Kevin Ashton of Procter & Gamble might make the term "Internet of things",[2] although he preferred the phrase "Internet for things". He thought that Radio-

3

Frequency Identification (RFID) is important to the Internet of things, which would ena- ble computers to manage all devices.[8]

In June 2002, a research article mentioning the IoT written by Kary Främling and his team at Helsinki University of Technology was submitted to the conference for Nordic Researchers in Logistics, Norway,[9] which was precedent for an article published in Finnish in January 2002.[10] It clearly describes an infrastructure of information system for implementing smart objects.[11]

Cisco Systems estimated that IoT was "born" between 2008 and 2009, and defined it as "simply the point in time when more 'things or objects' were connected to the Inter- net than people".[12]

2.2 Trend and Characteristics of Internet of Things

Recently, the major trend of IoT is the tremendous increase of things connected and controlled by the Internet.[13] The applications with IoT mean that the details could vary from device to device but there are basic characteristics in common.

The IoT makes it possible to directly integrate the physical world into computer-based systems. As a result, it improves efficiency, benefits economy, and reduces human ex- ertions.[14] In the Figure 1, there is a technology roadmap of the IoT from 2000.

4

Figure 1. Technology Roadmap of the IoT[15]

In 2017, the number of IoT devices increased to 8.4 billion and it is predicted that there will be 30 billion devices by 2020.[13] By 2020, it is expected that the global market value of IoT will reach $7.1 trillion.[16]

2.2.1 Intelligence

Ambient intelligence and autonomous control are basically not elements of the general concept of the IoT. They do not need Internet connections, either. However, a massive transition happened in companies, such as Intel, to merge the concepts of autonomous control and IoT. Consequently, initial outcomes for the research consider that objects are the basic components for autonomous IoT.[17]

IoT may be a non-deterministic and open network in the future, where intelligent fea- tures, such as World Wide Web (WWW) and Service Oriented Architecture (SOA) com- ponents and virtual objects (avatars), will work together, and can act independently de- pending on the context or environments. A major research trend consists of autono- mous behaviour through the collection and thinking of context information, as well as

5

the object's ability to detect changes in the environment and introduce suitable measures, clearly needed to provide reliability to the IoT technology. Therefore, mod- ern IoT products and solutions in the marketplace use various technologies to support such context-aware automation, but allowing sensors and intelligent cyber systems to be applied in real world require more sophisticated forms of intelligence.[18]

2.2.2 Network Architecture

The Internet of things requires massive network space to deal with the rising number of devices.[19] Therefore, one of solutions would be IETF 6LoWPAN to connect devices to IP networks. IPv6 will be much more significant in handling the complexity of network layer because billions of devices[20] can be added to the Internet space. IETF's CoAP, ZeroMQ, and MQTT would enable light and fast data transport.

2.2.3 Size Considerations

The IoT would combine 50 to 100 trillion objects and be able to follow the movement of those objects. According to a survey done by Business Insider’s premium research ser- vice[23], people living in urban area are surrounded by 1000 to 5000 trackable objects. It was disclosed that there were already 83 million smart devices by 2015. The number of devices is about to increase to 193 million in 2020 and will certainly keep growing in the near future.

2.2.4 Space Considerations

In the IoT, the precise geographic location and dimensions of a thing will be critical.[24] Therefore, actual data about a thing, such as its location in time and space, have been less critical to track because the person processing the information can determine whether information was important to be taken action on. For instance, the GeoWeb and Digital Earth are successful applications that enable things to become organised and connected by location. However, the remaining challenges are the limitations of variable spatial scales, the necessity to handle massive amounts of data, and an

6

indexing for fast search and neighbouring operations. Nevertheless, it is possible to substitute human-centred roles in the IoT if things could work on their own intention. Thus, the time-space context that humans take for granted must play a major role in this information system. Additionally, geographic data and information will be given a key role in the IoT since standards are given a key role in the Internet and the Web.[25]

2.2.5 Complexity

IoT will often be regarded and developed as a complex system in semi-open or closed loops, such as value chains, because of the immense number of various interactions, connections between autonomous devices, and its ability to integrate new devices. In other words, it will be considered as a chaotic environment at the overall stage (full open loop) since systems are always finite. However, in practical aspect, not every ele- ment in the IoT run in a global, public space. Therefore, subsystems are often imple- mented to redeem the risks of privacy, control and reliability. For example, domestic ro- botics running inside a smart home might only share data within and be available via a local network.[21] Software Defined Networking (SDN) provides the appropriate solution that can process the special requests of diverse IoT applications as supervising and controlling high dynamic IoT devices network is not simple with the traditional network architecture.[22]

2.2.6 A Solution for “basket of remotes”

Many IoT devices might partially occupy the IoT market. Jean-Louis Gassée, a mem- ber of Apple initial alumni team and BeOS co-founder, predicts that the most probable problem will be what he calls the "basket of remotes" problem, where there are a lot of applications to interface with hundreds of devices that do not share protocols for com- municating with one another.[26] To solve this problem, some technology leaders are cooperating to make standards for communication between devices. Others are mak- ing a transition to the concept of predictive interaction of devices, "where collected data is used to predict and trigger actions on the specific devices" while making them work together.[27]

7

2.3 Application for Smart Home

A skyrocketing number of IoT devices are manufactured for consumer use, including connected vehicles, home automation, wearable technology, connected health, and ap- pliances with remote monitoring capabilities.[28] In this section, home automation, which mostly contributes to IoT devices, is going to be dealt with.

IoT devices partially consist of home automation, which can include heating and air conditioning, lighting, media and security systems.[29] By automatically controlling lights and electronics, energy savings can be possible in the future.

A smart home or home automation could be originated on a platform or hubs that con- trol smart devices and appliances. For instance, an application in iOS devices, such as the iPhone and the Apple Watch can manage their home products and accessories by using Apple's HomeKit.[30] This could be an exclusive app or iOS built-in applications such as Siri. It can be also implemented in Lenovo's Smart Home Essentials, which is a connection of smart home devices that are controlled through Apple's Home app or Siri without a Wi-Fi router.[31] There are specialised smart home hubs including the Amazon Echo, Apple's HomePod, and Samsung's SmartThings Hub, which are provided as standalone platforms to connect different smart home products.[32]

2.3.1 Amazon Echo

Amazon Echo is a brand name of smart speakers developed by Amazon. The voice- controlled intelligent personal assistant service Alexa, which responds to the name "Alexa", is connected to the devices. This "wake word" can be changed by the user to "Amazon", "Echo" or "Computer".[33] The device is able to interact with voice, play mu- sic, make to-do lists, set alarms, stream podcasts, play audiobooks, and provide weather, traffic and other real-time information. It can also control several smart de- vices while acting as a home automation hub. Moreover, it is possible to add other de- vices in the Alexa voice services.[37]

8

Amazon had been developing Echo devices inside its Lab126, a research and develop- ment company of Amazon, in Silicon Valley and Cambridge, Massachusetts since 2010 according to the official reports. It made the first attempt aimed to widen its device property beyond the Kindle eBook-reader.[34] Thanks to this success, the Echo was dominantly shown up in Amazon's first-ever Super Bowl advertisement in 2016.[35] The product presented in the advertisement is shown in Figure 2.

Figure 2. The First Generation of Amazon Echo[36]

2.3.2 HomePod

HomePod is a smart speaker developed by Apple Inc. HomePod has a circular, cylin- drical shape, and a small touchscreen on the top. It has seven tweeters in its base and a four-inch woofer towards the top, as well as six microphones for voice control.[38] It is available in two colours: White (shown as Figure 3) and Space Gray.[39]

9

Figure 3. A HomePod in white[40]

The device runs an "audioOS", a variant OS based on iOS,[41] and features an Apple A8 SoC.[42] It includes Siri, which can control the speaker and other HomeKit devices, and can be used to pick up voice calls and send text from an iPhone. It only supports Apple platforms and services, including iTunes Store, Apple Music, Beats 1 radio, iTunes podcasts, Match, and AirPlay, (though an Apple device with iOS11 is re- quired for installlation). But it does not officially support Bluetooth audio.[38] At first, Ap- ple announced that it would include AirPlay 2 and multi-room, multi-speaker, but it is not included in the release of February 2018. To overcome these shortcomings, An- drew Faden of Akamai has developed a solution called "BabelPod" which makes it pos- sible to input external and Bluetooth audio to the HomePod by using Auxiliary jack in a Raspberry Pi.[43]

However, HomePod does not support multi-account, so it is not suitable for families be- cause only one user can access to their iCloud data.[44]

10

2.3.3 SmartThings

SmartThings Inc. is a technology company whose headquarter is in Mountain View, California and a software development centre in Minneapolis. SmartThings is develop- ing an open platform for smart homes and IoT products for consumers. SmartThings makes cloud platform, a hub ("gateway" or "home controller"), and client applications. However, SmartThings was bought by Samsung in August 2014.[45] There are a free a SmartThings Hub,[46] SmartThings app[47] as well as various smart devices for its main products.[48]

The mobile application of SmartThings enables users to monitor, automate, and control their home via mobile device. The application is programmed to adapt every user's de- mands.[46] The SmartSetup area in the application is accessible from the app's dash- board and provides the installation process of adding new devices. Customers can use the application to connect several devices at the same time or follow an instruction to configure one device at a time.[49]

Secondly, the SmartThings hub directly connects to an internet router in a home and is compatible with communication protocols such as Z-Wave, ZigBee, and IP-accessible devices. It provides a connection between sensors and devices with one another and the cloud, thus allowing them to communicate with the SmartThings app.[46]

Some SmartThings compatible devices include:[47]

• Motion, presence, and moisture sensors

• Locks

• Electrical outlets

• Garage door openers

• Speakers

• Thermostats

For instance, there are "a motion sensor, a moisture sensor, a smart outlet, two FOBs with 'presence' sensors, and two multi-sensors that can detect movement, vibration, orientation and temperature" in a SmartThings starter bundle.[50]

11

3 Components for Implementing Internet of Things

3.1 Hardware

3.1.1 Raspberry Pi

The Raspberry Pi is a collection of small single-board computers developed by the Raspberry Pi Foundation in the United Kingdom to teach basic computer science in schools and in developing countries.[51] The initial model became much more popular than expected and mainly sold for robotics. It does not include peripherals such as mouse, keyboards, and cases. However, some accessories have been included in sev- eral official and unofficial bundles.[52]

There are several generations of Raspberry Pis. Each model consists a Broadcom SoC with an integrated ARM-compatible CPU and on-chip GPU.

The CPU varies from 700 MHz to 1.4 GHz for the Pi 3 Model B+; Random Access Memory (RAM) varies from 256 MB to 1 GB. Secure Digital (SD) cards are used to store the OS and program memory in either SDHC or MicroSDHC sizes. The boards have one to four USB ports, HDMI and composite video ports, and a standard 3.5 mm jack for audio output. Lower-level output is provided by a number of General- Purpose Input and Output (GPIO) pins, which support common protocols like I²C. The B-models have an 8P8C Ethernet port and the Pi 3 and Pi Zero W have on-board Wi- Fi 802.11n and Bluetooth.

Raspberry Pi 3 Model B, which is shown in Figure 4 and is going to be used in this pro- ject, was released in February 2016 with a 64-bit quad core CPU, on-board Wi- Fi, Bluetooth and USB boot capabilities.[53] On 14 March 2018, model 3B+ appeared with a faster 1.4 GHz processor and a three times faster network based on gigabit Ethernet or 2.4 / 5 GHz dual-band Wi-Fi.

12

Figure 4. Raspberry Pi 3+ Model B[54]

Raspberry Pi 1 Models A+ and B+, Pi 2 Model B, Pi 3 Model B and B+, and Pi Zero and Zero W GPIO J8 have a 40-pin pinout. Pin schematic is as follows in Table 1.

Table 1. GPIO Pin Schematic for Raspberry Pi 1 A+/B+, 2 B, 3 B/B+, and Zero W[55]

GPIO# 2nd function Pin# Pin# 2nd function GPIO#

+3.3 V 1 2 +5 V

2 SDA1 (I²C) 3 4 +5 V

3 SCL1 (I²C) 5 6 GND

4 GCLK 7 8 TXD0 (UART) 14

GND 9 10 RXD0 (UART) 15

17 GEN0 11 12 GEN1 18

27 GEN2 13 14 GND

22 GEN3 15 16 GEN4 23

+3.3 V 17 18 GEN5 24

10 MOSI (SPI) 19 20 GND

9 MISO (SPI) 21 22 GEN6 25

13

11 SCLK (SPI) 23 24 CE0_N (SPI) 8

GND 25 26 CE1_N (SPI) 7

EEPROM ID_SD 27 28 ID_SC EEPROM

5 N/A 29 30 GND

6 N/A 31 32 12

13 N/A 33 34 GND

19 N/A 35 36 N/A 16

26 N/A 37 38 Digital IN 20

GND 39 40 Digital OUT 21

The Raspberry Pi Foundation provides Raspbian, a Debian-based Linux distribution for download, as well as third-party Ubuntu, Windows 10 IoT Core, and so on. It promotes Python and Scratch as the main programming languages, but it also supports other languages.

3.1.2 DHT11 Temperature Sensor

DHT temperature and humidity sensor is one of the most popular measurement sen- sors. This sensor is very basic and slow, but it is good for some basic data logging. The DHT sensor is made of two parts, a capacitive humidity sensor and a thermistor. There is a simple analogue to digital converter which sends a digital signal with the tempera- ture and humidity. The digital signal is easy to read with any microcontroller. Figure 5 shows DHT11 temperature and humidity sensor.

14

Figure 5. DHT11 Temperature and Humidity Sensor

There are two versions of the DHT sensor, DHT11 and DHT22. Both look quite similar and have the same pinout, but they have different characteristics. The common things for both sensors are that they use 3 ~ 5V power input, 2.5mA maximum current during conversion, and have 3 or 4 pins. However, for DHT11, it gives the best results for hu- midity range of 20 ~ 80% with 5% accuracy and temperature range of 0 ~ 50 °C with ±2°C accuracy, and sampling rate is less than 1Hz. On the other hand, for DHT22, it gives the best results for humidity range of 0 ~ 100% with 2 ~ 5% accuracy and tem- perature range of -40 ~ 80 °C with ±0.5 °C accuracy, and sampling rate is less than 0.5Hz. So, it is suitable to use DHT22 sensor for more accurate and extensive meas- urement.[56]

The pin configuration of DHT sensor is shown in Table 2 below. If the sensor has 3 pins, there is no NC pin.

Table 2. Pin Identification and Configuration of DHT sensor

No Pin Name Description

1 Vcc Power supply 3.5V to 5.5V

2 Data Outputs both Temperature and Humidity through serial Data

3 NC No Connection and hence not used

4 Ground Connected to the ground of the circuit

The DHT11 sensor is already calibrated and outputs serial data so it is highly easy to set up. The connection diagram for this sensor is shown in Figure 6.

15

Figure 6. Connection diagram for DHT11 sensor

As shown in Figure 6, the data pin is connected to an I/O pin of the microcontroller and a 5kΩ pull-up resistor is used. This data pin outputs the value of both temperature and humidity as serial data.[57]

3.2 Software

3.2.1 Raspbian for Raspberry Pi

Raspbian is a Debian-based computer OS for Raspberry Pi. There are several versions of Raspbian including Raspbian Stretch and Raspbian Jessie. Since 2015 it has been officially provided by the Raspberry Pi Foundation as the primary OS for the family of Raspberry Pi single-board computers. The initial build was completed in June 2012. The OS is still under active development. Raspbian is highly optimised for the Rasp- berry Pi line's low-performance ARM CPUs.

16

Figure 7. Raspbian OS in the Raspberry Pi

As shown in Figure 7, Raspbian uses Pi Improved X-Window Environment Lightweight () for its main desktop environment as of the latest version. It is consisted of a modified Lightweight X11 Desktop Environment (LXDE) and the Openbox stacking win- dow manager with a new theme and few other changes. The distribution includes a computer algebra program Mathematica and Minecraft Pi (a Raspberry Pi version of Minecraft) as well as , a lightweight version of Chrome, for the latest ver- sion.[58]

3.2.2 Ngrok

Ngrok is a web server which connects local servers protected by firewalls to the public internet over secured tunnels. It connects to the Ngrok cloud service which accepts traffic on a public address and relays that traffic through to the Ngrok process running on your machine and then on to the local address you specified. It is mainly used for building webhook consumers on device, testing mobile apps connected to locally run- ning backend, and running personal cloud services from your home. Figure 8 shows some examples of usage of Ngrok, which makes it easy to understand.

17

Figure 8. Some Examples of Usage of Ngrok[59]

As shown in Figure 8, it has several great features such as secure tunnel, which is mostly used and creates a public HyperText Transfer Protocol Secure (HTTPS) Uni- form Resource Locator (URL) for a website running on the device, request inspection, which uses web inspection interface to understand the HTTP request and response traffic, and so on. In addition, it provides custom subdomains, which can change HTTPS URL for some other name, reserved Transmission Control Protocol (TCP) ad- dress, which reserves a static IP and port for private use, and so on for paid version.[59]

3.2.3 Flask-Ask

Flask-Ask is a development tool for implementing Alexa Skills. It makes it easier to build high-end Alexa Skills for Amazon Echo Devices. It works well with Ngrok because it can skip the complicated procedures and make it faster.[60] Flask-Ask

• Has decorators to map Alexa requests and intent slots to view functions

• Helps construct ask and tell responses

• Makes session management easy

• Allows to separate code and speech through Jinja templates

• Verifies Alexa request signatures

18

4 Process for Building Smart Home System

4.1 Overview

In this section, there are some instructions for implementing the system. First, install software which is essential to operate a web server and to communicate with Amazon Alexa. Next, set up Alexa Skills to get ready for controlling hardware. Finally, install hardware components and start a code to demonstrate the system.

4.2 Installing Required Software

4.2.1 Setting up a Web Server on Raspberry Pi

The first task to make the system is installing Ngrok, which is a web server making HTTP tunnel to connect Raspberry Pi and Alexa. Before installing, make sure to update the Raspberry Pi to the latest version. It can be done by the following commands.

• sudo apt-get update

• sudo apt-get upgrade

Next, download Ngrok from the website (https://ngrok.com/download) and unzip the file. Please be aware that the version must be Linux ARM if Raspbian is installed in Raspberry Pi. Then start HTTP tunnel by the following command.

• sudo ./ngrok http 5000

5000 is the number of HTTP port, so any port number is allowed. If the server is run- ning okay, there should be a screen like Figure 9.

19

Figure 9. Screenshot for running Ngrok

In the screen, there are a message that the ‘Session Status’ is ‘online’ in green letters and Forwarding addresses in HTTP and HTTPS format. The HTTPS address in the red box is going to be used as an Endpoint in Alexa Skills.

4.2.2 Installing Flask-Ask

The next step is installing Flask-Ask, a development tool for Alexa. Make sure to up- date setup tools to the latest version by the following command so as to prevent errors while installing Flask-Ask.

• sudo pip install –upgrade setuptools

After updating, install Flask-Ask by the following command.

• sudo pip install Flask-Ask

If there are no errors while installing, now it is prepared to go to the next step.

4.2.3 Installing Adafruit Library

DHT sensor requires a specific library to read temperature and humidity data. The Ada- fruit DHT library deals with the data that needs to be exchanged with the sensor, but it is sensitive to timing issues. The OS in Raspberry Pi might be working while doing

20

other tasks so the library requests continuous readings from the sensor until it gets one valid data.

Prior to installing the library, check whether the package lists are up-to-date and the fol- lowing packages are installed. If not, install them beforehand by the following com- mands.

• sudo apt-get update

• sudo apt-get install build-essential python-dev

Then download the Adafruit library from GitHub repository.

• git clone https://github.com/adafruit/Adafruit_Python_DHT.git

• cd Adafruit_Python_DHT

Finally, install the library for Python 2 and Python 3.

• sudo python setup.py install

• sudo python3 setup.py install

To check if the library is successfully installed and the sensor works fine, try an exam- ple script for DHT11.

• cd ~

• cd Adafruit_Python_DHT

• cd examples

• python AdafruitDHT.py 11 17

The script takes two parameters: the first one is the sensor type, DHT11 or DHT22, and the second one is the GPIO number. In this case, the sensor is connected to GPIO pin #17.

If the sensor is working correctly, there should be an output like this.

• Temp=22.0* Humidity=68.0%

21

4.3 Registering the Raspberry Pi to Amazon Alexa Skills

In this section, there are procedures how to register the Raspberry Pi connected with hardware to Amazon Alexa Skills. First, go to Amazon Alexa webpage (developer.ama- zon.com/alexa) and sign in with Amazon account. If there is no account, please create a new one to use Alexa service. After signing in, click ‘Your Alexa Consoles’ and ‘Skills’ in the Figure 10 as indicated in the red box.

Figure 10. Amazon Alexa Webpage

In Alexa Developer Console, click ‘Create Skill’ and there is a screen for creating new skill like Figure 11. Enter a skill name less than 50 characters. The name can be any- thing you want. Then choose ‘Custom’ model since this skill is going to be used with certain codes. Other models are ready-made ones which contains sample codes.

22

Figure 11. Create a New Alexa Skill

After creating new skill, choose ‘Start from Scratch’ template and click ‘Choose’ button. Then as shown in Figure 12, go to ‘JSON Editor’, drag and drop a json file or copy and paste a code which is in Appendix, and click ‘Build Model’. After building is completed, click ‘Save Model’.

Figure 12. JSON Editor in Alexa Developer Console

The next task is setting up Endpoint. As indicated in Figure 13, go to ‘Endpoint’ section and choose ‘HTTPS’ for ‘Service Endpoint Type’. Enter the HTTPS URL obtained from

23

Ngrok in ‘Default Region’ field and choose ‘My development endpoint is sub-domain of domain that has a wildcard certificate from a certificate authority’, which is the second option. Finally, click ‘Save Endpoints’ and the job is done.

Figure 13. Setting up Endpoint

4.4 Installing Hardware Components

Now it is time to connect hardware. As shown in Figure 14, connect anode to GPIO17 and cathode to ground for green LED. This one is the light for room. Connect anode to GPIO18 and cathode to ground for red LED. This one is the light for kitchen. And for the sensor, connect VCC pin to DC 3V, GND to ground, and SIG to GPIO14. Remem- ber to connect 10kΩ resistor between VCC and SIG if the sensor has 4 pins otherwise it might not work properly. If the sensor has 3 pins, there is no need to connect resistor. Position of grounds, which is marked with grey ones, can be anywhere on the Pi. The position of GPIO pins marked with green ones can be also changed. However, keep in mind that the Python code should be modified because the pin number has to be changed in the code.

24

DHT11 Sensor

LED_Kitchen LED_Room

R1 10kΩ

Figure 14. Connecting Schematics

4.5 Demonstrating Alexa Skills

Finally, it is ready to demonstrate Alexa Skills. Make sure that Ngrok is running and Endpoint address is same with Ngrok. Next, start the python code (Code.py) by enter- ing the following command in Terminal console.

 sudo python Code.py

Then, in Amazon Alexa Skill webpage, go to ‘Test’ section and enable ‘Test the Skill’ shown as Figure 15. Hold the mic button and talk or enter a command in this line start- ing with ‘Alexa, ask raspberry to ~’. For instance, ‘Alexa, ask raspberry to turn on room light’. Then Alexa will respond by saying something, such as ‘Turning on room light.’. Check if LED is on or off or Alexa can read temperature and humidity from the sensor by the command.

25

Figure 15. Testing Alexa Skill

Figure 16 shows the result of the demonstration. When saying ‘Alexa, ask raspberry to turn on room light’, Alexa responds by saying ‘Turning on room light.’ and the green LED, which is called as ‘room light’, is on. When saying ‘Alexa, ask raspberry to turn off room light’, Alexa responds by saying ‘Turning off room light.’ and the green LED is off. When saying ‘Alexa, ask raspberry to tell me current temperature and humidity in my room’, Alexa responds by saying ‘The temperature is 26.0 degrees Celsius, and the hu- midity is 32.0 percent in the room. When saying ‘Alexa, ask raspberry to turn on kitchen light’, Alexa responds by saying ‘Turning on kitchen light.’ and the red LED, which is called as ‘kitchen light’, is on. When saying ‘Alexa, ask raspberry to turn off kitchen

26

light’, Alexa responds by saying ‘Turning off kitchen light.’ and the red LED is off. Therefore, it can be confirmed that the system works properly.

Figure 16. Result of the Demonstration

5 Conclusion

The purpose of this project was to turn on and off LEDs, read the temperature and hu- midity from DHT11 sensor by using voice command tool called Alexa. The data are sent to Raspberry Pi 3 through Ngrok web server. This is the demonstration to set up and implement a simple Smart Home System.

This project focuses on the application of the IoT with the sensor, Raspberry Pi, and Ngrok server. The project was successfully done, and it is combined with some sample

27

projects, such as using Raspberry Pi as Amazon Echo and testing DHT11 sensor with Python code. It covers main aspect of the smart home devices, such as controlling light and measuring temperature. It can be also manipulated by adding more various sen- sors or relay modules that are used as a switch to turn on or off lighting equipment.

However, it is only an introduction to the smart home system, so there needs more components to make a real smart home. In the ideal smart home, everything, for exam- ple TV, fridge, and air conditioner, is connected to the Internet, and can be controlled by a mobile application or voice assistant tool. There have been many smart home products recently, including smart TV and fridge. It might be possible to connect these products to a control server which would be an application.

28

References

1 Brown Eric. "Who Needs the Internet of Things?". Linux.com. 13 September 2016. https://www.linux.com/news/who-needs-internet-things. Retrieved 23 Octo- ber 2018.

2 Rouse Margaret. "Internet of Things (IoT)". TechTarget. June 2014. http://whatis.techtarget.com/definition/Internet-of-Things. Retrieved 25 October 2018.

3 "The "Only" Coke Machine on the Internet". Carnegie Mellon University. https://www.cs.cmu.edu/~coke/history_long.txt. Retrieved 10 October 2018.

4 Palermo Frank. "Internet of Things Done Wrong Stifles Innovation". Information- Week. 7 July 2014. http://www.informationweek.com/strategic-cio/executive-in- sights-and-innovation/internet-of-things-done-wrong-stifles-innovation/a/d- id/1279157. Retrieved 10 November 2018.

5 Mattern Friedemann, Floerkemeier Christian. "From the Internet of Computer to the Internet of Things". ETH Zurich. 2010. http://www.vs.inf.ethz.ch/publ/pa- pers/Internet-of-things.pdf. Retrieved 3 October 2018.

6 Raji R.S. "Smart networks for control". IEEE Spectrum. June 1994. http://ieeex- plore.ieee.org/xpl/login.jsp?tp=&arnumber=284793&url=http%3A%2F%2Fieeex- plore.ieee.org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D284793. Retrieved 30 October 2018.

7 Pontin Jason. "ETC: Bill Joy's Six Webs". MIT Technology Review. 29 Septem- ber 2005. http://www.technologyreview.com/view/404694/etc-bill-joys-six- webs. Retrieved 17 October 2018.

8 Ashton Kevin. "That 'Internet of Things' Thing". RFID Journal. 22 June 2009. http://www.rfidjournal.com/articles/view?4986. Retrieved 9 October 2018.

9 Huvio Eero, Grönvall John, Främling Kary. “Tracking and tracing parcels using a distributed computing approach”. Proceedings of the 14th Annual Conference for Nordic Researchers in Logistics (NOFOMA 2002). Trondheim, Norway. 12–14 June 2002. pp. 29-43.

10 Främling Kary. “Tracking of material flow by an Internet-based product data man- agement system (in Finnish: Tavaravirran seuranta osana Internet-pohjaista tuotetiedon hallintaa)”. Tieke EDISTY magazine No. 1. Publication of Tieke (Finn- ish Information Society Development Centre). Finland, 2002. pp. 24-25.

11 Främling Kary, Holoström Jan, Ala-risku Timo, Kärkkainen Mikko. “Product agents for handling information about physical objects”. Report of Laboratory of Information Processing Science Series B, TKO-B 153/03, Helsinki University of Technology, 2003. 20 p.

12 Evans Dave. "The Internet of Things: How the Next Evolution of the Internet Is Changing Everything". CISCO white paper. April

29

2011. https://www.cisco.com/c/dam/en_us/about/ac79/docs/in- nov/IoT_IBSG_0411FINAL.pdf. Retrieved 20 October 2018.

13 Nordrum Amy. "Popular Internet of Things Forecast of 50 Billion Devices by 2020 Is Outdated". IEEE. 18 August 2016. https://spectrum.ieee.org/tech-talk/tele- com/internet/popular-internet-of-things-forecast-of-50-billion-devices-by-2020-is- outdated.

14 Lindner Tim. "The Supply Chain: Changing at the Speed of Technology". Con- nected World. 13 July 2015. http://connectedworld.com/the-supply-chain-chang- ing-at-the-speed-of-technology. Retrieved 18 September 2018.

15 Apendix F of Disruptive Technologies Global Trends 2025. page 1 Figure 15 (Background: The Internet of Things). http://www.dni.gov/nic/PDF_GIF_confre- ports/disruptivetech/appendix_F.pdf. Retrieved 22 October 2018.

16 Hsu Chin-Lung Lin, Judy Chuan-Chuan. "An empirical examination of consumer adoption of Internet of Things services: Network externalities and concern for in- formation privacy perspectives". Computers in Human Behavior. 62: 516–527. 2016. https://doi.org/10.1016/j.chb.2016.04.023. Retrieved 29 October 2018.

17 "Smarter Things: The Autonomous IoT". GDR Blog. GDR Creative Intelligence. 5 January 2018. http://gdruk.com/smarter-things-autonomous-iot. Retrieved 26 September 2018.

18 Delicato F.C., Al-Anbuky A., Wang K. "Smart Cyber-Physical Systems: towards Pervasive Intelligence systems". Future Generation Computer Systems. Elsevier. 2018. https://www.journals.elsevier.com/future-generation-computer-sys- tems/call-for-papers/smart-cyber-physical-systems-towards-pervasive-intelli- gence. Retrieved 26 October 2018.

19 Pal Arpan. "Internet of Things: Making the Hype a Reality". IT Pro. May/June 2015. http://www.computer.org/cms/Computer.org/ComputingNow/is- sues/2015/07/mit2015030002.pdf. Retrieved 30 October 2018.

20 Stamford Conn. "Gartner Says 6.4 Billion Connected "Things" Will Be in Use in 2016, Up 30 Percent From 2015". Gartner. 10 November 2015. http://www.gart- ner.com/newsroom/id/3165317. Retrieved 21 October 2018.

21 Marginean Marcel-Titus, Lu Chao. "sDOMO for home ro- botic systems in the context of the internet of things". Computer Science, Tech- nology And Application. 2016. pp. 151–60. https://books.google.com/books?id=OGltDQAAQBAJ&pg=PAPA151. Retrieved 29 October 2018.

22 Rowayda A. Sadek. “An Agile Internet of Things (IoT) based Software Defined Network (SDN) Architecture". Egyptian Computer Science Journal. May 2018. http://ecsjournal.org/Archive/Volume42/Issue2/2.pdf. Retrieved 1 November 2018.

30

23 Meola Andrew, "How IoT & smart home automation will change the way we live". Business Insider. 02 September 2016. http://www.businessinsider.com/in- ternet-of-things-smart-home-automation-2016-8. Retrieved 10 October 2018.

24 Liang Steve. "OGC SensorThings API standard specification". OGC. 18 June 2015. https://portal.opengeospatial.org/files/?artifact_id=64146. Retrieved 15 September 2018.

25 Minteer A. "Chapter 9: Applying Geospatial Analytics to IoT Data". Analytics for the Internet of Things (IoT). Packt Publishing. 2017. pp. 230– 57. https://books.google.fi/books?id=FedDDwAAQBAJ&pg=PAPA230&re- dir_esc=y#v=onepage&q&f=false.

26 Gassée J.-L. "Internet of Things: The "Basket of Remotes" Problem". Monday Note. 12 January 2014. http://www.mondaynote.com/2014/01/12/internet-of- things-the-basket-of-remotes-problem/. Retrieved 26 September 2018.

27 de Sousa M. "Chapter 10: Integrating with Muzzley". Internet of Things with Intel Galileo. Packt Publishing. 2015. p. 163. https://books.google.fi/books?id=CFtICgAAQBAJ&pg=PAPA163&re- dir_esc=y#v=onepage&q&f=false.

28 Guhathakurta Rahul. "How IoT's are Changing the Fundamentals of "Retail- ing"". Trak.in – Indian Business of Tech, Mobile & Startups. 30 August 2016. https://trak.in/tags/business/2016/08/30/internet-of-things-iot-changing-fundamen- tals-of-retailing/. Retrieved 2 November 2018.

29 Kang Won Min, Moon Seo Yeon, Park Jong Hyuk. "An enhanced security frame- work for home appliances in smart home". Human-centric Computing and Infor- mation Sciences. 5 March 2017. https://hcis-jour- nal.springeropen.com/track/pdf/10.1186/s13673-017-0087-4?site=hcis-jour- nal.springeropen.com. Retrieved 3 November 2018.

30 Wollerton Megan. "Here's everything you need to know about Apple HomeKit". CNET. 03 June 2018. https://www.cnet.com/news/apple-homekit-eve- rything-you-need-to-know/. Retrieved 19 September 2018.

31 Lovejoy Ben. "HomeKit devices getting more affordable as Lenovo announces Smart Home Essentials line". 9to5Mac. 31 August 2018. https://9to5mac.com/2018/08/31/cheap-homekit-bulbs-switches-camera/. Re- trieved 19 September 2018.

32 Prospero Mike. "Best Smart Home Hubs of 2018". Tom's Guide. 1 November 2018. https://www.tomsguide.com/us/best-smart-home-hubs,review-3200.html. Retrieved 3 November 2018.

33 Bohn Dieter. "You can finally say 'Computer' to your Echo to command it". . 23 January 2017. https://www.theverge.com/tldr/2017/1/23/14365338/am- azon-echo-alexa-computer-wake-word-star-trek. Retrieved 28 September 2018.

31

34 Stone Brad, Soper Spencer. "Amazon Unveils a Listening, Talking, Music-Playing Speaker for Your Home". Bloomberg Businessweek. 6 November 2014. http://www.businessweek.com/articles/2014-11-06/amazon-echo-is-a-listening- talking-music-playing-speaker-for-your-home. Retrieved 7 October 2018.

35 Soper Taylor. “Amazon's first-ever Super Bowl commercial stars Alec Baldwin, Dan Marino, Missy Elliott”. Geekwire. 7 February 2016. http://www.geekwire.com/2016/amazons-first-ever-super-bowl-commercial-stars- alec-baldwin-dan-marino-missy-elliott/. Retrieved 5 October 2018.

36 “Amazon Echo Black (1st Generation)”. Amazon.com. https://images-na.ssl-im- ages-amazon.com/images/I/618dZBTlsCL._SX466_.jpg.

37 Etherington Darrell. "Amazon Unbundles Alexa Virtual Assistant from Echo with New Dev Tools". TechCrunch. AOL. 25 June 2015. https://techcrunch.com/2015/06/25/amazon-unbundles-alexa-virtual-assistant- from-echo-with-new-dev-tools/. Retrieved 17 October 2018.

38 Calore Michael. "HomePod Review: Only Apple Devotees Need Ap- ply". Wired. 14 February 2018. https://www.wired.com/review/review-apple- homepod/. Retrieved 4 November 2018.

39 Gil Lory, Sargent Mikah. "Everything about HomePod". iMore. 12 September 2018. https://www.imore.com/homepod-faq. Retrieved 29 October 2018.

40 Axon Samuel. “With HomePod around the corner, Siri’s “give me the news” fea- ture exits beta”. ArsTechnica. 18 January 2018. https://cdn.arstechnica.net/wp- content/uploads/2018/01/homepod.png. Retrieved 3 November 2018.

41 Hein Buster. "Leaked audio reveal HomePod's cool UI sounds - Cult of Mac". 1 August 2017. https://www.cultofmac.com/495557/homepod-ui-sounds/. Retrieved 4 November 2018.

42 Palladino Valentina. "Apple clarifies which audio sources are supported on HomePod speakers". Ars Technica. 1 February 2018. https://arstech- nica.com/gadgets/2018/02/apple-clarifies-which-audio-sources-are-supported-on- homepod-speakers/. Retrieved 4 November 2018.

43 Faden Andrew. "BabelPod: Line-In and Bluetooth Input for HomePod". faden.me. 18 May 2018. http://faden.me/2018/03/18/babelpod.html. Retrieved 4 November 2018.

44 E. Adam. “Can multiple icloud accounts be used with HomePod?”. Apple Inc. 26 January 2018. https://www.apple.com/shop/question/answers/homepod/can-mul- tiple-icloud-accounts-be-used-with-homepod/QACKATJKFJUD9J4UT. Retrieved 4 November 2018.

45 Tilley Aaron. "Samsung Acquires SmartThings, A Fast-Growing Home Automa- tion Startup". Forbes. 14 August 2014. https://www.forbes.com/sites/aarontil- ley/2014/08/14/samsung-smartthings-acquisition-2/. Retrieved 7 November 2018.

32

46 Nieva Richard. "Next step for connected devices? Connect the devices". CNET. 26 December 2013. http://www.cnet.com/news/next-step-for-connected-devices- connect-the-devices/. Retrieved 7 November 2018.

47 Kovach Steve. "I Turned My Tiny, Dark, And Overpriced Unit Into A 'Smart Home' For Just $US300". Business Insider. 10 February 2014. http://www.busi- nessinsider.com.au/smartthings-review-2014-2. Retrieved 7 November 2018.

48 Byrne Ciara. "Automate this! SmartThings lets you control the real world". Ven- tureBeat. 7 December 2012. https://venturebeat.com/2012/12/07/smartthings- controls-eal-world/. Retrieved 7 November 2018.

49 Crist Ry. "SmartThings surges toward connected-home supremacy". CNET. 21 May 2014. http://www.cnet.com/news/smartthings-surges-toward-connected- home-supremacy/. Retrieved 7 November 2018.

50 Lee Adriana. "Smart Home Shocker: My Cats Are Out To Get Me". ReadWrite. 6 February 2014. http://readwrite.com/2014/02/06/smart-home- cats#awesm=~ozWlMd2xAcVJdT. Retrieved 10 November 2018.

51 Cellan-Jones Rory. "A£15 computer to inspire young programmers". BBC News. 5 May 2011. http://www.bbc.co.uk/blogs/thereporters/rorycel- lanjones/2011/05/a_15_computer_to_inspire_young.html. Retrieved 18 Novem- ber 2018.

52 Upton Eben. "Ten millionth Raspberry Pi, and a new kit – Raspberry Pi". Rasp- berry Pi Foundation. 8 September 2016. https://www.raspberrypi.org/blog/ten-mil- lionth-raspberry-pi-new-kit/. Retrieved 18 November 2018.

53 Adams James. "Eben Upton talks Raspberry Pi 3". The MagPi Magazine. 29 February 2016. https://www.raspberrypi.org/magpi/pi-3-interview/. Retrieved 19 November 2018.

54 Halfacree Gareth. “Raspberry Pi 3 B+ single-board computer, supplied as a press sample by the Raspberry Pi Foundation”. 14 March 2018. https://www.flickr.com/photos/120586634@N05/39906369025/. Retrieved 20 No- vember 2018.

55 Jimblom, Mtaylor. “Raspberry GPIO”. Sparkfun. https://learn.sparkfun.com/tutori- als/raspberry-gpio/gpio-pinout. Retrieved 25 November 2018.

56 “DHT11-Temperature and Humidity Sensor”. Components101. 5 January 2018. https://components101.com/dht11-temperature-sensor. Retrieved 5 December 2018.

57 Ada Lady, “DHT11, DHT22, and AM2302 sensors”. Adafruit. 29 July 2012. https://learn.adafruit.com/dht/overview. Retrieved 7 December 2018.

58 Long Simon. "Introducing PIXEL - Raspberry Pi". Raspberry Pi. 28 September 2016. https://www.raspberrypi.org/blog/introducing-pixel/. Retrieved 28 November 2018.

33

59 “What is ngrok?”. Inconshreveable 2018 Inc. https://ngrok.com/product. Retrieved 8 December 2018.

60 Wheeler John. “Welcome to Flask-Ask”. 2016. https://flask- ask.readthedocs.io/en/latest/. Retrieved 8 December 2018.

Appendix 1 1 (4) Appendix 1. Source Code for Controlling Hardware import logging import os import Adafruit_DHT from flask import Flask from flask_ask import Ask, request, session, question, statement import RPi.GPIO as GPIO app = Flask(__name__) ask = Ask(app, "/") logging.getLogger('flask_ask').setLevel(logging.DEBUG)

STATUSON = ['on','high'] STATUSOFF = ['off','low'] STATUSDHT = ['current','high'] bedLightPin = 17 kitchenLightPin = 18 dht11 = Adafruit_DHT.DHT11 dhtPin = 4

@ask.launch def launch(): speech_text = 'Welcome to Raspberry Pi Automation.' return question(speech_text).reprompt(speech_text).sim- ple_card(speech_text) @ask.intent('GpioIntentRoom', mapping = {'status':'status'}) def Gpio_Intent_Room(status,room): GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(bedLightPin,GPIO.OUT) if status in STATUSON: GPIO.output(bedLightPin,GPIO.HIGH) return statement('Turning {} room light.'.format(status)) elif status in STATUSOFF: GPIO.output(bedLightPin,GPIO.LOW) 2

return statement('Turning {} room light.'.format(status)) else: return statement('Sorry not possible.')

@ask.intent('GpioIntentKitchen', mapping = {'status':'status'}) def Gpio_Intent_Kitchen(status,kitchen): GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(kitchenLightPin,GPIO.OUT) if status in STATUSON: GPIO.output(kitchenLightPin,GPIO.HIGH) return statement('Turning {} kitchen light.'.format(status)) elif status in STATUSOFF: GPIO.output(kitchenLightPin,GPIO.LOW) return statement('Turning {} kitchen light.'.format(status)) else: return statement('Sorry not possible.')

@ask.intent('GpioIntentDHT', mapping = {'status':'status'}) def Gpio_Intent_DHT(status, dht): GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(dhtPin,GPIO.OUT) if status in STATUSDHT: GPIO.output(dhtPin,GPIO.HIGH) humidity, temperature = Adafruit_DHT.read_retry(dht11, dhtPin) return statement('The temperature is {} degrees celsius, and the humidity is {} percent in your room.'.format(temperature, humid- ity)) else: return statement('Failed to get reading. Please try again.') @ask.session_ended def session_ended(): return "{}", 200

3

@ask.intent('AMAZON.HelpIntent') def help(): speech_text = 'You can say hello to me!' return question(speech_text).reprompt(speech_text).sim- ple_card('HelloWorld', speech_text) if __name__ == '__main__': if 'ASK_VERIFY_REQUESTS' in os.environ: verify = str(os.environ.get('ASK_VERIFY_REQUESTS', '')).lower() if verify == 'false': app.config['ASK_VERIFY_REQUESTS'] = False app.run(debug=True)

4

JSON Code for Alexa Skill { "interactionModel": { "languageModel": { "invocationName": "raspberry", "intents": [ { "name": "AMAZON.FallbackIntent", "samples": [] }, { "name": "AMAZON.CancelIntent", "samples": [] }, { "name": "AMAZON.HelpIntent", "samples": [] }, { "name": "AMAZON.StopIntent", “samples": [] }, { "name": "GpioIntentRoom", "slots": [ { "name": "status", "type": "STATUS" } ], "samples": [ "turn room light {status}", "turn {status} room light" ] }, { "name": "GpioIntentKitchen", "slots": [ { "name": "status", "type": "STA- TUS" } ], "samples": [ "turn kitchen light {status}", "turn {status} kitchen light" ] }, { "name": "GpioIntentDHT", "slots": [ { "name": "status", "type": "STATUS" } ], "samples": [ "tell me {status} temperature and humidity in my room" ] } ], "types": [ { "name": "STATUS", "values": [ { "name": { "value": "off", "synonyms": [ "Off", "low" ] } }, { "name": { "value": "on", "synonyms": [ "High", "On" ] } }, { "name": { "value": "current", "synonyms": [ "High", "On" ] } } ] }]}}}