0% found this document useful (0 votes)
19 views62 pages

BKLight

The document describes a project to build an automatic street light monitoring system using IoT technology. It discusses the theoretical background, system design, hardware components, and implementation of the system. The system uses sensors to monitor streetlights and send data to a server via LoRa modules and WiFi. The data is displayed on a web interface to monitor the lights remotely.

Uploaded by

đặng thành
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views62 pages

BKLight

The document describes a project to build an automatic street light monitoring system using IoT technology. It discusses the theoretical background, system design, hardware components, and implementation of the system. The system uses sensors to monitor streetlights and send data to a server via LoRa modules and WiFi. The data is displayed on a web interface to monitor the lights remotely.

Uploaded by

đặng thành
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

FPT SOFTWARE

PROJECT
IOT CHALLENGE 2023

Topic

AUTOMATIC STREET
LIGHT MONITORING SYSTEM

Mentor: NGUYEN TUAN ANH


BKLight: NGUYEN PHUONG NAM
VU MINH HIEU
PHAM THANH TAM
DANG TAT THANH
VU DUC MINH

Ha Noi, September 20, 2023


PREFACE

Today, 70% of global electricity is generated by burning fossil fuels, a source of


air and greenhouse gas pollution, with approximately 300 million streetlights worldwide
running on electricity. In order to raise awareness of energy-efficient and effective elec-
tricity usage, many countries around the world have implemented solutions to upgrade
public lighting systems - a move that has helped France reduce energy consumption by
up to 65%.
Currently, in Vietnam, lighting electricity accounts for approximately 35% of total
electricity consumption, whereas globally, this ratio is only about 17-25%. There are
several reasons for this 35% figure, but the fundamental causes lie in outdated lighting
technology and operational methods, as well as a large number of lights due to rapid
urbanization.
With the aforementioned issues and the rapid development of IoT technology in
Vietnam, the desire is to provide people with a automatic street lighting solution, utiliz-
ing a digital technology system, and incorporating sensors capable of providing accurate
data. This data can then be used as a basis for implementing improvements to the street
lighting system, resulting in high efficiency, time savings, and reduced effort for the
management system
For these reasons, our group has decided to undertake the project "Automatic Street
Light Monitoring System". The aim is to enhance the monitoring capabilities of envi-
ronmental conditions for crop cultivation in order to make timely decisions for climate
control and create a better environment for crop growth
This project aims to construct a model of a automatic street lighting system that
addresses the weaknesses of previous systems, with the goal of creating the best possible
product that can be integrated into daily life.
Ensure efficient operation, compact size, ease of installation, and transportability.
Research content:

• Research and understand the theoretical foundations underlying the topic.

• Investigate and select hardware components such as power sources, sensor modules,
microcontrollers, and control circuits using suitable peripheral devices.

• Study the EFR32xG24, how to interact with the sensors used in the project.

• Research and write code for the EFR32xG24 to implement desired functions, com-
municate with peripherals, and create a Website that meets all requirements.
• Complete the model, assess and evaluate the achieved results.

• Finalize the report and presentation.

• Complete a video demonstration of the product.

System functions:

• The system has the capability to automatically dim the light intensity based on
motion, ambient light levels, and user-defined settings via the Website.

• It monitors the lights (using current sensing sensors) and provides alerts on the
Website when these parameters deviate from normal conditions.

• It displays real-time values for each streetlight and historical notifications on the
Website.

• Communication is established through the Website.

The report is structured into four chapters with the following main content:

• Chapter 1: Theoretical Foundations.

• Chapter 2: System Design.

• Chapter 3: System Implementation.

• Chapter 4: Conclusion and Future Development.

Based on the results presented in Chapter 3, an evaluation of the system’s strengths and
weaknesses will be conducted. Subsequently, conclusions will be drawn, and directions
for further development of the project will be proposed.

2
CLAIM

We are BKLight, a team of IoT Challenge 2023. Our advisor for this project is
Mr. Nguyen Tuan Anh. We hereby declare that the entire content presented in this
document is our original work. We confirm that all citations and references adhere to
the regulations of intellectual property, and that all sources have been accurately and
clearly listed. We take full responsibility for all the contents written in this thesis.

Ha Noi, September 20, 2023


Declarant

BKLight
TABLE OF CONTENTS

LIST OF FIGURES 7

ABSTRACT 8

CHAPTER 1. THEORETICAL BASIS 1


1.1 Overview of automatic street light system . . . . . . . . . . . . . . . . 1
1.2 Advantages and disadvantages of automatic street light systems . . . . . 1
1.2.1 Advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2.2 Disadvantages . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 IoT application in street light system . . . . . . . . . . . . . . . . . . . 2
1.3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.2 Basic structure of an IoT system . . . . . . . . . . . . . . . . . 2
1.3.3 IoT application in street lighting system . . . . . . . . . . . . . 3
1.4 Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.1 Concept of microcontroller . . . . . . . . . . . . . . . . . . . . 4
1.4.2 The role of microcontrollers in IoT . . . . . . . . . . . . . . . . 4
1.5 Data transmission standard, connection standard . . . . . . . . . . . . . 5
1.5.1 Module -> Kit -> Gateway . . . . . . . . . . . . . . . . . . . . 5
1.5.2 Gateway -> Server: MQTT . . . . . . . . . . . . . . . . . . . . 7
1.6 Web server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6.1 Introduction to Streamlit . . . . . . . . . . . . . . . . . . . . . 9
1.6.2 System design and analysis . . . . . . . . . . . . . . . . . . . . 10
1.6.3 Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.6.4 User Interface Design . . . . . . . . . . . . . . . . . . . . . . 13
1.7 System security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.7.1 Node - Gateway Security (AES-128) . . . . . . . . . . . . . . . 16
1.7.2 MQTT Broker Security (TLS/SSL) . . . . . . . . . . . . . . . 20
1.8 Introduction to Hardware . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.8.1 Power supply 12V - 5A . . . . . . . . . . . . . . . . . . . . . . 22
1.8.2 Module Lora . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.8.3 Motion sensor module HC - SR602 . . . . . . . . . . . . . . . 27
1.8.4 BH1750 intensity measuring sensor module . . . . . . . . . . . 28
1.8.5 ACS712 current measurement sensor module . . . . . . . . . . 29
1.8.6 LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.8.7 Kit EFR32xG24 EK2703 . . . . . . . . . . . . . . . . . . . . . 31
1.8.8 Raspberry pi 4B . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.9 Chapter conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

CHAPTER 2. SYSTEM DESIGN 35


2.1 System overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.1.1 Control each light via iot . . . . . . . . . . . . . . . . . . . . . 35
2.1.2 Dimming LED . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.2 System block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.3 Chapter conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

CHAPTER 3. SYSTEM CONSTRUCTION 40


