MQTT Based Environment Monitoring in Factories For Employee Safety
MQTT Based Environment Monitoring in Factories For Employee Safety
Abstract
Safety of employees, in any industry, especially at the factory level is one
of the most important aspects to be considered by businesses. This is of
paramount importance, both for the well-being of the employees and that of the
corporation as a whole. In factories where working conditions are harsh and
employees need to take great caution while going about their work, it is
common for mishaps to occur. With numbers going as high as into the
thousands it is important that there is a measure of safety for the employees
from any possible hazardous situations. As a solution to this problem, a
monitoring system to be installed in factories. With this system, we will be able
to monitor critical safety parameters of the working environment in these
factories so that we are well-aware of the safety situation and the possibility of
occurrence of any mishap. For the design of this system, we use an ESP8266
Wi-Fi chip enabled microcontroller NodeMCU.To this are connected three
sensors - one to monitor temperature and humidity ( DHT sensor ), an ultrasonic
sensor ( HC-04 ) and a smoke sensor( MQ2 sensor ). these sensors continually
monitor the environment in the workplace and upload the data onto the Losant
IoT Platform, which is one of the most powerful cloud platforms which help
monitor data by different visualizations and further provisions.
Introduction
With rapid industrial development, there have been a drastically increased
number of factories all over India in all sectors. With this development, the
spurious outburst of factories have unfortunately not been accompanied by the
required and regulated safety standards set by the National Policy on Safety,
Health and Environment at Workplace. There are plenty of problems that plague
the workers working in factories with hazardous environments. The main
problems that affect the workers in a typical factory are the environmental
conditions, namely, temperature and humidity, the presence of potentially
harming and dangerous equipment used in the factory, and the possibility of a
fire outbreak itself in the factory. So for a more employee-friendly and safe
atmosphere to prevent accidents there is the need for a system which can
continually monitor the situation in the factory and send the data in an
understandable way to the concerned authorities so that they can monitor it and
accordingly act when there is any mishap to avoid escalation of the problem or
when there is the possibility of an accident and alert the concerned people to
prevent it. The Internet of Things is what comes to the rescue here with us being
able to monitor the environment with several sensors and upload the data so that
it can be monitored.
Existing system
We also outlined design issues and implementation vulnerabilities, which
can contribute to the number of unsecure deployments that we found. A design
issue that we discovered (designated as CVE-2017-7653 for Mosquito, the most
popular broker), for instance, can allow a malicious client to supply invalid
data. By using the message-retain option and modifying the quality of service
(Quos), an attacker can lead clients to be flooded with the same (retained)
message over and over. Unsecure endpoints, moreover, can expose records and
leak information, some of which we found to be related to critical sectors, for
any casual attacker to see. Vulnerable endpoints can also run the risk of denial-
of-service (DoS) attacks or even be taken advantage of to gain full control.
Disadvantages
Message Queuing Telemetry Transport (MQTT) is a communication
protocol widely used in both IoT and IIoT deployments. MQTT is a publish-
subscribe protocol that facilitates one-to-many communication mediated by
brokers. Clients can publish messages to a broker and/or subscribe to a broker to
receive certain messages. Messages are organized by topics, which essentially
are “labels” that act as a system for dispatching messages to subscribers. An
internet-wide scan on exposed MQTT endpoints conducted by IO Active’s
Lucas Lundgren between 2016 and 2017 presented a clear deployment problem
among tens of thousands of unsecure MQTT hosts. A smart-home-centric
MQTT research was also released by vast this year, highlighting the lack of
secure configurations and the likelihood of misconfigurations in home devices
that use MQTT. We decided to look into the same problem include. What we
found was striking: Hundreds of thousands of MQTT host is reachable via
public-facing IP addresses. Overall, this provides attackers with millions of
exposed records. Finding exposed endpoints in virtually every country is
feasible due to the inherent openness of the protocols and publicly searchable
deployments.
Proposed system
In a nutshell, implements an MQTT protocol based communication to
send data to the cloud. The various sensors keep pushing data to the NodeMCU
which stores them temporarily in predefined variables. Then it uploads all this
data to the Losant IoT platform by publishing the data through MQTT. The
Losant account to which data is being published to will already have subscribed
to the topics which the NodeMCU. NodeMCU is an open source IoT platform.
It includes firmware which runs on the ESP8266 Wi-Fi So C from Espresso if
Systems, and hardware which is based on the ESP-12module. It is quite
compact and also affordable, making it one of the most popular choices for
many people working on IoT applications. With a RAM of 128kB and a storage
space of 4MB, it is quite light on memory and power consumption. It has one
analog and eight digital GPIOs, thus making it quite convenient to run a variety
of different applications integrating sensors and actuators with it. It is very
comfortable to work with, as it is a quite versatile device and also there is a lot
of documentation available on it on the Internet. Owing to its advantages with
respect to size, memory and power consumption, it has become one of the most
popular microcontrollers in the IoT scenario. The DHT11 sensor is a low-cost
and low-power sensor to measure the temperature and humidity in the
atmosphere. It is very inexpensive but on the downside the sensor is very basic
and slow to work, often involving a delay of around two seconds. The DHT
sensor is made up of two parts, the capacitive humidity sensor and a thermistor.
These are the two components mainly responsible for sensing humidity and
temperature respectively. The DHT sensor also includes analog to digital
conversion and sends out data in the form of a digital signal. This makes it easy
for us to read the data directly without having to do calibrations of any sort for
temperature or humidity. HC SR-04, an ultrasonic sensor is used to measure the
distance of any person approaching. The modules involved in this operation
include ultra sonic transmitter, a receiver and the requisite control circuit. The
module automatically sends ultrasonic waves which, if there is an obstacle, get
reflected back from the obstacle and reach. DHT Temperature and Humidity
Sensor back to the receiver module of the sensor. If a signal is received back,
the time taken between the transmission and reception is calculated and the
distance is accordingly calculated from the speed of the waves and the time. The
HC SR-04 operates at a voltage of 5V and draws a current of 15mA. Its
minimum range is 2cm and maximum is 400cm. The MQ2 is a sensor we use to
detect the presence of combustible gas and smoke. This sensor uses a small
heater inside with an electrochemical sensor. It is sensitive to a range of gases
and is used indoors at room temperature. It is an analog sensor which outputs an
analog value which directly corresponds to a change in voltage according to the
amount of smoke those envelopes the sensor. Higher the amount of smoke,
higher will be the value which can be read from the smoke sensor, thus enabling
us to detect the presence of smoke by setting a safe threshold value. It has a
wide detecting scope, high sensitivity and fast response time. It is a simple
design sensor with a long life and stability.
The SSD1306 OLED Display module is a 128x64 single-chip CMOS
OLED Driver with controller for organic light emitting dot matrix graphic
display system. It consists of128 segments and 64 commons. It has a 256-step
brightness control and communication with any general MCU can be done
through Serial Peripheral Interface (SPI) or I2C (Inter-Integrated Circuit). It
operates at a voltage of 1.65-3.3V.
The Losant IOT Platform is one of the most popular and powerful cloud
platforms that help users effortlessly integrate their solutions with their cloud
services to store potentially massive amounts of raw data and process them to
make sense out of them. It supports communication from billions of devices and
uses the lightweight MQTT protocol for communication. It provides robust data
collection, aggregation and different ways to visualize our accumulated data in
an easily understandable way.
Block Diagram
Advantages
The hardware and software have been appropriately set up and the code
has been successfully uploaded onto the NodeMCU, we check the results.
Firstly the updating of events including connecting to Wi-Fi, Losant platform
and publishing the sensor data via MQTT can be seen on the Serial Monitor of
the Arduino IDE. It also shows the values of sensor readings obtained, and also
the course of action being taken when a connection has not been established
successfully. This helps us analyze how the application is working and allows
us to properly editor code so that we can further optimize it. Next we open the
Losant IoT Platform and navigate to Dashboards under the Application. On the
dashboard we can see all the sensor data coming from various sensors on one
platform. So it is easy for us to gather all this data into one place and visualize it
on a user-friendly interface. This integrating of devices with the Internet of
Things makes monitoring easy and more efficient, paving the path for
improvements and consequent large-scale implementation of the application.
MQTT is one of the most popular protocols for the Internet of Things
(IoT) systems – devices connected to the internet – and for mobile web apps.
This article explores why it works so well for smart buildings. In the smart
buildings industry, where most devices will be small, mobile and have relatively
low battery power, efficiency is vital. MQTT’s messages can be as small as
2mb and are capped at a maximum size of 256mb, meaning it uses less data and
therefore less energy than some protocols, helping to conserve battery life. The
small message sizes also make it perfect for instances where bandwidth is
constrained, another important consideration for IoT systems. Because MQTT
is so well suited to use in IoT it is one of the most commonly-used protocols
and is used by some of the biggest platforms such as IBM Watson IoT and
Microsoft Azure. This means devices that use MQTT are likely to easily sync
with your existing systems. MQTT is an open protocol which means multiple
devices from different manufacturers can talk to one another. This gives you
more flexibility in designing your smart building systems and makes it easier to
adopt across a wide variety of IoT devices and platforms. Closed protocols
require you to buy all your components from one specific manufacturer in order
for them to speak to one another. In an arena where real-time data is crucial,
you need a protocol that will get information to where it’s needed as quickly as
possible. There’s little point using a smart sensor to monitor the air quality in a
room if it’s likely to have changed by the time the data appears on your
software platform. If a protocol is the method used to get data from one place to
another then MQTT could be considered as the electric car of protocols –
lightweight, fast and energy efficient. Other protocols such as HTTP are more
like diesel-powered buses better at transporting larger volumes of data from
one place to another but guzzling more fuel in the process. In the IoT world,
where speed, efficiency and agility are key, it’s easy to see why MQTT is one
of the most popular protocols if you’re looking for smart-building technology
that uses MQTT, check out our smart gateway. It converts sensor data into
MQTT protocol and makes it securely available locally or via the cloud.
SYSTEM REQUIRMENTS
Hardware Requirements
• Node MCU
• Ultrasonic Sensor
• Temperature Sensor
• Gas Sensor
• LCD Display
• Power Supply
Software Requirements
• Arduino IDE
• SQLITE Database
Hardware Requirements
Node MCU
The ESP8266 is a low-cost Wi-Fi microchip,with a full TCP/IP
tack and microcontroller capability, produced by Espressif Systems in
Shanghai, China.
ESP8266
The chip first came to the attention of Western makers in August 2014 with
the ESP-01 module, made by a third-party manufacturer Ai-Thinker. This small
module allows microcontrollers to connect to a Wi-Fi network and make simple
TCP/IP connections using Hayes-style commands. However, at first there was
almost no English-language documentation on the chip and the commands it
accepted. The very low price and the fact that there were very few external
components on the module, which suggested that it could eventually be very
inexpensive in volume, attracted many hackers to explore the module, the chip,
and the software on it, as well as to translate the Chinese documentation.
The ESP8285 is an ESP8266 with 1 MiB of built-in flash, allowing the building
of single-chip devices capable of connecting to Wi-Fi.
These microcontroller chips have been succeeded by the ESP32 family of
devices, including the pin-compatible ESP32-C3.
Features
Pinout of ESP-01
The pinout is as follows for the common ESP-01 module:
ESP-01
1. GND, Ground (0 V)
2. GPIO 2, General-purpose input/output No. 2
3. GPIO 0, General-purpose input/output No. 0
4. RX, Receive data bit X, also GPIO3
5. VCC, Voltage (+3.3 V; can handle up to 3.6 V)
6. RST, Reset
7. CH_PD, Chip power-down
8. TX, Transmit data bit X, also GPIO1
When power is applied to the module you should see the red power light turn on
and the blue serial indicator light flicker briefly.
With FTDI 3.3V Board (Legit)
If you have a 3.3V FTDI Serial to USB board you can get started without fear
of destroying your new ESP8266 Wi-Fi module. Do note that many FTDI
boards have a solder jumper to convert from 3.3V to 5V operation so ensure it is
set to enable 3.3V operation.
Serial Control
With the hardware connections in place you can communicate with the Wi-Fi
module through a serial terminal.
Using Arduino IDE Serial Monitor
If you already have the Arduino IDE installed the easiest way to get started is to
use the built-in Serial Monitor:
• Plug in the Wi-Fi module.
• Choose the correct serial port from the Tools > Serial Port menu.
• Open the Serial Monitor via the Tools menu or “magnifying glass” icon
on the editor window.
• For the default firmware version (00160901), ensure Carriage return is
selected in the line ending pop-up menu at the bottom of the serial monitor. (For
later versions it must be set to Both NL & CR)
• For the default firmware version, ensure the communication speed is set
to 115200 baud.
Using GNU Screen
It’s possible to use GNU Screen out of the box with the default version of the
firmware (00160901)
which expects Carriage-Return-only line endings, e.g. (on OS X): screen
/dev/tty.usbserial-AB12345 115200
Unfortunately the updated firmware versions require Carriage-Return-and-New-
Line line endings and
there appears to be no way to configure screen to send both with one key press.
Instead, you need to press <enter> or Ctrl-M then follow that with Ctrl-J.
You might have more success with something like minicom or picocom with
later firmware versions.
Acting as a Wi-Fi Access Point
In addition to connecting to Wi-Fi Access Points the module can also act as an
Access Point–this means you can connect devices to the module without any
other network infrastructure in place. Ideal for a local private shared “drop box”
perhaps…
1. The module comes with an access point pre-defined (SSID of “ESP_…”)
but you can define your own with:
AT+CWSAP="NoWorriESSID","password",3,0
The first parameter is the SSID name; the second parameter is the password; the
third the Wi-Fi channel–pick one not used in your area; and, the final parameter
is the encryption standard to use. An encryption value of 0 turns encryption off
which means the password is ignored–but it still can’t be an empty value. I
couldn’t get any encryption to work though (it would always create an
unencrypted network) you might have more luck–possibly with a more recent
firmware…
2. To actually enable the network to be created you need to set the “Wi-Fi
mode” of the module to “AP” (2) or “Both” (3):
AT+CWMODE=3
Now you will be able to connect to your module as an access point from another
device (e.g. a laptop or a phone).
3. You can list the IP address etc. of any device connected to the network
with:
Ultrasonic Sensor
Introduction
The HCSR04 ultrasonic sensor uses sonar to determine distance to an object
like bats or dolphins do. It offers excellent noncontact range detection with high
accuracy and stable readings in an easytouse package. From 2cm to 400 cm or
1” to 13 feet. It operation is not affected by sunlight or black material like Sharp
rangefinders are (although acoustically soft materials like cloth can be difficult
to detect). It comes complete with ultrasonic transmitter and receiver module.
As shown above the HC-SR04 Ultrasonic (US) sensor is a 4 pin module, whose
pin names are Vcc, Trigger, Echo and Ground respectively. This sensor is a
very popular sensor used in many applications where measuring distance or
sensing objects are required. The module has two eyes like projects in the front
which forms the Ultrasonic transmitter and Receiver. The sensor works with the
simple high school formula that
The Ultrasonic transmitter transmits an ultrasonic wave, this wave travels in air
and when it gets objected by any material it gets reflected back toward the
sensor this reflected wave is observed by the Ultrasonic receiver module as
shown in the picture below
Ultrasonic Sensor Working
Now, to calculate the distance using the above formulae, we should know the
Speed and time. Since we are using the Ultrasonic wave we know the universal
speed of US wave at room conditions which is 330m/s. The circuitry inbuilt on
the module will calculate the time taken for the US wave to come back and
turns on the echo pin high for that same particular amount of time, this way we
can also know the time taken. Now simply calculate the distance using a
microcontroller or microprocessor.
Power the Sensor using a regulated +5V through the Vcc ad Ground pins of
the sensor. The current consumed by the sensor is less than 15mA and hence
can be directly powered by the on board 5V pins (If available). The Trigger and
the Echo pins are both I/O pins and hence they can be connected to I/O pins of
the microcontroller. To start the measurement, the trigger pin has to be made
high for 10uS and then turned off. This action will trigger an ultrasonic wave at
frequency of 40Hz from the transmitter and the receiver will wait for the wave
to return. Once the wave is returned after it getting reflected by any object the
Echo pin goes high for a particular amount of time which will be equal to the
time taken for the wave to return back to the sensor.
The amount of time during which the Echo pin stays high is measured by the
MCU/MPU as it gives the information about the time taken for the wave to
return back to the Sensor. Using this information the distance is measured as
explained in the above heading.
Applications
Used to avoid and detect obstacles with robots like biped robot, obstacle avoider
robot, path finding robot etc.
Depth of certain places like wells, pits etc can be measured since the waves can
penetrate through water
Temperature Sensor
INTRODUCTION
Humidity is the concentration of water vapor present in the air. Water vapor, the
gaseous state of water, is generally invisible to the human eye. Humidity
indicates the likelihood for precipitation, dew, or fog to be present. The amount
of water vapor needed to achieve saturation increases as the temperature
increases. As the temperature of a parcel of air decreases it will eventually reach
the saturation point without adding or losing water mass. The amount of water
vapor contained within a parcel of air can vary significantly. For example, a
parcel of air near saturation may contain 28 grams of water per cubic metre of
air at 30 °C, but only 8 grams of water per cubic metre of air at 8 °C.
Humidity plays an important role for surface life. For animal life dependent on
perspiration (sweating) to regulate internal body temperature, high humidity
impairs heat exchange efficiency by reducing the rate of moisture evaporation
from skin surfaces. This effect can be calculated using a heat index table, also
known as a humidex.
The digital temperature and humidity sensor DHT11 is a composite sensor that
contains a calibrated digital signal output of temperature and humidity. The
technology of a dedicated digital modules collection and the temperature and
humidity sensing technology are applied to ensure that the product has high
reliability and excellent long-term stability.
Absolute humidity is the total mass of water vapor present in a given volume or
mass of air. It does not take temperature into consideration. Absolute humidity
in the atmosphere ranges from near zero to roughly 30 grams per cubic metre
when the air is saturated at 30 °C (86 °F).
Relative humidity
The relative humidity {\displaystyle (RH}{\displaystyle (RH} or
{\displaystyle \phi )}{\displaystyle \phi )} of an air-water mixture is defined as
the ratio of the partial pressure of water vapor {\displaystyle (p_{H_{2}O})}
{\displaystyle (p_{H_{2}O})} in the mixture to the equilibrium vapor pressure
of water {\displaystyle (p_{H_{2}O}^{*})}{\displaystyle (p_{H_{2}O}^{*})}
over a flat surface of pure water at a given temperature:
Specific humidity
Specific humidity (or moisture content) is the ratio of the mass of water vapor
to the total mass of the air parcel. Specific humidity is approximately equal to
the mixing ratio, which is defined as the ratio of the mass of water vapor in an
air parcel to the mass of dry air for the same parcel. As temperature decreases,
the amount of water vapor needed to reach saturation also decreases. As the
temperature of a parcel of air becomes lower it will eventually reach the point
of saturation without adding or losing water mass.
Gas Sensor
Electrochemical gas sensors are gas detectors that measure the
concentration of a target gas by oxidizing or reducing the target gas at an
electrode and measuring the resulting current.
GAS SENSORS
Construction
THEORY OF OPERATION
The gas diffuses into the sensor, through the back of the porous
membrane to the working electrode where it is oxidized or reduced. This
electrochemical reaction results in an electric current that passes through the
external circuit. In addition to measuring, amplifying and performing other
signal processing functions, the external circuit maintains the voltage across
the sensor between the working and counter electrodes for a two electrode
sensor or between the working and reference electrodes for a three electrode
cell. At the counter electrode an equal and opposite reaction occurs, such that
if the working electrode is an oxidation, then the counter electrode is a
reduction.
Cross sensitivity
CIRCUIT DIAGRAM
CIRCUIT DESCRIPTION
The gas sensor is the special sensor which designed for sense the gas
leakage. In the gas sensor the supply voltage is given to input terminal. The
gas sensor output terminals are connected to non inverting input terminal of
the comparator.
LCD Display
LIQUID CRYSTAL DISPLAY(LCD)
A liquid-crystal display (LCD) is a flat panel display, electronic visual
display, or video display that uses the light modulating properties of liquid
crystals. Liquid crystals do not emit light directly.
LCDs are available to display arbitrary images (as in a general-purpose
computer display) or fixed images which can be displayed or hidden, such as
preset words, digits, and 7-segment displays as in a digital clock. They use the
same basic technology, except that arbitrary images are made up of a large
number of small pixels, while other displays have larger elements.
LCDs are used in a wide range of applications including computer
monitors, televisions, instrument panels, aircraft cockpit displays, and signage.
They are common in consumer devices such as DVD players, gaming
devices, clocks, watches, calculators, and telephones, and have replaced cathode
ray tube (CRT) displays in most applications. They are available in a wider
range of screen sizes than CRT and plasma displays, and since they do not use
phosphors, they do not suffer image burn-in. LCDs are, however, susceptible
to image persistence.
The LCD screen is more energy efficient and can be disposed of more
safely than a CRT. Its low electrical power consumption enables it to be used
in battery-powered electronic equipment. It is an electronically modulated
optical device made up of any number of segments filled with liquid
crystals and arrayed in front of a light source (backlight) or reflector to produce
images in color or monochrome.
16×2 LCD is named so because; it has 16 Columns and 2 Rows. There are a lot
of combinations available like, 8×1, 8×2, 10×2, 16×1, etc. But the most used
one is the 16*2 LCD, hence we are using it here.
LCD Display
All the above mentioned LCD display will have 16 Pins and the programming
approach is also the same and hence the choice is left to you. Below is the
Pinout and Pin Description of 16x2 LCD Module:
Sr.
Pin No. Pin Name Pin Type Pin Description Pin Connection
No
Connected to the
This is a ground pin ground of the
1 Pin 1 Ground Source Pin
of LCD MCU/ Power
source
Connected to the
This is the supply
2 Pin 2 VCC Source Pin supply pin of
voltage pin of LCD
Power source
Connected to a
Adjusts the contrast
3 Pin 3 V0/VEE Control Pin variable POT that
of the LCD.
can source 0-5V
4 Pin 4 Register Control Pin Toggles between Connected to a
Select Command/Data MCU pin and gets
Register either 0 or 1.
0 -> Command
Mode
1-> Read
Operation
Must be held high to Connected to
6 Pin 6 Enable Control Pin perform Read/Write MCU and always
Operation held high.
In 4-Wire Mode
It is okay if you do not understand the function of all the pins, I will be
explaining in detail below. Now, let us turn back our LCD:
Okay, what is this two black circle like things on the back of our LCD?
These black circles consist of an interface IC and its associated components to
help us use this LCD with the MCU. Because our LCD is a 16*2 Dot matrix
LCD and so it will have (16*2=32) 32 characters in total and each character will
be made of 5*8 Pixel Dots. A Single character with all its Pixels enabled is
shown in the below picture.
So Now, we know that each character has (5*8=40) 40 Pixels and for 32
Characters we will have (32*40) 1280 Pixels. Further, the LCD should also be
instructed about the Position of the Pixels.
It will be a hectic task to handle everything with the help of MCU, hence an
Interface IC like HD44780 is used, which is mounted on LCD Module itself.
The function of this IC is to get the Commands and Data from the MCU and
process them to display meaningful information onto our LCD Screen.
Let’s discuss the different type of mode and options available in our LCD that
has to be controlled by our Control Pins.
The LCD can work in two different modes, namely the 4-bit mode and the 8-bit
mode. In 4 bit mode we send the data nibble by nibble, first upper nibble and
then lower nibble. For those of you who don’t know what a nibble is: a nibble is
a group of four bits, so the lower four bits (D0-D3) of a byte form the lower
nibble while the upper four bits (D4-D7) of a byte form the higher nibble. This
enables us to send 8 bit data.
Whereas in 8 bit mode we can send the 8-bit data directly in one stroke since we
use all the 8 data lines.
Now you must have guessed it, Yes 8-bit mode is faster and flawless than 4-bit
mode. But the major drawback is that it needs 8 data lines connected to the
microcontroller. This will make us run out of I/O pins on our MCU, so 4-bit
mode is widely used. No control pins are used to set these modes. It's just the
way of programming that change.
LCD Commands:
There are some preset commands instructions in LCD, which we need to send to
LCD through some microcontroller. Some important command instructions are
given below:
Power Supply
SMPS
A switched-mode power supply (switching-mode power supply, switch-mode
power supply, switched power supply, SMPS, or switcher) is an electronic
power supply that incorporates a switching regulator to convert electrical power
efficiently. Like other power supplies, an SMPS transfers power from a DC or
AC source (often mains power) to DC loads, such as a personal computer, while
converting voltage and current characteristics. Unlike a linear power supply, the
pass transistor of a switching-mode supply continually switches between low-
dissipation, full-on and full-off states, and spends very little time in the high
dissipation transitions, which minimizes wasted energy.. Voltage regulation is
achieved by varying the ratio of on-to-off time (also known as duty cycles). In
contrast, a linear power supply regulates the output voltage by continually
issipating power in the pass transistor.
Switching regulators are used as replacements for linear regulators when higher
efficiency, smaller size or lighter weight are required. They are, however, more
complicated; their switching currents can cause electrical noise problems if not
carefully suppressed, and simple designs may have a poor power factor.
Explanation:
A linear power supply (non-SMPS) uses a linear regulator to provide the desired
output voltage by dissipating excess power in ohmic losses (e.g., in a resistor or
in the collector–emitter region of a pass transistor in its active mode). A linear
regulator regulates either output voltage or current by dissipating the excess
electric power in the form of heat, and hence its maximum power efficiency is
voltage-out/voltage-in since the volt difference is wasted.
In a SMPS, the output current flow depends on the input power signal, the
storage elements and circuit topologies used, and also on the pattern used (e.g.,
pulse-width modulation with an adjustable duty cycle) to drive the switching
elements. The spectral density of these switching waveforms has energy
concentrated at relatively high frequencies. As such, switching transients and
ripple introduced onto the output waveforms can be filtered with a small LC
filter.
Other advantages include smaller size, lower noise, and lighter weight from the
elimination of heavy line-frequency transformers, and comparable heat
generation. Standby power loss is often much less than transformers.
Very low cost SMPSs may couple electrical switching noise back onto the
mains power line, causing interference with devices connected to the same
phase, such as A/V equipment.
Arduino IDE
Writing Sketches
Programs written using Arduino Software (IDE) are called sketches. These
sketches are written in the text editor and are saved with the file extension .ino.
The editor has features for cutting/pasting and for searching/replacing text. The
message area gives feedback while saving and exporting and also displays
errors. The console displays text output by the Arduino Software (IDE),
including complete error messages and other information. The bottom right-
hand corner of the window displays the configured board and serial port. The
toolbar buttons allow you to verify and upload programs, create, open, and save
sketches, and open the serial monitor.
NB: Versions of the Arduino Software (IDE) prior to 1.0 saved sketches with
the extension .pde. It is possible to open these files with version 1.0, you will be
prompted to save the sketch with the .ino extension on save.
Verify
Upload
Note: If you are using an external programmer with your board, you can
hold down the "shift" key on your computer when using this icon. The
text will change to "Upload using Programmer"
New
Creates a new sketch.
Open
Presents a menu of all the sketches in your sketchbook. Clicking one will
open it within the current window overwriting its content.
Note: due to a bug in Java, this menu doesn't scroll; if you need to open a
sketch late in the list, use the File | Sketchbook menu instead.
Save
Saves your sketch.
Serial Monitor
Opens the serial monitor.
Additional commands are found within the five menus:
File, Edit, Sketch, Tools, Help. The menus are context sensitive, which means
only those items relevant to the work currently being carried out are available.
File
• New
Creates a new instance of the editor, with the bare minimum structure of a
sketch already in place.
• Open
Allows to load a sketch file browsing through the computer drives and folders.
• Open Recent
• Sketchbook
Shows the current sketches within the sketchbook folder structure; clicking on
any name opens the corresponding sketch in a new editor instance.
• Examples
• Close
• Save
Saves the sketch with the current name. If the file hasn't been named before, a
name will be provided in a "Save as” window.
• Save as...
• Page Setup
Sends the current sketch to the printer according to the settings defined in Page
Setup.
• Preferences
Opens the Preferences window where some settings of the IDE may be
customized, as the language of the IDE interface.
• Quit
Closes all IDE windows. The same sketches open when Quit was chosen will be
automatically reopened the next time you start the IDE.
Edit
• Undo/Redo
Goes back of one or more steps you did while editing; when you go back, you
may go forward with Redo.
• Cut
Removes the selected text from the editor and places it into the clipboard.
• Copy
Duplicates the selected text in the editor and places it into the clipboard.
Copies the code of your sketch to the clipboard in a form suitable for posting to
the forum, complete with syntax coloring.
• Copy as HTML
Copies the code of your sketch to the clipboard as HTML, suitable for
embedding in web pages.
• Paste
Puts the contents of the clipboard at the cursor position, in the editor.
• Select All
Selects and highlights the whole content of the editor.
• Comment/Uncomment
Puts or removes the // comment marker at the beginning of each selected line.
• Increase/Decrease Indent
Adds or subtracts a space at the beginning of each selected line, moving the text
one space on the right or eliminating a space at the beginning.
• Find
Opens the Find and Replace window where you can specify text to search inside
the current sketch according to several options.
• Find Next
Highlights the next occurrence - if any - of the string specified as the search
item in the Find window, relative to the cursor position.
• Find Previous
Highlights the previous occurrence - if any - of the string specified as the search
item in the Find window relative to the cursor position.
Sketch
• Verify/Compile
Checks your sketch for errors compiling it; it will report memory usage for code
and variables in the console area.
• Upload
Compiles and loads the binary file onto the configured board through the
configured Port.
This will overwrite the bootloader on the board; you will need to use Tools >
Burn Bootloader to restore it and be able to Upload to USB serial port again.
However, it allows you to use the full capacity of the Flash memory for your
sketch. Please note that this command will NOT burn the fuses. To do so a
Tools -> Burn
Saves a .hex file that may be kept as archive or sent to the board using other
tools.
• Include Library
• Add File...
Adds a source file to the sketch (it will be copied from its current location). The
new file appears in a new tab in the sketch window. Files can be removed from
the sketch using the tab menu accessible clicking on the small triangle icon
below the serial monitor one on the right side of the toolbar.
Tools
• Auto Format
This formats your code nicely: i.e. indents it so that opening and closing curly
braces line up, and that the statements inside curly braces are indented more.
• Archive Sketch
Archives a copy of the current sketch in .zip format. The archive is placed in the
same directory as the sketch.
• Fix Encoding & Reload
Fixes possible discrepancies between the editor char map encoding and other
operating systems char maps.
• Serial Monitor
Opens the serial monitor window and initiates the exchange of data with any
connected board on the currently selected Port. This usually resets the board, if
the board supports Reset over serial port opening.
• Board
Select the board that you're using. See below for descriptions of the various
boards.
• Port
This menu contains all the serial devices (real or virtual) on your machine. It
should automatically refresh every time you open the top-level tools menu.
• Programmer
• Burn Bootloader
The items in this menu allow you to burn a bootloader onto the microcontroller
on an Arduino board. This is not required for normal use of an Arduino or
Genuino board but is useful if you purchase a new ATmega microcontroller
(which normally come without a bootloader). Ensure that you've selected the
correct board from
the Boards menu before burning the bootloader on the target board. This
command also set the right fuses.
Help
Here you find easy access to a number of documents that come with the
Arduino Software (IDE). You have access to Getting Started, Reference, this
guide to the IDE and other documents locally, without an internet connection.
The documents are a local copy of the online ones and may link back to our
online website.
• Find in Reference
This is the only interactive function of the Help menu: it directly selects the
relevant page in the local copy of the Reference for the function or command
under the cursor Sketchbook
The Arduino Software (IDE) uses the concept of a sketchbook: a standard place
to store your programs (or sketches). The sketches in your sketchbook can be
opened from the File > Sketchbook menu or from the Open button on the
toolbar. The first time you run the Arduino software, it will automatically create
a directory for your sketchbook. You can view or change the location of the
sketchbook location from with the Preferences dialog.
Beginning with version 1.0, files are saved with a .ino file extension. Previous
versions use the .pde extension. You may still open .pde named files in version
1.0 and later, the software will automatically rename the extension to .ino. Tabs,
Multiple Files, and Compilation
Allows you to manage sketches with more than one file (each of which appears
in its own tab). These can be normal Arduino code files (no visible extension),
C files (.c extension), C++ files (.cpp), or header files (.h).
Uploading
Before uploading your sketch, you need to select the correct items from the
Tools > Board and Tools > Port menus. The boards are described below. On the
Mac, the serial port is probably something like /dev/tty.usbmodem241 (for a
Uno or Mega2560 or Leonardo) or /dev/tty.usbserial-1B1 (for a Duemilanove or
earlier USB board), or/dev/tty.USA19QW1b1P1.1 (for a serial board connected
with a Key span USB-to-Serial adapter). On Windows, it's probably COM1 or
COM2 (for a serial board) or COM4, COM5, COM7, or higher (for a USB
board) - to find out, you look for USB serial device in the ports section of the
Windows Device Manager. On Linux, it should be /dev/ttyACMx,
/dev/ttyUSBx or similar. Once you've selected the correct serial port and board,
press the upload button in the toolbar or select the Upload item from the
File menu. Current Arduino boards will reset automatically and begin the
upload. With older boards (pre-Decimal) that lack auto-reset, you'll need to
press the reset button on the board just before starting the upload. On most
boards, you'll see the RX and TX LEDs blink as the sketch is uploaded. The
Arduino Software (IDE) will display a message when the upload is complete, or
show an error.
When you upload a sketch, you're using the Arduino bootloader, a small
program that has been loaded on to the microcontroller on your board. It allows
you to upload code without using any additional hardware. The bootloader is
active for a few seconds when the board resets; then it starts whichever sketch
was most recently uploaded to the microcontroller. The bootloader will blink
the on-board (pin 13) LED when it starts (i.e. when the board resets).
Libraries
Libraries provide extra functionality for use in sketches, e.g. working with
hardware or manipulating data. To use a library in a sketch, select it from the
Sketch
Import Library menu. This will insert one or more #include statements at the top
of the sketch and compile the library with your sketch. Because libraries are
uploaded to the board with your sketch, they increase the amount of space it
takes up. If a sketch no longer needs a library, simply delete its #include
statements from the top of your code.
There is a list of libraries in the reference. Some libraries are included with the
Arduino software. Others can be downloaded from a variety of sources or
through the Library Manager. Starting with version 1.0.5 of the IDE, you do can
import a library from a zip file and use it in an open sketch. See these
instructions for installing a third-party library.
Third-Party Hardware
Support for third-party hardware can be added to the hardware directory of your
sketchbook directory. Platforms installed there may include board definitions
(which appear in the board menu), core libraries, bootloaders, and programmer
definitions. To install, create the hardware directory, then unzip the third-party
platform into its own sub-directory. (Don't use "arduino" as the sub-directory
name or you'll override the built-in Arduino platform.) To uninstall, simply
delete its directory.
Serial Monitor
Displays serial data being sent from the Arduino or Genuino board (USB or
serial board). To send data to the board, enter text and click on the "send" button
or press enter. Choose the baud rate from the drop-down that matches the rate
passed to Serial. Begin in your sketch. Note that on Windows, Mac or Linux,
the Arduino or Genuino board will reset (rerun your sketch execution to the
beginning) when you connect with the serial monitor.
Preferences
Some preferences can be set in the preferences dialog (found under the
Arduino menu on the Mac, or File on Windows and Linux). The rest can be
found in the preferences file, whose location is shown in the preference dialog.
Language Support
Since version 1.0.1, the Arduino Software (IDE) has been translated into 30+
different languages. By default, the IDE loads in the language selected by your
operating system. (Note: on Windows and possibly Linux, this is determined by
the locale setting which controls currency and date formats, not by the language
the operating system is displayed in.)
If you would like to change the language manually, start the Arduino Software
(IDE) and open the Preferences window. Next to the Editor Language there is a
dropdown menu of currently supported languages. Select your preferred
language
from the menu, and restart the software to use the selected language. If your
operating system language is not supported, the Arduino Software (IDE) will
default to English.
You can return the software to its default setting of selecting its language based
on your operating system by selecting System Default from the Editor
Language drop-down. This setting will take effect when you restart the Arduino
Software (IDE). Similarly, after changing your operating system's settings, you
must restart the Arduino Software (IDE) to update it to the new default
language.
Boards
The board selection has two effects: it sets the parameters (e.g. CPU speed and
baud rate) used when compiling and uploading sketches; and sets and the file
and fuse settings used by the burn bootloader command. Some of the board
definitions differ only in the latter, so even if you've been uploading
successfully with a particular selection you'll want to check it before burning the
bootloader. You can find a comparison table between the various boards here.
Arduino Software (IDE) includes the built in support for the boards in the
following list, all based on the AVR Core. The Boards Manager included in the
standard installation allows to add support for the growing number of new
boards based on different cores like Arduino Due, Arduino Zero, Edison, and
Galileo and soon.
SQLITE Database
SQLite is a relational database management system (RDBMS) contained
in a C library. In contrast to many other database management systems, SQLite
is not a client–server database engine. Rather, it is embedded into the end
program.
This means that one can, for example, insert a string into a column defined as an
integer. SQLite will attempt to convert data between formats where appropriate,
the string "123" into an integer in this case, but does not guarantee such
conversions and will store the data as-is if such a conversion is not possible.
DESIGN
SQLite stores the entire database (definitions, tables, indices, and the data itself)
as a single cross-platform file on a host machine. It implements this simple
design by locking the entire database file during writing. SQLite read operations
can be multitasked, though writes can only be performed sequentially.
implies that it is specialized for running servers on it. This often implies that it
is more powerful and reliable than standard personal computers, but
alternatively, large computing clusters may be composed of many relatively
simple, replaceable server components.
OPRATION
Originally used as "servers serve users" (and "users use servers"), in the sense
of "obey", today one often says that "servers serve data", in the same sense as
"give". For instance, web servers "serve [up] web pages to users" or "service
their requests".
The server is part of the client–server model; in this model, a server serves data
for clients. The nature of communication between a client and server is request
and response. This is in contrast with peer-to-peer model in which the
relationship is on-demand reciprocation. In principle, any computerized process
that can be used or called by another process (particularly remotely, particularly
to share a resource) is a server, and the calling process or processes is a client.
Thus any general-purpose computer connected to a network can host servers.
For example, if files on a device are shared by some process, that process is a
file server. Similarly, web server software can run on any capable computer,
and so a laptop or a personal computer can host a web server.
MQTT
The MQTT protocol defines two types of network entities: a message broker
and a number of clients. An MQTT broker is a server that receives all messages
from the clients and then routes the messages to the appropriate destination
clients. An MQTT client is any device (from a micro controller up to a full-
fledged server) that runs an MQTT library and connects to an MQTT broker
over a network.
MQTT connection
When a publishing client first connects to the broker, it can set up a default
message to be sent to subscribers if the broker detects that the publishing client
has unexpectedly disconnected from the broker.
Clients only interact with a broker, but a system may contain several broker
servers that exchange data based on their current subscribers' topics.
MQTT relies on the TCP protocol for data transmission. A variant, MQTT-SN,
is used over other transports such as UDP or Bluetooth.
MQTT sends connection credentials in plain text format and does not include
any measures for security or authentication. This can be provided by using TLS
to encrypt and protect the transferred information against interception,
modification or forgery.
The default unencrypted MQTT port is 1883. The encrypted port is 8883.
HTTP SERVER
The Hypertext Transfer Protocol (HTTP) is an application layer protocol for
distributed, collaborative, hypermedia information systems. HTTP is the
foundation of data communication for the World Wide Web, where hypertext
documents include hyperlinks to other resources that the user can easily access,
for example by a mouse click or by tapping the screen in a web browser.
HTTP/2 is a more efficient expression of HTTP's semantics "on the wire", and
was published in 2015; it is now supported by virtually all web browsers and
major web servers over Transport Layer Security (TLS) using an Application-
Layer Protocol Negotiation (ALPN) extension where TLS 1.2 or newer is
required.
The primary function of a web server is to store, process and deliver web pages
to clients. The communication between client and server takes place using the
Hypertext Transfer Protocol (HTTP). Pages delivered are most frequently
HTML documents, which may include images, style sheets and scripts in
addition to the text content.
Multiple web servers may be used for a high traffic website; here, Dell servers
are installed together being used for the Wikimedia Foundation.
This usually means that no additional software has to be installed on the client
computer since only a web browser is required (which now is included with
most operating systems).
Literature review
With the rapid development of the Internet, especially in recent years, the
development of mobile Internet is increasingly rapid. Message push, which is an
important way for mobile client to publish information and make
communication, plays a significant role in mobile Internet. MQTT protocol is
one of the implementation technologies of message push in Android system
with low power consumption and high scalability. In addition, it can save
internet traffic, so it has been used in many applications. Meanwhile, as a
distributed message queue, Rocket MQ has great advantages in distributed
deployment of servers. It has the characteristics of high performance, high
reliability and high real time ability. The MQTT protocol and the application of
Rocket MQ, and implements a MQTT protocol message push server based on
Rocket MQ through the combination of Rocket MQ and Mosquito.
Conclusion
Reference
[[1] Ravi Kishore Kodali, Borade Samar Sarjerao, A Lost Cost Smart Ir-rigation
System using MQTT Protocol, IEEE Region 10 Symposium(TENSYMP), 14-
16 July, 2017. Cochin, India.
[2] Ravi Kishore Kodali, Snehashish Mandal, IoT Based Weather Station,2016
International Conference on Control, Instrumentation, Communication and
Computation Technologies (ICCICCT), 16-17 December, 2016.Kumaracoil,
India.
[3] Ravi Kishore Kodali, Archana Sahu, An IoT based soil moisture monitoring on
Losant platform, 2nd International Conference on Contemporary Computing
and Informatics (IC3I), 14-17 Dec. 2016. Noida, India.
[4] Ravi Kishore Kodali; Kopulwar Shishir Mahesh, A low cost implementation of
MQTT using ESP8266, 2nd International Conference on Contemporary
Computing and Informatics (IC3I), 14-17 Dec. 2016,Noida, India.
[5] S. Robla-Gmez; V. M. Becerra; J. R. LLata; E. Gonzlez-Sarabia; C.Torre-
Ferrero; J. Prez-Oria, Working Together: A Review on Safe Human-Robot
Collaboration in Industrial Environments, IEEE Access, , 2017.
[6] Mohammed Al-Soh; Imran A. Zualkernan, An MQTT-Based Context-Aware
Wearable Assessment Platform for Smart Watches, IEEE 17thInternational
Conference on Advanced Learning Technologies (ICALT),2017, Timisoara,
Romania.
[7] Ravi Kishore Kodali; Kopulwar Shishir Mahesh, Low cost ambient monitoring
using ESP8266, 2nd International Conference on Contemporary Computing and
Informatics (IC3I), 14-17 Dec. 2016, Noida, India.
[8] Ma Yue; Yan Ruiyang; Sun Jianwei; Yao Kaifeng A MQTT Protocol Message
Push Server Based on RocketMQ, 10th International Conference on Intelligent
Computation Technology and Automation (ICICTA), 2017,Changsha, China.
[9] Naili Shofa; Andrian Rakhmatsyah; Siti Amatullah Karimah, Infusion
monitoring using WiFi (802.11) through MQTT protocol, 5th Inter-national
Conference on Information and Communication Technology(ICoIC7), 2017,
Malacca City, Malaysia.
[10] Vania; Kanisius Karyono; I. Hargyo Tri Nugroho, Smart dog feeder design
using wireless communication, MQTT and Android client, International
Conference on Computer, Control, Informatics and its Applications(IC3INA),
2016, Tangerang, Indonesia.