A Prototype Air Flow Control System For Home Automation Using MQTT Over Websocket in Aws Iot Core
A Prototype Air Flow Control System For Home Automation Using MQTT Over Websocket in Aws Iot Core
A Prototype Air Flow Control System for Home Automation using MQTT over
Websocket in AWS IoT Core
Abstract—Amazon Web Services have recently developed their Previous works of other researchers include projects on
IoT platform, AWS IoT Core, which integrates all the the MQTT message broker based architecture and have
necessary functions required for developing an IoT system. integrated a separate data management component in cloud
Our objective in this paper is to explore some of those for authentication and management of resources [10]. Here
functions and their integration in our designed project. In light maintenance of the different components and message
of this, we develop and present a prototype air flow control broker makes the project complex to handle compared to
system for home automation using AWS IoT Core and MQTT using a managed IoT platform like AWS IoT.
protocol over Websocket server. The advantages obtained in Some other researchers have created their MQTT broker
the choice of modules, communication protocols and services
on AWS cloud server and verified the use of MQTT and
are explained in depth. System architecture, its
AWS as suitable for small business applications [11]. The
implementation and performance analysis are also presented.
built in IoT capabilities of AWS – AWS IoT Core - weren’t
Keywords—IoT; AWS IoT Core; MQTT; Websocket server; used in this case. A rather cumbersome method of creating a
air flow control; smart home separate broker in the available AWS server was used which
is more prone to errors and crashes.
I. INTRODUCTION In another paper the design and implementation of a
The smart home trend has been in the technology scene dynamic vehicle traffic control system in AWS IoT was
for long now with some automated connected technologies presented and evaluated [12]. Implementation and
that we couldn’t have envisioned even a decade ago. Even evaluation was done on a simulated environment, contrary
with this rapid developments in cutting edge technologies, to our real system and sensors. The evaluation results of
adoption of these by the consumers have been very slow. scalability, latency and cost were therefore less practical.
Issues that act as deterrents for consumers are security In a different paper, the authors have published data in
threats, excessive expense, and scalability and reliability AWS IoT using raspberry pi under different scenarios [13].
concerns [1]. With a lot of personal information moving Detailed implementation for only publishing the data into
around in the network, it becomes easier for hackers to pry cloud was presented and scalability, reliability, security and
into valuable information; both network and appliance cost other claimed features were justified based on this
are still not low enough to be afforded by an average implementation. Whereas in our paper we have detailed the
household; issues arise when the network needs to be entire publish - subscribe mechanism and based our
extended to more rooms or when new devices are added and performance evaluations on them.
most importantly there is the concern of unexpected In this paper, we present the prototype of a practically
software or server crashes and periodic software upgrades. implementable air flow control system based on room
For creating an IoT system that eliminates the above temperature and humidity. The prototype system utilizes the
concerns, the hardware end devices need to be affordable, newly developed AWS IoT Core, which is a user friendly
low power consuming and interoperable with each other [2]. and managed cloud service for easy connection between
The cloud services also needs to have low charges, high devices and applications. Also, we have used an open source
processing capabilities, provide data encryption, be reliable IoT platform, NodeMCU as the wifi connecting hardware
and lastly manage itself with very low user interference. end device, and temperature and humidity sensor, DHT22.
With several cloud services available and undergoing Moreover, as the communication protocol, the lightweight,
continuous upgrades, AWS IoT Core is the most low power consuming and secure MQTT protocol over
customizable and closest to integrating the desired Websocket is used. In the proposed air flow control system,
characteristics. The communication protocol to be used DHT temperature sensor connected to a NodeMCU wifi
needs to be lightweight, secure, and fast and support a large module sends data via wifi channel to a wifi/LTE enabled
number of devices. Message Queue Telemetry Transport, modem, which then communicates to the cloud through
MQTT is by far the most popular communication protocol Internet or LTE. The cloud (AWS) monitors the temperature
that supports the above mentioned properties. and humidity values, then takes decision whether to send
command for turning on the fan depending on a preset
Authorized licensed use limited to: MANIPAL INSTITUTE OF TECHNOLOGY. Downloaded on December 11,2022 at 07:33:29 UTC from IEEE Xplore. Restrictions apply.
Figure. 1. DHT22 Module
112
Authorized licensed use limited to: MANIPAL INSTITUTE OF TECHNOLOGY. Downloaded on December 11,2022 at 07:33:29 UTC from IEEE Xplore. Restrictions apply.
Figure 3. MQTT architecture
The MQTT broker connects the publishers and subscribers.
It receives all incoming messages from the publishers, Figure 4. MQTT over Websocket illustration
filters them and redistributes them accordingly such that
only specific clients receive specific messages. Flexibility ESP8266 doesn’t support TLS as of yet, so the MQTT
and speed is achieved through space, time and messages need to be packaged in a Websocket protocol as
synchronization decoupling of publisher and subscriber. The shown in Fig. 4 for communication with AWS. The MQTT
publish/subscribe model enhances scalability and processes protocol enables message delivery with low bandwidth and
on the broker are run parallel and are initiated by specific latency while the Websocket layer provides the SSL
events. security to messages. The MQTT protocol can be replaced
MQTT provides three values of QoS for each message with a more lightweight protocol without any change to the
sent. The QoS determines how the messages are sent and system and so the system can be upgraded to newer
hence ensures reliability of the system [8]. protocols very easily.
x QoS 0 – With a QoS value of 0, there is no E. AWS IoT Core
guarantee that the message reaches the destination
Amazon Web Services has developed AWS IoT Core
as there are no return acknowledgement messages.
which is a fully managed IoT cloud platform that lets
This is also the fastest way to deliver a message.
connected devices to interact with cloud services and other
x QoS 1- A QoS value of 1 ensures that the message devices securely and conveniently. The Core allows users to
is delivered at least once and it requires the easily connect to other AWS services - AWS Lambda, AWS
reception of one pair of acknowledgement message. Kinesis, AWS IoT Analytics and many more that provides a
It contains a header and so is less lightweight. range of compute, storage, networking, management,
x QoS 2 – Here actual messages are sent exactly once. analytics and other capabilities, as shown in Fig. 5. AWS
Two pairs of acknowledgement messages between with its huge computing space and variety of processing
the publisher and broker are transferred as a capabilities provide a low cost scalable infrastructure as a
handshake to ensure that the message has been sent service model. Its massive global presence with servers
exactly once. This is the slowest and also the most scattered widely and pricing policies which include an entry
reliable. level free tier, charge by usage and literally no fixed charges
Different QoS levels are suited to applications which makes it convenient for startups and growing businesses [9].
have varying needs with respect to speed and type of AWS IoT Core architecture lets users connect to server
messages sent. without the hassle of managing or updating it in addition to
2) Websocket: providing security and reliability to data transfer. It can
Websocket is a low latency, bi-directional messaging support a billion of devices at a time and also save its
protocol that allows persistent connection over a single current state as a shadow profile and update it continuously
TCP/IP connection [8]. Unlike HTTP, messages can be so that users can connect to it even when the device is
continuously sent once the connection has been made until offline. The Core provides end to end encryption on the data
the connection is deliberately broken by one side.
Websocket was designed to be used in web applications that
need real time persistent connections, such as live chat,
video conferencing, etc.
3) MQTT over websocket:
AWS supports MQTT communication using the
Transport Layer security (TLS) cryptography protocol and
Websocket connection using the Socket Security Layer
(SSL) cryptography protocol.
113
Authorized licensed use limited to: MANIPAL INSTITUTE OF TECHNOLOGY. Downloaded on December 11,2022 at 07:33:29 UTC from IEEE Xplore. Restrictions apply.
Figure 7. MQTT initial connection
114
Authorized licensed use limited to: MANIPAL INSTITUTE OF TECHNOLOGY. Downloaded on December 11,2022 at 07:33:29 UTC from IEEE Xplore. Restrictions apply.
As previously mentioned, this paper uses publish -
subscribe mechanism for message delivery. In the message
broker in AWS IoT core, two topics were created and
named “DHT22” and “FAN”-the former where messages
from the sensor are published and the latter where the
actuator (fan) subscribes to and receives the command
messages from. Further for threshold comparison the IoT
Rules Action “CONTROL” and Lambda function
“COMMAND” are created. Sensor data published in topic
“DHT22” triggers the function “COMMAND” via the rule
“CONTROL”. Threshold comparison of the sensor inputs
takes place in the Lambda function and corresponding
outputs are generated as shown in figure 8. The command Figure 8. IoT Core setup
messages (0, 1, 2)are published in topic “FAN” to which the AWS Identity and Access Management (IAM) User
actuator subscribes. The fan responses to the commands are allows people and applications (device API in NodeMCU)
given in details in Fig 8. access to AWS accounts, while IAM Roles allow AWS
IV. IMPLEMENTATION services such as Lambda to work with AWS resources on
our behalf. IAM User generates a security credentials in the
A. AWS setup form of AWS access keys and password for authenticated
Every Client object needs to be registered as a thing in access using Signature Version 4. The Websocket layer
the AWS IoT Core. The DHT sensor in the system has been provides encryption of messages. Each User is given
registered in AWS as a thing named “Temp_sensor” and the permissions for certain actions by attaching the required
fan as the “Fan_actuator”. This registered thing has a device policies to it. AWS has its own set of policies and also
shadow through which it can be updated or communicated allows other customized policies to be created. The IAM
with using an application even when the actual device is User automatically generates device certificates for a thing
offline. The thing has a unique Amazon Resource Name for authentication on server side when the device API
(ARN), which can be used as a unique identification for that connects to that thing.
thing. It also has a REST API endpoint through which it can Two IAM USERs were created for the two clients
be connected to the physical device via NodeMCU for shown in Fig.6. Also two policies ‘publish’ and ‘subscribe’
message transfer. The thing also has other reserved MQTT were created and attached to the two USERs of publish
topics which can be used to make necessary changes to the client and subscriber client respectively. At the server end
thing shadow. the two corresponding certificates were generated. Also two
At the device end, the topic to which the DHT client IAM roles were created one for AWS rule “CONTROL”
publishes, named “DHT22” has been specified in the device and the other for Lambda function “COMMAND” and
API code in NodeMCU. The topics to which messages are necessary suggested policies were attached to them to allow
published and subscribed from together make the message access to the AWS topics.
broker [Fig 5]. The generalized events of Fig 5 are B. Client-side embedded API setup
specialized for our case in Fig 8. The Rules action
“CONTROL” an instance of AWS rules engine is activated For client side API the libraries containing the following
whenever a message is published in topic “DHT22”. The .cpp and .h files were downloaded and their header files
SQL query statement of “CONTROL” calls the Lambda were used in codes. The following headers were used -
function “COMMAND” created in AWS Lambda. The Arduino.h, Stream.h, ESP8266WiFi.h,
function after processing the threshold comparison ESP8266WiFiMulti.h, DHT.h,sha256.h, Utils.h, Hash.h,
algorithm returns the command messages as the output of WebSocketsClient.h, SPI.h, IPStack.h, Countdown.h,
the SQL query statement. The Rule “CONTROL” then MQTTClient.h, Client.h, AWSWebSocketClient.h and
publishes those messages to the topic “FAN”. The thing CircularByteBuffer.h.
“Fan_actuator” subscribes to this topic and sends it to the NodeMCU 1.0 board was downloaded and installed in
NodeMCU connected to the fan motor. arduino IDE and the customized device code for each client
was compiled and uploaded in the respective NodeMCUs.
The publisher client receives the temperature and
humidity data and sends them to its corresponding topic in
AWS.
The subscriber client receives the command messages
(0/1/2). For “0” it sends a 0V signal to the speed control pin
of motor driver; for “1” it sends a 25% high pulse width
modulation (pwm) signal of maximum voltage 5V; for “2”
it sends a 75% high pwm signal.
115
Authorized licensed use limited to: MANIPAL INSTITUTE OF TECHNOLOGY. Downloaded on December 11,2022 at 07:33:29 UTC from IEEE Xplore. Restrictions apply.
Figure 9. Hardware setup. Sensor side (right) and motor side (left) Figure 11. Protocol used and messaging types shown graphically
B. Delay analysis
Fan motor response to changes in temperature and
humidity takes around 13 seconds as observed from the
message logs in AWS console. Since the DHT sensor is
slow, around 10s have been given in code between
successive sensor readings. Another 1 second has been used
Figure 10. Power sources used. Adapter for powering fan (left) and 5V to provide adequate heap space for error-free connection. As
battery for powering the DHT sensor a result the response due to message travel takes around 2s of
C. Hardware Setup time. This time is affected by the quality of service used, but
the change in near to insignificant.
As shown in Fig. 9 and Fig.10, two NodeMCUs have
been used; one connected to the sensor (DHT22) and C. Reliability analysis
another to the actuator motor driver- lm298. The ESP8266 Observations of message transfer for over half an hour at
wifi module in the NodeMCUs communicates with the multiple instances in the AWS console did not result in a
AWS cloud via a WiFi router installed anywhere in the single message drop, which depicts the high reliability of
room. The router may connect to the cloud using Ethernet or the system. Reliability claims are further backed by the
LTE or both; enabling both capabilities increases the robust hardware end devices – DHT22 and NodeMCU. As
reliability of the system. already mentioned DHT22 ensures reliability by producing
digital signal with long transmission range and covering a
V. PERFORMANCE ANALYSIS large range of values with very low uncertainty percentage.
A brief analysis of the type of protocol in use, ratio of NodeMCU being an open source IoT platform gets free
control to data messages sent, rate of inbound and outbound upgrades and gets its bugs easily fixed. Reliability is also
messages sent and delay in message transfer have been strengthened by some features of MQTT such as Keep Alive
performed. Also, the claims for reliability, scalability and and customizable QoS levels as already briefed before.
efficiency of the system have been evaluated.
D. Scalability analysis
A. Performance metrics in AWS The proposed system can be easily expanded into a
In AWS IoT, number of successful connections made wireless sensor network (maximum 5 sensors) where the
over time, rate of incoming and outgoing messages published different nodes can communicate with each other and any of
and the protocols used are visualized graphically in their the nodes can act as a gateway. This is possible due to the
console, as shown in Fig. 11. dual – WiFi station and access point – capability of the
1st Pie chart - As illustrated in Fig. 11, message NodeMCU. Also since the open source hardware follows
transfer occurred using only MQTT protocol. open standards it is interoperable with other technologies.
2nd Pie chart - Connect messages were sent Moreover, the decoupling of end clients in the publish –
whenever the connection was lost due to channel subscribe model of MQTT and the unlimited client handling
faults and ping messages were sent whenever capability in AWS IoT Core makes expansion of any system
message timeout occurred. The areas for publish is feasible with little technical effort.
twice the area for subscribe which shows that twice
as many messages were published than subscribed. E. Power and cost efficiency analysis
This happened because messages were published to The hardware end devices used are inexpensive yet more
the topics “DHT22” and “FAN” but subscribed only than capable for our application. The devices can easily
from “FAN”. switch to low power consumption more when idle and hence
3rd Pie chart - As shown the number of outbound extend the battery life. The lightweight MQTT protocol is
messages is greater than inbound messages efficient in both power and bandwidth usage while also
ensuring low latency. AWS IoT Core as already mentioned
is suitable for small startups due to its pricing policies.
116
Authorized licensed use limited to: MANIPAL INSTITUTE OF TECHNOLOGY. Downloaded on December 11,2022 at 07:33:29 UTC from IEEE Xplore. Restrictions apply.
VI. CONCLUSION enhanced living environments” 2016 IEEE international Balck Sea
Conference on Communications and Networking (BlackSeaCom)
A prototype of a pragmatic air flow control system for 2016, pp. 1-5
home automation using recently developed AWS IoT Core, [3] DHT-sensort_sensor_library. Available URL : https:
efficient MQTT protocol over Websocket server and robust //github.com/adafruit/DHT-sensor-library
hardware end devices have been presented. The component [4] NodeMCU. Available URL: http://nodeMCU.com/index_en.html
parts, protocols, and cloud service have been chosen to [5] Beginner’s Guide to Esp8266. Available URL :
make the system easily expandable to further developments, https://tttapa.github.io/ESP8266/Chap01%20-%20ESP8266.html
resilient to failure, secure and most importantly sustainable. [6] S. Davidson, “Open-source hardware” IEEE Design & Test of
Each part of the system has been explained in depth to Computers, issue -5, vol -21 pp 456-456, 2004
support our claim. Then the system design, messaging and [7] MQTT Webpage. Available URL: https://mqtt.org
communication mechanism using the newly developed [8] MQTT Essentials. Available URL: http://www.hivemq.com/mqtt-
capabilities in AWS and the dynamic features of MQTT essentials/
protocol have been laid out. Following that, changes made [9] AWS Documentation. Available URL:
in AWS IoT Core for implementing our system have been https://aws.amazon.com/documentation/
described in details. The hardware setup has also been [10] Aykut Guner, Kaan Kurtel and Ufuk Celikkan “A Message Broker
based Architecture for Context Aware IoT Application Development”
elaborated. Lastly, performance analysis of the overall 2nd International Conference on Computer Science and Engineering
communication system has been mentioned which further (UBMK ’17) Turkey 2017
justified our assertions. [11] D. H. Kang et al., “Room Temperature Control and Fire
The prototype illustrated has several scopes of future Alarm/Supression IoT service Using MQTT on AWS,” 2017
expansion. We intend to integrate other different types of International Conference on Platform Technology and service
sensors and actuators into the system to increase its usage in (PlatCon) Busan, 2017, pp. 1-5
a smart home. Also, we intend to use other AWS services [12] William Tärneberg, Vishal Chandrasekaran and Marty Humphrey,
“Experiences Creating a Framework for Smart Traffic Control using
including AWS IoT analytics for developing a predictive AWS IOT,” 2016 IEEE/ACM 9th International Conference on Utility
analysis based system. and Cloud Computing(UCC) Shanghai, China.
[13] O. Jukić, I. Špeh and I. Heđi “Cloud-based services for Internet of
Things,” 2018 41st International Convention on Information and
REFERENCES Communication Technology, Electronics and Microelectronics
[1] Malik Nadeem Anwar, Mohammad Nazir and Khurram Mustafa (MIPRO) Opatija, Croatia.
“Security threats toxonomy: Smart-home perspective” 2017 3rd
International Conference on Advances in Computing,Communication
& Automation (ICACCA) 2017, pp.1-4
[2] Ennio Gambi, Laura Montanini, Laura Raffaeli, Susanna Spinsante
and Lambros Lambrinos “Interoperability in IoT infrastructure for
117
Authorized licensed use limited to: MANIPAL INSTITUTE OF TECHNOLOGY. Downloaded on December 11,2022 at 07:33:29 UTC from IEEE Xplore. Restrictions apply.