3.1 Install software and programming on EFR32xG24 . . . . . . . . . . . . 40
3.2 Install software and programming on Raspberry pi . . . . . . . . . . . 40
3.2.1 Install CMake . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.2.2 Install Mosquitto . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.3 Proceed with programming . . . . . . . . . . . . . . . . . . . . . . . . 41
3.3.1 Algorithmic flow chart of the system . . . . . . . . . . . . . . 41
3.3.2 Web programming . . . . . . . . . . . . . . . . . . . . . . . . 47
3.4 Prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.5 Product evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

CONCLUSION 51
REFERENCES 53

6
LIST OF FIGURES

Figure 1.1 Basic structure of an IoT system . . . . . . . . . . . . . . . . . . 3


Figure 1.2 I2C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 1.3 UART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 1.4 MQTT Broker . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 1.5 Power supply 12V - 5A . . . . . . . . . . . . . . . . . . . . . . 23
Figure 1.6 Module LoRa E32 SX1278 . . . . . . . . . . . . . . . . . . . . 24
Figure 1.7 Motion sensor module HC - SR602 . . . . . . . . . . . . . . . . 28
Figure 1.8 BH1750 intensity measuring sensor module . . . . . . . . . . . 29
Figure 1.9 ACS712 current measurement sensor module . . . . . . . . . . 30
Figure 1.10 LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Figure 1.11 Kit EFR32xG24 EK2703 . . . . . . . . . . . . . . . . . . . . . 32
Figure 1.12 Raspberry pi 4B . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Figure 2.1 System block diagram . . . . . . . . . . . . . . . . . . . . . . . 38
Figure 3.1 Simplicity Studio 5 . . . . . . . . . . . . . . . . . . . . . . . . 40
Figure 3.2 System’s block diagram . . . . . . . . . . . . . . . . . . . . . . 41
Figure 3.3 Example data frame between Node and Gateway . . . . . . . . . 47
Figure 3.4 Data frame between Gateway and Database/Web . . . . . . . . . 47
Figure 3.5 Prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

7
ABSTRACT

The Smart Street Light Monitoring System is an innovative solution designed to


enhance urban lighting infrastructure by integrating cutting-edge technology and intel-
ligent monitoring capabilities. In an era of urbanization and sustainability, this system
offers efficient management of street lighting networks, optimizing energy consumption,
reducing maintenance costs, and improving overall urban safety and aesthetics.
This system leverages Internet of Things (IoT) technology to connect individual
street lights to a centralized control platform. Through this connectivity, it enables real-
time monitoring, remote control, and data analysis of street lights. Various sensors and
smart algorithms ensure adaptive lighting control, allowing the system to adjust lumi-
nosity based on ambient light levels and pedestrian or vehicular traffic. Additionally, it
can detect faulty or malfunctioning lights, enabling prompt maintenance and reducing
downtime.
The Smart Street Light Monitoring System provides numerous benefits, including
energy conservation by dimming or turning off lights when not needed, reducing carbon
emissions, and lowering energy bills for municipalities. Moreover, it enhances public
safety by ensuring well-lit streets at all times, contributing to crime prevention and road
safety.
This abstract highlights the significance of the Smart Street Light Monitoring Sys-
tem as a sustainable, cost-effective, and intelligent solution for modern urban environ-
ments. Its ability to transform traditional street lighting into a smart, connected network
represents a step towards more efficient, eco-friendly, and safer cities.

8
CHAPTER 1. THEORETICAL BASIS

1.1 Overview of automatic street light system


The Automatic Street Lighting System is an integral part of transforming cities into
Smart Cities and enhancing community life. This system employs modern technology to
optimize the management and control of streetlights in urban areas, offering numerous
benefits ranging from energy savings to improved traffic safety.

1.2 Advantages and disadvantages of automatic street light systems


1.2.1 Advantages
Energy and Cost Savings: The Automatic Street Lighting System helps opti-
mize energy usage by adjusting lighting based on real-time needs, thereby reduc-
ing energy consumption and operational costs.
Enhanced Security: Integrated cameras and sensors in streetlights can improve
security in the area. They can detect incidents such as traffic accidents or unlaw-
ful activities and provide valuable data to law enforcement.
Traffic Information Integration: The system has the capability to integrate with
other traffic information systems, enhancing traffic flow and reducing conges-
tion.
Real-Time Feedback: The system provides real-time information on the sta-
tus of streetlights, making it easier for management to address issues and plan
maintenance.

1.2.2 Disadvantages
Initial Deployment Costs: Implementing a automatic street lighting system re-
quires a significant upfront investment in purchasing and installing sensors, cam-
era systems, and management software.
Security and Privacy: Since this system often involves collecting and transmit-
ting data from sensors and cameras, data security and privacy are crucial consid-
erations. Measures must be in place to protect data to avoid personal information
leaks.
Technical Issues and Malfunctions: The system can encounter technical issues
such as network disconnections or sensor malfunctions, requiring regular main-
tenance to maintain optimal performance.
Public Response: Some individuals may oppose the use of automatic street
lighting systems due to concerns about privacy rights or fears of potential exces-

1
sive surveillance and control measures.
Dependency on Energy and Power Grid: The system relies on a stable energy
supply and power grid, so disruptions in energy infrastructure and the power grid
can impact system operations.

1.3 IoT application in street light system


1.3.1 Introduction
Since first introduced nearly 20 years ago, up to the present day, IoT applications
have been one of the fastest-growing technology sectors in the Industry 4.0 revolution.
They have emerged and positively impacted every industry and field, including street
lighting systems. The application of IoT in street lighting systems brings many benefits,
including enhanced performance, energy savings, and improved system management.

1.3.2 Basic structure of an IoT system


The IoT architecture is fundamentally represented by four components: Things,
Gateways, Network and Cloud infrastructure, and Service creation and Solutions Layers.

• Things: Nowadays, there are billions of devices existing in the consumer and tech-
nology markets, both indoors and in the hands of users. Examples include cars,
sensors, wearables, and mobile phones that are directly connected through wireless
network bands and have internet access. IoT solutions enable smart devices to be
screened, connected, and manage data locally, while non-smart devices can connect
through gateways.

• Gateways: A major challenge in IoT deployment is that around 85% of devices are
not designed to connect to the internet and cannot share data with cloud computing.
To address this issue, gateways act as direct intermediaries, allowing these existing
devices to securely connect to cloud computing and easily manage them.

• Network and Cloud Infrastructure:


Network infrastructure: The internet is a global system of interconnected IP
networks, linked together with computer systems. This network infrastructure in-
cludes routers, gateways, aggregation devices, switches, and various other devices
capable of controlling data traffic and is also connected to the telecommunications
and cable networks deployed by service providers.
Data center/cloud computing infrastructure: Data centers and cloud computing
infrastructure comprise a large system of servers, storage systems, and virtualized
networks.

2
• Service Layers: These are applications created by technology companies or even
users to efficiently use IoT products and fully leverage their value.

Figure 1.1 Basic structure of an IoT system

