Presented at Serverless Days 2019, Jaipur, India. The talk focusses on the integration and use of serverless APIs for Internet of Things applications to be used in home automation.
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
IOT and Home Automation with Serverless Computing | Serverless Days 2019 | Sonal Raj | Jaipur
1. 1S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
S E R V E R L E S S D A Y S 2 0 1 9
IOT and Home Automation
Serverless Computing
JAIPUR, INDIA
@Sonal Raj
2. 2S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Hi, I’m Sonal …
3. 3S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
… and here
is where you
can find me
4. 4S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
What’s the plan for this
hour?
S E R V E R L E S S D A Y S 2 0 1 9
5. 5S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
I Internet
of Things
S
Serverless
Z
Python
C
Create
D
Ideas
6. 6S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Senses
7. 7S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Your location
Your state of motion and
direction
Orientation of the
device
Ambience or light in the
room
Proximity to a surface
Can listen to what you
say
See things in front and
behind it.
Transfer Info over a
wireless network
8. 8S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Raspberry Pi 3B+ Arduino PLC / PAC
9. 9S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
What does a simple
IOT setup look like?
10. 10S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
11. 11S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
12. 12S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
13. 13S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Internet
Enabled
Support Digital
Assistants
Smart Phone
Controls
Programmable
APIs
14. 14S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
15. 15S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Architecture
16. 16S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Smart
Homes
17. 17S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Smart
Cities
18. 18S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Serverless
Computing
19. 19S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
20. 20S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
21. 21S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Event Triggers
22. 22S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Serverless Providers
23. 23S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
How it all
works?
24. 24S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Static Websites, Web Apps,
Flask Packages
Backend Apps and Services,
Mobile and IOT
Data Processing in Real Time,
Batch or MapReduce
Creating logic for chatbots
Voice enabled apps and skills
in Alexa assistants
Automation of Services and
Infrastructure management
Applications
25. 25S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Using Python
26. 26S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Can setup REST APIs on
serverless architectures
Message Queueing
Telemetry Transport Libmraa – Low level Communication
library for linux
27. 27S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
pyopencv – Image and
Video Processing
library
Audio and Sound Processing
in Python Micropython
28. 28S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
A Flask extension that has wrappers for the
common constructs for the alexa skills API.
• Has decorators to map Alexa requests and intent slots to view functions
• Helps construct ask and tell responses, re-prompts and cards
• Makes session management easy
• Allows for the separation of code and speech through Jinja templates
• Verifies Alexa request signatures
29. 29S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Lambda/Function structure
for IOT
Lambda Handlers
Parse incoming request message
based on type/context
Event / Session Handlers
Handle launch events and
session events
Response Builders Custom logic and API to
generate response based on
parsed input and sends back
30. 30S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
What can you integrate in
lambdas?
• REST APIs / Http Servers
• Database querying scripts.
• Kafka Queues
• Randomized generators
• Filtering and transforming data on the fly
• Automated backups and everyday tasks and Reports
• Log analysis on the fly
31. 31S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Lambda Tips and Tricks
• Lambda Functions are recycled. Subsequent invocation are redeployed &
add latency. Worse if networked.
32. 32S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Lambda Tips and Tricks
• If you are using Node 4.*, upgrade! OpenSSL bug causes SSL connections
will fail without cause intermittently, but only if you’re using DynamoDB.
Just upgrade to Node 6.x
• Try and Avoid Global State Usage! Containers are reused, it’s possible to
stuff data into global memory and, with a good probability, it will be there in
the next invocation.
33. 33S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Lambda Tips and Tricks
• Keep timeouts to a minimum. Most async library operations come along
with long default timeout periods. NodeJs has default of 2 minutes. Alexa
expects an answer in 7.5s. Keeps applications well behaved.
• User friendly error logging. Make sure that you log custom metrics for
tracking these “soft errors” since Lambda’s invocation error metrics won’t
be relevant anymore. (Cloudwatch on AWS helps!)
34. 34S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Function Limitations
35. 35S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Creating Serverless
APIs for IOT
36. 36S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Code Walkthrough
and Demo
37. 37S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
“Alexa, ask Zomato for the nearest [restaurantType]”
Invocation Name
Slot
Utterance
Intent
What a user must say to
“start” the skill. Each skill
has a unique Invocation
Name
A variable within an
utterance. Variable
possibilities must be
defined.
The spoken message is
mapped to an intent which
decides what code to run
within your skill.
A spoken phrase that
maps to an intent. A skill
can have many
utterances.
38. 38S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Echosim.io
Simulator
39. 39S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
How the future
looks like?
40. 40S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
AlexaBot
https://github.com/jacobajit/AlexaBot
41. 41S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Event driven, serverless
chatbots architecture
42. 42S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
https://goo.gl/UEzRGo
Google Assistant on Your
Amazon Echo
43. 43S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Using data from fitness trackers . . .
• Continuous HR data – detect spikes, stroke patterns, anxiety
• Calorie estimation from step count, and alert when you need to eat.
• Alerting triggers based on thresholds
• Create APIs to connect other devices like glucometers, and Blood
Pressure monitors.
• Publish data to a central store, with web visualization support.
44. 44S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
• Interactive Social Networks
• Interactive Idea boards
• Voice Gaming
• Crisis Alerting
• Office Integration – Meeting room bookings, etc.
• Always aware state.
The Future
45. 45S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
Smart
Problems!
46. 46S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
47. 47S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Internet of Things Serverless Python Create Ideas
48. 48S L I D EJ a i p u r , I n d i a S E R V E R L E S S D A Y S 2 0 1 9- [ ] -
Questions
github.com/sonal-raj/serverlessdays2019