1.3.3 IoT application in street lighting system


Street lighting and public illumination are vital community services within a city’s
overall infrastructure. However, with outdated street lighting systems and inefficient
management methods, up to 40% of a city’s energy budget can be consumed. IoT-
based street lighting systems, using Internet of Things (IoT) technology, which combines
public lighting sensors and promising new energy-saving technologies, are becoming a
replacement for the entire conventional public lighting system.

• Reducing energy consumption of public lighting by controlling the on-off schedule


of the lights. This phase can be controlled by using environmental light level sensors
or integrated timers.

• Adjusting and reducing light intensity by lowering the voltage flow to each light,
thereby saving electricity.

• Utilizing high-performance lights and devices, including integrated smart devices


capable of self-adjustment, automatic power source detection, and issues related to
lights such as: measuring and transmitting data on light status, light levels, energy
consumption, voltage, current, and power factor; receiving commands to turn on/off
and control the lights.

3
On the other hand, the remote central management system must have the capability
to control and monitor each individual light. With this system, operators can monitor
key parameters of any lamppost or light bulb from a control room or through mobile
devices. The collected data can be analyzed, allowing for statistical calculations and
forecasts of consumption, bulb lifespan, voltage, faults, etc. This method enables a shift
from reactive maintenance processes to proactive maintenance processes with the aim
of cost and time savings.
On a broader scale, smart public lighting systems allow cities and municipalities
to adjust and enforce lighting strategies tailored to specific conditions such as changing
light intensity, color, time, and location suitable for various areas and different user
groups.

1.4 Microcontroller
1.4.1 Concept of microcontroller
The term ’microcontroller’ is commonly used to refer to various types of embed-
ded processors or microprocessors, specifically electronic devices used to control the
operation of other systems and devices. Microcontrollers are typically used in a wide
range of applications, including controlling smart home devices, medical equipment,
automobiles, industrial machinery, and many other applications.
Microcontrollers are often programmed to perform specific tasks, ranging from
simple tasks like turning on/off an LED light to more complex tasks like controlling
and managing automated systems. Microcontrollers have the capability to interact with
various sensors and output devices to carry out defined tasks.

1.4.2 The role of microcontrollers in IoT


Microcontrollers play a crucial role in the Internet of Things (IoT) by serving as
the primary component to control and manage connected devices within the IoT network.
Below are some important roles of microcontrollers in IoT:

• Device Control: Microcontrollers act as the brains of IoT devices, executing spe-
cific control functions based on data from sensors and network information.

• Data Collection: Microcontrollers can be configured to collect data from various


sensors such as temperature sensors, humidity sensors, light sensors, pressure sen-
sors, and many other types of sensors. This data can then be transmitted to central
systems for processing and analysis.

• Network Communication: Microcontrollers are often integrated with network con-


nectivity protocols such as Wi-Fi, Bluetooth, Zigbee, LoRa, or other protocols de-

4
pending on the specific application. This enables IoT devices to connect to the
network and send data to servers or other devices.

• Basic Data Processing: Microcontrollers often perform some basic data processing
before sending it, helping reduce network load and optimize bandwidth usage.

• Energy Efficiency: In IoT, microcontrollers often need to operate under energy-


efficient conditions to extend battery life or conserve power sources. They have the
ability to switch to power-saving modes or disable unnecessary functions to save
energy.

• Security: Microcontrollers must have data and device security capabilities. They
often integrate security features such as data encryption, authentication, and access
control.

• User Interaction: In some cases, microcontrollers may be used to interact with users
through a user interface, such as a touchscreen or LED lights to display notifications
or device status.

In summary, microcontrollers are a critical component in IoT systems, perform-


ing various essential functions for control, data collection, communication, and security
within the IoT network.

1.5 Data transmission standard, connection standard


1.5.1 Module -> Kit -> Gateway
1. I2C (BH1750) I2C stands for Inter-Integrated Circuit. It is a bus interface connec-
tion protocol incorporated into devices for serial communication. It was originally
designed by Philips Semiconductor in 1982. Recently, it is a widely used protocol
for short-distance communication. It is also known as Two Wired Interface(TWI).

2. UART UART stands for universal asynchronous receiver / transmitter and defines
a protocol, or set of rules, for exchanging serial data between two devices. UART
is very simple and only uses two wires between transmitter and receiver to transmit
and receive in both directions. Both ends also have a ground connection. Commu-
nication in UART can be simplex (data is sent in one direction only), half-duplex
(each side speaks but only one at a time), or full-duplex (both sides can transmit
simultaneously). Data in UART is transmitted in the form of frames. The format
and content of these frames is briefly described and explained.

3. LoRa

5
Figure 1.2 I2C

Figure 1.3 UART

(a) Definition LoRa (Long Range) is a wireless communication technology that


enables long-range, low-power transmission of data between devices. It utilizes
a modulation technique called Chirp Spread Spectrum (CSS) to transmit data
over long distances without requiring a significant amount of power.
(b) Advantages:
• Long range: LoRa signal can travel multiple miles from 1 - 10 km or more.
• Low power usage: The devices are inexpensive and can run for years with-
out needing a battery change.
• Suitable to IoT devices: This creates the ability to monitor devices that are
difficult to access or out of range for wifi or cell service.
(c) Disadvantages: The caveat to this wonderful technology is the limited amount
of bandwidth it offers.

6
• Low bandwidth: In order to have such a long range and extended battery
life, the frequency of a LoRa transmission must be very low.
• More bandwidth vs. range: The more data you want to transfer at a time,
the less distance and more battery you use. While it may seem pointless if
you can’t use it to stream Netflix, there are plenty of cases where range and
reliability trump bandwidth.
(d) Main terminologies: Four main configuration terminologies in LoRA.
• Frequency: Commonly 433 MHz (Asia), 868 MHz (Europe) and 915 MHz
(North America).
• Preamble Length: A LoRa frame begins with a preamble. After the pream-
ble, there is an optional header. E.g: 8 bits.
• Spreading Factor: Number of bits encoded per symbol. The higher the
spreading, the faster bandwidth and the shorter range. Eg: 7, 9, 12...
• Signal bandwidth: The width of spectrum occupied by the chirp (the sig-
nal). E.g: 125Kbps
• Coding Rate: This is a measure for the amount of forward error correction.
E.g: 4/5

1.5.2 Gateway -> Server: MQTT


MQTT is simple, lightweight messaging protocol used to establish communication
between multiple devices. It is TCP-based protocol relying on the publish-subscribe
model. This communication protocol is suitable for transmitting data between resource-
constrained devices having low bandwidth and low power requirements. Hence this
messaging protocol is widely used for communication in IoT Framework.
Publish-Subscribe Model: This model involves multiple clients interacting with
each other, without having any direct connection established between them. All clients
communicate with other clients only via third party known as Broker.

1.6 Web server


Using the web as an interface for an IoT (Internet of Things) project offers several
compelling reasons that make it a practical and effective choice. Here are some of the
key reasons for using a web-based interface in IoT projects:

• Accessibility: Cross-Device Compatibility: Web interfaces can be accessed from a


wide range of devices, including smartphones, tablets, laptops, and desktop com-
puters. This ensures that users can control and monitor IoT devices from the device
of their choice.

7
Figure 1.4 MQTT Broker

• Remote Access: Global Accessibility: Web interfaces enable remote access to IoT
devices and systems from anywhere with an internet connection. This is particularly
useful for monitoring and managing IoT devices that are geographically dispersed.

• User-Friendly: Intuitive Design: Web interfaces can be designed to be intuitive and


user-friendly, making it easier for individuals, including those without technical
expertise, to interact with IoT devices.

• Scalability: Easily Scalable: Web applications are scalable and can accommodate
an increasing number of IoT devices as your project grows. This scalability is es-
sential as the number of connected devices in IoT projects often expands over time.

• Real-Time Updates: Real-Time Feedback: Web interfaces can provide real-time


updates and feedback, ensuring that users have the most up-to-date information
about their IoT devices and can take immediate actions as needed.

• Remote Control: Remote Configuration: Users can remotely configure and con-
trol IoT devices through web interfaces, which is especially valuable for tasks like
adjusting settings, turning devices on/off, or changing operational parameters.

• Security: Authentication and Authorization: Web interfaces can implement robust


security features such as user authentication and authorization mechanisms to pro-
tect sensitive IoT data and control access.

8
• User Management: User Profiles: Web interfaces can support user profiles, allow-
ing different users to have customized access and permissions, ensuring that only
authorized personnel can control and monitor specific IoT devices.

• Cloud Integration: Cloud Services: Web interfaces can be integrated with cloud
services, providing a centralized platform for managing and analyzing data from
multiple IoT devices.

• Reduced Deployment Costs: No App Installation: Web-based interfaces eliminate


the need for users to install specific apps on their devices, reducing deployment and
maintenance costs.

In summary, using the web as an interface for IoT projects offers a versatile, ac-
cessible, and user-friendly means of interacting with and managing connected devices.
It ensures that users can harness the full potential of IoT technology while benefiting
from real-time updates, scalability, and robust security measures. The web’s reach and
adaptability make it a valuable choice for IoT projects across various industries and use
cases.
In this project, we choose Streamlit as the main framework to deploy our IOT app,
the link is here

1.6.1 Introduction to Streamlit


Streamlit is an open-source Python library designed for creating web applications
with minimal effort and maximum functionality. It is particularly well-suited for data
science and IoT projects because it allows developers to transform data scripts into share-
able web apps quickly.
Streamlit’s key features include:

• Rapid Prototyping: Streamlit eliminates much of the boilerplate code typically


required for web development. With just a few lines of Python code, you can create
interactive web apps.

• Ease of Use: Its simple and intuitive API enables developers, including those with
minimal web development experience, to build interactive interfaces effortlessly.

• Data Integration: Streamlit seamlessly integrates with popular data science li-
braries like Pandas, Matplotlib, and Plotly, making it ideal for visualizing and ana-
lyzing IoT data.

• Real-time Updates: It allows for dynamic content updates, which is crucial for IoT
applications that require real-time monitoring and control.

9
• Customization: While it offers a straightforward path to web app creation, Stream-
lit also supports customization for more complex projects.

1.6.2 System design and analysis


In this project, we decided to build a data-driven website. Data-driven web pro-
gramming not only helps organizations efficiently manage information but also provides
users with new interactive experiences. Below are some important functional and non-
functional requirements for developing data-driven web applications.

1. Functional Requirements:

• On/Off Control: Users should have the ability to turn street lights on or off
individually or collectively. This control ensures efficient energy usage and
allows for the activation of lights only when necessary.
• Dimming Functionality: The application should provide a dimming feature for
each street light. Users can adjust the brightness level to save energy during
low traffic hours or to create different lighting scenarios.
• Time-Based Scheduling: Users should be able to set specific schedules for each
street light or group of lights. This scheduling feature allows for automated
control, ensuring that lights are on when needed and off when not required.
• Data Visualization: The web application should display real-time data on the
status of each street light, including whether they are currently on, off, or
dimmed. This data can help users monitor the system’s performance.
• Dead Light Notifications: The system should have a mechanism to detect and
notify users when a street light is malfunctioning or "dead." This could include
sending alerts through the web interface or via email/SMS notifications.
• Gateway Health Monitoring: The application should also monitor the health of
gateways or communication devices that connect the street lights to the central
control system. If a gateway goes offline or malfunctions, the system should
notify administrators for prompt troubleshooting.
• User Authentication and Authorization: Implement a secure user authentication
and authorization system to ensure that only authorized personnel can access
and control the street lights and system settings.
• Audit Trail: Maintain an audit trail to log all actions related to street light con-
trol, scheduling changes, and system notifications. This log can be valuable for
accountability and troubleshooting.

10
• Grouping and Zoning: Allow users to group street lights based on geographic
location, usage patterns, or other criteria. This simplifies management and
control, especially for large-scale deployments.

2. Non-Functional Requirements:

• Performance: The system must have good performance to process and display
data quickly, especially for large datasets.
• Engaging User Interface: The user interface needs to be designed attractively
and user-friendly to provide a good user experience.
• Data Security Assurance: Data must be tightly secured to ensure the privacy of
personal and business information.
• Integration Support: The system needs to support integration with other sys-
tems and services to create a robust data ecosystem.
• Documentation and Support: Provide documentation and support for users and
developers to help them effectively use the application.

1.6.3 Database
The database used here is Supabase, a modern open-source alternative to tradi-
tional backend as a service (BaaS) platforms. Supabase provides developers with a pow-
erful set of tools for building serverless applications, simplifying database management,
authentication, and real-time features.

1. Supabase: A Brief Overview


Supabase is an open-source platform that offers a suite of backend services and
tools to streamline the development of web and mobile applications. It is built on
top of PostgreSQL, one of the most advanced open-source relational databases. Key
features of Supabase include:

• Database Management: Supabase simplifies database setup and management,


providing a PostgreSQL database that can be easily configured and accessed
through APIs.
• Authentication: It offers user authentication and authorization out of the box,
making it effortless to secure your applications and manage user access.
• Real-Time: Supabase supports real-time updates, enabling instant data syn-
chronization between clients, which is valuable in scenarios where data changes
need to be reflected immediately.

11
• API Generation: Supabase automatically generates APIs for database tables,
reducing the amount of boilerplate code needed to interact with data.
• Custom Functions: Developers can write custom serverless functions using
JavaScript or TypeScript and deploy them directly on Supabase for added flex-
ibility.

2. Database of Street Light-IOT project:

• Account Table:
Id (int): unique id for each account.
(text): username.
Password (text): encrypted password.
• Light Table:
Lightid (int): A unique identifier for each street light (primary key).
Longitude (float): Represents the longitudinal coordinate of the street light’s
physical location.
Latitude (float): Represents the latitudinal coordinate of the street light’s
physical location.Events Entity:
• Events/Control Table:
Id (int): the id of the event (primary key).
Timestamp (timestamp): Records the date and time when an event oc-
curred.
Lightid (int): Relates the event to a specific street light using its unique
identifier.
Dimming (int): Indicates the level of brightness (dimming) at the time of
the event, in percent.
On/off (int): Records whether the street light was turned on or off at the
time of the event, 0 is on and 1 is off.
Flow (float): Potentially represents additional information or events related
to the street light.
• NodeDeath Table:
Id (int): primary key for the node death event.
Timestamp (timestamp): Records the date and time when a node (possibly
a communication or control node) experienced an issue or malfunction.
Lightid (int): Relates the node death event to a specific street light, likely
indicating which street light is affected by the node’s failure.

12
Death reason (int): Provides details on the reason for the node’s failure or
death:
0: lost connection,
1: current is too low,
2: : current is too high.
• GateAlive Table:
Id (int): primary key of row.
Timestamp (timestamp): Records the date and time when the gateway is
still alive, that means if the last time in this table is 10 minutes late to the
current time, the gateway is probably dead for 10 minutes.

1.6.4 User Interface Design


1. Home page

The Home page serves as an introduction to our team through a Facebook post in the
main group of this contest. Any Facebook user with internet access can comment
directly below the post.

2. Login Page

13
When a user (Admin/Manager) wishes to access all the features of the web app,
they must first log in. Otherwise, they will receive a notification like the one shown
below, instead of the feature they intended to use.

To log in, users need to enter their account and password in the respective fields
and click the ’Login’ button, or simply press the Enter key on the keyboard. It’s
important to note that passwords are not stored in the database; rather, they are
securely encrypted.

3. Device page

14
The Device page displays streetlight data geographically, including location, bright-
ness, and the on/off state of each lamp. Users can access the data by clicking or
hovering over the light bulb icon. If the icon is black, it indicates that the streetlight
in that location is turned off.

4. Control page

The Control page allows users to manage all the street lights. At the top of the
page, there are widgets that enable users to control all the street lights collectively:
a slider for dimming, a button for turning them on/off, and four time input widgets
for scheduling based on time.

15
Below, there are identical widgets for each street light, allowing users to control
them individually.

5. Notification page

The notification page displays the status changes of each streetlight in a real-time
data table. Additionally, a red notification will appear if the gateway hasn’t pub-
lished any data to the database for 10 minutes. All the yellow notifications show the
timestamp and the reason for when and why a streetlight is not functioning.

1.7 System security


1.7.1 Node - Gateway Security (AES-128)
Advanced Encryption Standard (AES) uses a symmetric encryption algorithm, and
the key size can be 128/192/256 bits. AES is a block cipher, each block has 128 bits data.

16
We have three main states in the process of transforming plain text into cipher
text, and we employ five distinct functions to achieve this encryption. These functions
collectively manipulate the plain text to generate a secure cipher text.
The number of repeat round depends on size of key:

• 128 bit key – 9 rounds

• 192 bit key – 11 rounds

• 256 bit key – 13 rounds

17
KeyExpansion: in each round, keyExpansion will calculate all the round keys
from the key. So the initial key is used to create many different round keys which will be
used in the corresponding round of the encryption.

SubBytes: In this function, each byte is substituted by another byte. Its performed
using a lookup table also called the S-box

18
ShiftRows: Each row is shifted a particular number of times.

• The first row is not shifted

• The second row is shifted once to the left.

• The third row is shifted twice to the left.

• The fourth row is shifted thrice to the left.

19
MixColumns: This function is basically a matrix multiplication. Each column is
multiplied with a specific matrix and thus the position of each byte in the column is
changed as a result.
Add Round Keys: Now the resultant output of the previous stage is XOR-ed with
the corresponding round key.

1.7.2 MQTT Broker Security (TLS/SSL)


Transport Layer Securities (TLS) are designed to provide security at the trans-
port layer. TLS ensures that no third party may eavesdrop or tamper with any message.
TLS/SSL provides operations for authentication mechanism, asymmetric encryption al-
gorithm.

20
TLS is using a special protocol called ‘Handshake’ to agree on the protocol and
to exchange keys. Basically the certificate is used to verify the server identity, and the
asymmetric encryption is used to exchange a shared secret key for symmetric encryption:

1. Client sends a clear (unencrypted) ‘hello’ message to the server, asking for an en-
crypted session.

2. Server responds with a server certificate which includes the server public key in it.

3. Client verifies the certificate and extracts the public key.

4. Client uses the public key to send a ‘pre-master’ key he has generated to the server.

5. The server uses its private key to extract the ‘pre-master’ key.

6. Both the client and the server use the ‘pre-master’ key to compute a shared secret
key.

7. Client sends a message to the server encrypted by that shared secret key.

8. The server decrypts the received message and checks it.

21
9. If that passes, the server sends back an encrypted message using the shared secret
key to the client to confirm that everything is ok.

10. From this point on, both the client and server are using the shared secret key for
their communication.

1.8 Introduction to Hardware


1.8.1 Power supply 12V - 5A
• Input Voltage: 110V/220V AC (can be switched between 110V and 220V)

• Output Voltage: 12V DC

• Current Rating: 5A

• Maximum Power Output: 60W

22
Figure 1.5 Power supply 12V - 5A

1.8.2 Module Lora


The RF UART LoRa module EBYTE E32-433T20D is a communication device
that uses the SEMTECH SX1278 chip and operates on the LoRa (Long Range) commu-
nication standard. LoRa offers two essential features: energy efficiency and long-range
transmission, making it a popular choice for IoT research and applications.
Here are the technical specifications for the EBYTE E32-433T20D LoRa module:

• Main IC: SX1278 from SEMTECH.

• Operating Voltage: 2.3 - 5.5 VDC

• Communication Voltage: TTL-3.3V

• UART Interface: Data bits 8, Stop bits 1, Parity none, baud rates from 1200 to
115200.

• Frequency Range: 410 - 441MHz

• Output Power: 20dBm (100mW)

23
• Maximum Transmission Range in ideal conditions: 3000 meters

• Data Rate: 0.3 - 19.2 Kbps (default 2.4 Kbps) 512-byte buffer.

• Supports configuration of 65536 addresses.

• Dimensions: 21x36mm.

The module integrates SPI-to-UART communication conversion for the SX1278,


simplifying communication and usage. To configure the module, you’ll need to connect
it to software provided by the manufacturer to set parameters such as addresses, baud
rates, and transmission power. Additionally, you may need to purchase a USB-to-UART
converter to connect it to a computer.
=> Overall, this LoRa module is well-suited for long-range wireless communica-
tion in IoT applications, thanks to its energy efficiency and extensive range.

Figure 1.6 Module LoRa E32 SX1278

Include:

• M0, M1 are used to set the M-S mode

• RX, TX: UART communication

• VCC = 5V, GND = 0V

1. Module pins and dimensions

24
2. Working Mode

3. Mode transmission
There are 2 transmission modes of LoRa E32. In transparent transmission, we send
to all and receive from all that have the same address e channel. But it isn’t a
standard scenario, and we usually want to send to a specified point and receive a
response. So in this system, we use fixed transmission.

25
• Transparent transmission
We set M0 and M1 to LOW for transmission.
• Fixed transmission
For fixed transmission, as for transparent transmission, we set M0 and M1 to
LOW
– Fixed transmission: point to point
To use this type of transmission, we set a parameter on configuration and
set a specified address for every device.

– Fixed transmission: broadcast

26
We can test the broadcast communication with the exact configuration of
the address and channel.

– Fixed transmission: monitoring


We can hear all messages in the specified channel.

1.8.3 Motion sensor module HC - SR602


The SR602 motion sensor is an infrared sensor (PIR - Passive Infrared Sensor)
used to detect the movement of people or objects in a specific area. The SR602 motion
sensor is a useful tool in controlling and automating systems based on motion detection,
and it is commonly used in various applications to enhance convenience and security.
Specifications:

• Detection range: up to 5 meters, recommended 0-3.5 meters.

• Output: high level, H = 3.3V, L = 0V.

• DC power supply: 3.3V-15V.

• Static current: 20uA.

27
Figure 1.7 Motion sensor module HC - SR602

1.8.4 BH1750 intensity measuring sensor module


The BH1750 Digital Light Sensor is used to measure light intensity in lux units.
The sensor features internal ADC and preprocessing, so it directly provides lux values
without the need for any additional processing or calculations through I2C communica-
tion.
Specifications:

• Power supply: 3 5VDC

• Interface voltage: TTL 3.3 5VDC

• Communication standard: I2C

• Measurement range: 1 -> 65535 lux

• Size: 21*16*3.3mm

Some examples of light intensity:

• Nighttime: 0.001 - 0.02 Lux

• Moonlight: 0.02 - 0.3 lux

• Cloudy indoor: 5 - 50 lux

• Cloudy outdoor: 50 - 500 lux

• Sunny indoor: 100 - 1000 lux

• Light required for reading: 50 - 60 lux

28
Figure 1.8 BH1750 intensity measuring sensor module

1.8.5 ACS712 current measurement sensor module


The ACS712 Hall Effect Current Sensor is used to measure AC/DC currents, fea-
turing a compact size and easy connectivity. It provides a linear analog voltage out-
put corresponding to the measured current, making it straightforward to connect and
program with microcontrollers. It is suitable for applications requiring high-precision
current measurements.
Measuring DC Current: When measuring DC current, connect the load in series
between Ip+ and Ip- in the correct direction. When the current flows from Ip+ to Ip-,
Vout will output a voltage level between 2.5 5VDC, corresponding to a current range
from 0 Max. If connected in reverse, Vout will output a voltage between 2.5 0VDC,
corresponding to 0 (-Max).
With a 5VDC power supply to the module and no current (no load connected in
series), Vout will be at 2.5VDC. When the current (load current) reaches Max, Vout will
be at 5VDC. Vout will vary linearly with Ip in the range of 2.5 5VDC, corresponding to
a current range of 0 Max. You can use a DC voltage meter (VOM) to measure Vout for
verification.
Measuring AC Current: When measuring AC current, polarity doesn’t matter since
AC current doesn’t have a direction. With a 5VDC power supply to the module and no
current (no load connected in series with the terminal block), Vout will be at 2.5VDC.
When there is alternating current Ip (AC current), since AC current varies continuously
with a sine function, the voltage Vout will have a linear magnitude from 0 5VDC, cor-
responding to (-Max) Max (AC current). To verify, use an AC voltage meter to measure

29
Vout.
Specifications:

• IC: ACS712 5A

• Power supply: 5VDC

• Output sensitivity: 190mV/A

• Low-noise analog signal path

• Output response time to input: 5µs

• Conductor resistance: 1.2mΩ

Figure 1.9 ACS712 current measurement sensor module

1.8.6 LED
• COB (Chip-on-Board) LED Light

• Power: 2W

• Voltage: 12V

• Color: White

• Number of LEDs: 24 chips

• LED Chip Type: COB

30
Figure 1.10 LED

1.8.7 Kit EFR32xG24 EK2703


The EFR32XG24 Kit is a development kit based on Silicon Labs’ versatile EFR32XG24
microcontroller, designed specifically for IoT (Internet of Things) and wireless applica-
tions. The EFR32XG24 focuses on rapid prototyping and concept creation for IoT ap-
plications using 2.4 GHz wireless protocols, including Bluetooth LE, Bluetooth Mesh,
Zigbee, Thread, and Matter.
Key features of the board include a USB interface, an on-board SEGGER J-Link
debugger, packet trace interface, push buttons, and support for additional hardware via
mikroBus socket and Qwiic® connector. Hardware expansion is facilitated by additional
hardware support utilities that allow developers to create and prototype applications us-
ing a wide variety of available boards from mikroE, Sparkfun, AdaFruit, and Seeed
Studios.
Specifications:

• High-performance 2.4 GHz radio

31
Figure 1.11 Kit EFR32xG24 EK2703

• 78 MHz 32-bit ARM® Cortex®-M33

• 1536 kB flash and 256 kB RAM

• Protocol support:

– Bluetooth Low Energy


– Bluetooth Mesh
– Zigbee
– Thread
– Matter
– Proprietary

• Product Features:

– Two LEDs and two push buttons


– Reset button
– Micro-B USB connector for power and debugging
– On-board SEGGER J-Link debugger
– Virtual COM port

32
– Packet Trace Interface (PTI)
– Third-party utility support for connection
– mikroBUS™ socket
– Qwiic® connector

1.8.8 Raspberry pi 4B
Advantages of the Raspberry Pi 3 compared to previous versions:

• The new BCM2837 CPU from Broadcom with a clock speed of 1.2GHz, featuring
a 4-core ARM Cortex-A53 64-bit architecture. The Raspberry Pi 3’s CPU deliv-
ers over 50-60% better performance compared to the previous Raspberry Pi 2. It’s
worth noting that the CPU has transitioned to a 64-bit architecture, similar to Ap-
ple’s iPhone CPUs.

• Integrated 802.11n Wi-Fi and Bluetooth 4.1.

• Backward compatibility with hardware and software designs from previous ver-
sions, such as the Raspberry Pi 1 and 2.

Detailed Specifications:

• Manufactured at the Sony factory in the UK (Made in UK / PRC), officially by RS


Components.

• 1.2GHz 64-bit quad-core ARM Cortex-A53 CPU (BCM2837)

• 1GB RAM (LPDDR2 SDRAM)

• On-board Wireless LAN - 2.4 GHz 802.11 b/g/n (BCM43438)

• On-board Bluetooth 4.1 + HS Low-energy (BLE) (BCM43438)

• 4 x USB 2.0 ports

• 10/100 Ethernet

• 40 GPIO pins

• Full-size HDMI 1.3a port

• Combined 3.5mm analog audio and composite video jack

• Camera interface (CSI)

• Display interface (DSI)

33
• microSD slot

• VideoCore IV multimedia/3D graphics core @ 400MHz/300MHz

Figure 1.12 Raspberry pi 4B

1.9 Chapter conclusion


This chapter establishes the foundation for the topic, starting from the overall struc-
ture of a basic IoT system, data transmission standards, connectivity, and delving into
the details of its components, from hardware to software. It provides readers with the
broadest overview of what is addressed in the research project.

34
CHAPTER 2. SYSTEM DESIGN

2.1 System overview


The model that the team is implementing is also an experimental model, so the
results of the design and construction process must meet the following requirements:

• Monitor values and statuses of lights, brightness, current continuously.

• Control lights via web

• Achieve stability and high accuracy in the model.

2.1.1 Control each light via iot


Street lighting IoT system components down to each lamp

• System Server

• Control and Monitoring Cabinet: Street lights can be interconnected and remotely
controlled and monitored through the control cabinet system.

• Control and Monitoring Application

• Wirelessly connected LED lighting devices with built-in lighting control.

IoT system control diagram for each light

• IoT system control diagram for each light

• The central control room and control applications will connect to the Cloud system
via the internet to send and receive signals for remote monitoring.

• The Gateway cabinets will connect to the Cloud system to transmit signals to the
lights in the system through a wireless network.

• Operating the system primarily through a wireless network offers several advan-
tages and conveniences in terms of installation and operation compared to tradi-
tional wired systems.

IoT solution features to control each light:

• The system controls and monitors the lighting system, each light through wireless
communication.

35
• It manages the light statuses, allows for direct control, and sets up contextual sched-
ules.

• The device control software is user-friendly, easy to use, and can run on multiple
platforms (cloud computing technology applications).

• The management software is presented in a diagram format, making it more visually


intuitive and user-friendly.

• It provides statistics on the rate of faulty or malfunctioning lights and the system’s
operating time. Statistical reports from the software help you maintain good control
of system operations and make adjustments as needed based on real-time condi-
tions.

• It can be expanded to integrate with other smart city platforms such as smart trans-
portation.

Solution advantages:

• Cost savings on electricity usage.

• Cost savings on operational expenses (eliminating the need for manual operation).

• Increased lifespan of light bulbs due to reduced power consumption and lighting
duration.

• Initial cost savings on electrical cabinets and power cables.

• Automatic control and monitoring of the system from a central hub.

• Immediate alerts for malfunctioning lights and the ability to isolate and repair indi-
vidual faulty lights

Application of IoT system for each light:

• Streets

• Highways

• National roads

• City lighting

• Industrial zones

• Factories, laboratories

36
• Parks

• Monumental areas, memorials

2.1.2 Dimming LED


Dimming is the adjustment of light intensity - reducing the power output from LED
street lights. The lights shine at 100% power during peak hours and automatically dim
during off-peak hours with low traffic flow to save energy.
Key features of the solution:

• Integrated dimming capability directly into the lights, no additional equipment


needed

• Automatic dimming based on preset time settings

• Compatible with existing electrical systems

• Responsive to real-time usage needs in the area

Advantages of the solution:

• Dimming the lights saves electricity, reducing electricity bills and the need to re-
place bulbs

• Adjusting the brightness of the lights extends the lifespan of LED bulbs

• Easy to install and operate

2.2 System block diagram


Functions of each block:

• Power Supply Block: This is a crucial block that provides electricity to the entire
system to operate. Therefore, it is important to select the right power supply block
to provide enough current and voltage for the blocks to operate well and stably.

• Central Control Block: The central control block uses the high-performance EK2703
to process and control the system:

– Reads and processes data from sensors.


– Controls peripheral devices.
– Transmits data to the website.

37
Figure 2.1 System block diagram

• Sensor Block: This includes motion sensors, light intensity sensors, and highly
accurate current sensors. These sensors are used to collect data on current and
motion, as well as the light intensity around the light. The data is then sent as
a signal to the central control block, compared with preset values, and then the
central control block processes it to match the preset values.

• Peripheral Devices: LED lights that adjust their brightness based on motion de-
tection and ambient light are included here. Any errors detected are immediately
reported for prompt repairs.

• Interactive Web Interface: This interacts with the central control block, displaying
the status of peripheral devices, values read from sensors, and device operations.

• Operating Principle of the Block Diagram:

– The power supply block provides power to the central control block, sensors,
and peripheral devices.
– The sensor block retrieves data regarding motion, current of the lights, and am-
bient light intensity around the lights and sends it to the central control block,
which is then displayed through the website. Users can access the website via a
phone or computer to monitor and control the peripheral devices (LEDs). Each
interaction on the web block sends a corresponding signal to the central control
block. As a result, the central control block can understand and execute com-
mands in accordance with these interactions, ensuring that the system operates

38
correctly based on the actions on the website

2.3 Chapter conclusion


In this chapter, we begin to delve into the details of the system’s formation, in-
troduce the functions of the final product, and then, based on the desired functions, we
construct functional blocks. Subsequently, we select suitable hardware for each block,
elucidating the operating principles of the entire system, encompassing the intercon-
nected functional blocks.

39
CHAPTER 3. SYSTEM CONSTRUCTION5G

3.1 Install software and programming on EFR32xG24


Step 1: To program on the EFR32xG24 Explorer Kit, first, we need to install
the Simplicity Studio 5.
Step 2: After that, plug the USB Type-C cable into the board through the J-Link
port. Connect additional peripheral pins (if any) as well.
Step 3: Load the code and run it (or debug it).

Figure 3.1 Simplicity Studio 5

3.2 Install software and programming on Raspberry pi


With this program, i using CMake to compile our project, Mosquitto as MQTT
Broker

3.2.1 Install CMake


Step 1: Connect your raspberry Pi to the internet
Step 2: install CMake from the Raspberry Pi repository using the following
command: sudo apt install cmake -y

40
3.2.2 Install Mosquitto
Step 1: Connect your raspberry Pi to the internet
Step 2: To install the Mosquitto Broker enter these next commands:
sudo apt install -y mosquitto mosquitto-clients
Step 3: To make Mosquitto auto start when the Raspberry Pi boots, you need
to run the following command (this means that the Mosquitto broker will auto-
matically start when the Raspberry Pi starts):
sudo systemctl enable mosquitto.service
Step 4: Modify the configuration file in /etc/mosquitto/mosquitto.conf to set-
ting the desire configuration
Step 5: Restart Mosquitto for the changes to take effect.
sudo systemctl restart mosquitto

3.3 Proceed with programming

Figure 3.2 System’s block diagram

3.3.1 Algorithmic flow chart of the system


1. End Node
Each node has a specific address, that is our End node ID
4 Main function of End Node is: Reading sensor, Control LED, Transmit data
to Gateway and Receive command from Gateway

41
In the init function, we initialize our MCU, all peripherals needed and all de-
vices that MCU interact with. Next, it requests the Synctime from Gateway, if
the request fails, our End Node program will continue requesting until Gateway
responds to the Synctime request.
In the task Sensor, we gonna read the raw value of 3 sensor, and process that
raw value to usable value

42
The most important function is LED−Control. We have 2 mode to control LED:
Control by itself (Follow the time table and sensor) or Control by Server

43
As control by itself, our End Node split 1 day to 4 parts as 4 timemark. Corre-
sponding to it is 4 LED− de f ault − state with each time period.

44
We can set 4 timemark using our website

• As controlled by Server, the Node follow command is received from the gate-
way for an amount of time. To demo, we let the Server control time by 10s.
• The LED will instantly turn On with 100% when it’s in the nighttime, no matter
what happens
• With this control method, we can save 50% energy every day, and still guarantee
traffic safety.

End node and Server communicate with each other through Gateway. Using
LoRa with AES-128, End node can reach the Gateway

• Each node has to send the data each 5 minutes, or LED−Control has been
changed. So that, the data always be realtime
• When the LED is broken, it makes the current outside the safezone, so it will
send a warning to Gateway.
• “Parse the data” function analyzes the received data, it can be a Control led
state command, or Set the time mark command.

45
2. Gateway

The gateway serves as the intermediary for message transfer between the node
and the Server. It analyzes incoming messages, coordinates, and routes them to
their intended destinations
The gateway employs two communication protocols, LoRa and MQTT, to cor-
respondingly communicate with the Node and the Server. Both of these mentioned
protocols utilize security measures. For MQTT, it utilizes openSSL to encrypt mes-
sages at the Transport layer, preventing eavesdropping
Data frame between Node and Gateway (LoRa): To easily develop, maintain,
we create our own data frame

46
• We don’t encrypt first 3 send byte because it contains 3 information of Desti-
nation LoRa.
• Sync1 and Sync2 to define the start of frame
• KEY - LENGTH - VALUE: Combination to produce various message types
• CRC:"Filtering for received messages or error messages

Figure 3.3 Example data frame between Node and Gateway

Data frame between Gateway and Database/Web: Similar to LoRa, we create


our own data frame, but if above is using Byte frame, with MQTT protocol, we
decide to using String frame for convenience transform.

Figure 3.4 Data frame between Gateway and Database/Web

3.3.2 Web programming


Our web page is built using Python in the Streamlit framework, with some HTML
embedded in certain components and widgets.

47
The web server is hosted on the Streamlit Cloud server. It connects to the database using
the key and URL provided by the Supabase API and to the Gateway using the paho.mqtt
library, utilizing the address, port, and certificate provided by the MQTT Broker.
Whenever the database receives a datarow from the gateway, the web server dis-
plays it for the user. Users can control street lights through the web interface by sending
messages to the corresponding topic.

3.4 Prototype
3.5 Product evaluation
With the initial goal of the project being the creation of a automatic street light-
ing control system via IoT, during the research and experimentation process, despite
encountering numerous challenges and issues, the team gained valuable experience and
gradually improved the product. Various algorithmic methods and hardware configura-
tions were utilized to create the most refined product.
The system operates relatively stable. Sensors read stable values with relatively
high accuracy.
The system operates efficiently, saving labor and achieving high precision, making
it highly suitable for smart urban areas.
The flexibility of the system is relatively high, making it easy to customize ac-
cording to the specific requirements of different real-world models. The hardware of
the system can be expanded as needed by users without the need for a complete system
redesign.
As of now, we have essentially completed this report. However, due to our limited
knowledge and time constraints in completing the project, we acknowledge that there

48
Figure 3.5 Prototype

may be some shortcomings. We sincerely hope to receive guidance from the evaluators
to further enhance our project.
In terms of results, the testing process yielded positive outcomes and met the re-
quirements set by the team. Although there are still some limitations, the team has
identified the causes and solutions.

49
The device was tested in specific scenarios regarding light and motion. The cir-
cuit’s accuracy is high. The circuit has a response time of 2-3 seconds for receiving
commands from the Web Server.

50
CONCLUSION

Comments and reviews


Advantages of the system

• Successfully applied IoT to create a compact product, making it easy to set up a


automatic street lighting model.

• Provided several energy-saving solutions compared to the old street lighting sys-
tems.

• Sensor data is continuously updated and objectively displayed on the WebServer


interface, convenient for users to observe, evaluate, and take timely action.

• The system can be remotely controlled, depending on the user’s needs.

Disadvantages of the system

• The system has not yet achieved the highest level of stability.

• Sensors still have some margin of error, making the system not entirely precise.

Development direction of the topic

• Increasing the number of sensors, improving sensor quality, expanding the system,
and turning it into a multi-purpose automatic street lighting model.

• Integration with other automatic systems to create a larger system.

• Upgrading security features.

Conclusion
While not a groundbreaking or extensive topic, our project reflects the application
of the knowledge we have acquired in a scientific manner, a diligent work ethic, a thirst
for learning, and the exploration of new concepts. We would also like to acknowledge the
wholehearted support and guidance provided by Mentor Nguyen Tuan Anh throughout
this journey.
Our initial goal for this project was to create a automatic street lighting system
via the Internet of Things (IoT). Despite facing numerous challenges and issues during
our research and experimentation, our team gained valuable experience and gradually
improved the product.

51
Due to time constraints, our project does have some limitations. Given the op-
portunity, we could further develop the design to include additional features, enhance
efficiency, and optimize performance.
The designed circuit operates steadily, continuously updating the data it reads to
the WebServer. The WebServer interface is user-friendly and easily accessible. Various
algorithmic methods and hardware configurations have been employed to create the most
refined product possible.
After thorough research and project implementation, we can proudly state that
our "AUTOMATIC STREET LIGHTING SYSTEM" project has reached a fundamental
level of completion.

• The model functions effectively.

• It can be controlled seamlessly through the WebServer.

• The user-friendly web interface displays essential information such as sensor data
and device statuses, allowing for real-time adjustments without the need to interact
with the hardware.

• A relatively complete system model has been successfully installed.

• Database management on the web platform is straightforward

Lastly, we would like to express our sincere gratitude to Mentor Nguyen Tuan Anh
for his invaluable assistance in completing this report. REFERENCES

52
REFERENCES

Advanced Encryption Standard (AES)


Introduction to Security and TLS (Transport Layer Security)
OpenSSL
S3WAN: Hệ thống đèn đường thông minh tiết kiệm năng lượng

53

You might also like