Online Machine Learning for Embedded Systems
(ESP32)

Mamadou Sow, Muhammad Sanaullah Kayani

► To cite this version:

Mamadou Sow, Muhammad Sanaullah Kayani. Online Machine Learning for Embedded Systems (ESP32). ComPAS 2024 - Conférence francophone en informatique autour des thématiques du parallélisme, de l'architecture et des systèmes, IETR (Institut d'Electronique et des Technologies du numéRique) et le LS2N (Laboratoire des Sciences du Numérique de Nantes) - Nantes Université, Jul 2024, Nantes, France. pp.1-20. hal-04680048v2

HAL Id: hal-04680048

https://hal.science/hal-04680048v2

Submitted on 29 Aug 2024

**HAL** is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Online Machine Learning for Embedded Systems (ESP32)
## Introduction with the Slides

Christophe Cerin*, Mamadou SOW*, Muhammad Sanaullah Kayani

*Sorbonne Paris Nord University, LIPN CNRS UMR7030, 99 avenue J.B. Clément 93430 Villetaneuse France
Grenoble Alpes University, 621 avenue Centrale, 38400 Saint-Martin-d'Hères France
cerin@lipn.univ-paris13.fr, mamadou.sow@lipn.univ-paris13.fr,
muhammad-sanaullah.kayani@etu.univ-grenoble-alpes.fr

## Abstract

Due to the explosive growth of data traffic in the Internet of Things systems (IoT), machine learning and data-driven approaches are expected to become a key factor in fueling the development of wireless networks beyond 5G (B5G). Standard machine learning approaches require centralizing training data on a single data center such as a cloud. However, due to privacy constraints and limited communication resources for data transmission, it is impractical for all wireless devices to transmit all their collected data to a data center that can use the collected data to implement centralized machine learning algorithms for data analysis and inference. This has led to the emergence of a fast-growing research area, called Edge Learning, which can deeply integrate two major areas : wireless communication and machine learning. Our work revolves around implementing online machine learning algorithms at the edge, specifically the k-means clustering algorithm as a use case on ESP32-WROOM microcontroller.

ESP32 can work with sensors for things like measuring temperature, but it can also handle more complicated jobs like executing "complex" machine learning (ML) algorithms. We're particularly interested in its industry-leading performance in electronic integration, power consumption, and connectivity. Using its built-in WIFI that uses very little power, the ESP32 receives data from a dataset, corresponding to a building located at Grenoble, and processes the k-means algorithms under study. The data we process on the board, comprising CO2 volume and temperature readings, is obtained from an MQTT server, which implements the publication-subscription paradigm. This paradigm allows for asynchronous and non-blocking message communication, enhancing efficiency.

We aim to study models capable of continual learning from new data, without revisiting past data. One of the K-Means algorithms we study iteratively groups unlabeled data into K clusters based on cluster centers (centroids). The data assigned to each cluster is determined such that their average distance from their respective centroid is minimized. In this case, we develop with the Arduino toolchain. In another case, to efficiently put in place our software code, we utilize the Micropython-ulab environment on ESP32, providing a robust platform for coding ML algorithms. We are also studying River, a dedicated Python online machine learning tool, but not capable of running on ESP32-like boards. Finally, we provide lessons learned and insights into our use case. The presentation aims to discuss the difficulties in these tasks, both from a technical point of view and from an algorithmic one.

**Keywords:** Online machine learning algorithms, ESP32 and microcontrollers architectures, Micropython and Arduino ecosystems, Edge computing.
# 1. Introduction

Our internship aims to develop a model capable of continuous learning from sequential data streams on embedded systems, ensuring adaptation to new information without revisiting past data. We focus on a model that can adapt to concept drift and suit real-world production contexts, especially event-based ones, while seamlessly integrating into the embedded systems programming ecosystem. Online machine learning presents challenges such as catastrophic forgetting, where previous knowledge is abruptly lost upon learning new information. To address these challenges, we explore ecosystems such as micropython-ulab, Scikit-learn, and River, offering out-of-core implementations and user-friendly libraries for machine learning on streaming data. River, a combination of Creme and scikit-multiflow, provides a wide range of algorithms for continual learning and streaming data processing, encompassing linear models, decision trees, anomaly detection, clustering, and more.

In smart buildings, prioritizing residents' data privacy and security may prevent data transmission to external cloud servers (such as Amazon or Alibaba Cloud). This shift requires redesigning building data management systems, processes, and controllers. As a result, it raises further research into optimizing the use of computing, networking, and storage resources owned by building occupants and visitors, along with evaluating the performance of embedded devices within the building. These aspects are vital for efficiently utilizing on-site data for learning purposes. Inside a building, a CO2 sensor and temperature sensor generate data, motivating our interest in clustering the data to identify anomalies and applying regression techniques for analysis. By tackling these challenges, our internship aims to enhance the learning capabilities of embedded systems for practical implementation in real-world scenarios, while optimizing power consumption utilizing low-power devices such as the ESP32.

## 1.1. Methodology

An MQTT server gathers real-time data including CO2 volume and temperate measurement from the sensor and sends it to the ESP32-embedded device for further processing. We have set up MicroPython, uLab, and other required libraries on the ESP32 to implement online machine-learning algorithms. We are collecting power consumption data into our matrices for further optimization, and then clustering the data using online K-means algorithms. Online machine learning sequentially updates the best predictor using incoming data. To validate the result, we compare the performance of River, a user-friendly ML library for streaming data, with our developed clustering algorithm, evaluating quality-oriented metrics like Jaccard and Jini indexes, and metrics for concept drift estimation.

# 2. Related work

The literature on data stream clustering algorithms emphasizes their importance in partitioning observations into clusters to reduce data complexity. These algorithms are designed for situations where data flows continuously, presenting difficulties related to memory and time limitations, particularly in IoT and edge computing environments. We study one existing algorithm (2). It outlines two-phase schemes for data stream clustering, with online components processing data points and offline components generating clusters. Methodological considerations include models for data streams and sliding windows to handle potentially infinite and non-stationary data.

Ghesmoune, M. and Lebbah (3) provide valuable insights into modern data stream clustering methods, categorizing them by their clustering strategies. While they explore hierarchical stream methods like neural gas, we focus on partitioning-based clustering, notably the k-means
algorithm, which relies on distance metrics to form clusters. Our approach emphasizes simplic-
ity, sidestepping the requirement for intricate data structures and optimizations. Moreover, we
capitalize on the efficiency of the MQTT server and its data publication rate to enhance batch
processing in our work.

3. Problem statement and algorithmic solution

3.1. Problem statement

Sensors continuously transmit data to a server using the MQTT protocol as shown in Figure 1. The “Processor for clustering” subscribes to these messages from the server and conducts the clustering process. The publisher (MQTT server) and the clustering processor are low-cost machines. It’s feasible for a single machine e.g. ESP32 to handle both tasks, allowing data collection and clustering services to run on the same device. This co-location reduces communication overhead by maintaining data production and processing nearby. We’ve chosen to illustrate only one processing machine for clarity, but multiple sources can supply data to this machine. Therefore, we haven’t addressed scalability and architecture dimensioning. Our proposed architecture is additionally suitable for using phones or tablets as processing machines, given that the MQTT protocol is already supported on these devices.

<figure><img src="image_2.png" /><figcaption>Figure 1: Sensors Data Collection and Processing</figcaption></figure>

3.2. Proposed Solution

The Stream window clustering algorithm (1) efficiently processes streaming data by partition-
ing it into fixed-size windows and adapting to its dynamic nature. Initially, it employs k-means
or k-means++ clustering to identify patterns within each window. Subsequently, data points are
sorted based on coordinates for streamlined processing. Regularly removing points maintains
data diversity, with new ones from the stream replacing them. Continuous centroid updates
mirror the changing data distribution. Utilizing proven algorithms and possibly implement-
ing multithreading guarantees scalability and efficiency, rendering it well-suited for real-time
processing of large-scale data streams.

Many existing streaming clustering algorithms cannot serve as baseline algorithms because they are not designed to meet the requirements of low-cost machines or memory-constrained devices. Therefore, comparing them would not be fair. In summary, the key properties of our generic framework are as follows:

* The algorithm is based on offline clustering, allowing for traditional methods like k-means to be utilized.

* When repeating the clustering process, only a small fraction of data (p << W) needs to be inserted, enabling control of memory space.

* Each sorting step can potentially be performed in parallel, if hardware permits, aiding in preserving diversity in the data.

* The concept of eliminating a fraction of data regularly corresponds to maintaining diversity in the input.

# 4. Experiments

This section overviews the testing devices employed and outlines the experimental design. Our experimentation involves applying online k-means clustering to evolving CO2 and temperature data collected from various zones within the IMAG building, with a focus on detecting concept drift for subsequent analysis.

## 4.1. Test Equipment and Tools

We utilized the low-cost machine to achieve our objective, our experimental setup includes the following hardware and software components:

### 4.1.1. ESP-WROOM-32D

We programmed the Micropython-ulab collaboratory on ESP32 to achieve our results. It's a powerful and versatile Wi-Fi and Bluetooth module developed by Espressif Systems. It features a dual-core Tensilica LX6 microprocessor with a clock speed of up to 240 MHz, offered robust processing capabilities for a wide range of applications while minimizing energy consumption.

### 4.1.2. MQTT Server

An MQTT (Message Queuing Telemetry Transport) server, also known as an MQTT broker, is a crucial component in the MQTT communication protocol, which is designed for lightweight, efficient message exchange in IoT and embedded systems. It's widely used in IoT applications, such as smart buildings, for efficient real-time data transmission between sensors and processing units. Popular implementations include Mosquitto, HiveMQ, and EMQX.
### 4.1.3. Setting of MQTT Client

To configure the MQTT client to connect to an MQTT broker, Broker Address (Hostname or IP), Port Number, Username, and Password (If authentication is enabled) are required to establish a connection between the devices. After configuring the client, you can publish or subscribe the messages to MQTT topics using the `mosquitto_pub` or `mosquitto_sub` commands given below.

* `mosquitto_pub -h <10.188.186.20> -p <1883> -u <root> -t <test/topic> -m <message>`

* `mosquitto_sub -h <10.188.186.20> -p <1883> -u <root> -t <test/topic>`

<figure><img src="image_3.png" /><figcaption>Figure 2: Setting MQTT client to subscribe data</figcaption></figure>

### 4.1.4. Setup Thonny IDE

This is the IDE we use to perform multiple experiments for our project. Thonny is an Integrated Development Environment (IDE) specifically designed to make Python programming more accessible and user-friendly. It supports virtual environment management, allowing users to isolate projects and dependencies for better organization and reproducibility. So, it's easy for us to install a library on ESP32 as it provides built-in internal support to install libraries and plugins. Furthermore, establishing a connection of micropython-ulab over the ESP32 board is very convenient compared to a manual shell tool. You can upload your code on ESP32 in simple clicks and execute your code over there without flashing ESP32. These all features caught our attention to choose Thonny IDE for our research project.

<figure><img src="image_4.png" /><figcaption>Figure 3: Micropython-ulab on ESP32</figcaption></figure>
4.2. Experiment on ESP32 to apply an Online K-Means using Micropython

Online K-means clustering is a variation of the traditional K-means algorithm, designed for
dynamic and incremental data. In this method, we define a target number k, which refers to the
number of centroids needed in the dataset. A centroid represents the central point of a cluster.
Each data point is incrementally assigned to a cluster, minimizing the sum of squares within
the cluster. Unlike the traditional approach, where the algorithm first identifies k centroids
and then allocates each data point to the nearest cluster, online K-means updates the centroids
iteratively as new data points are processed. This allows the centroids to adjust dynamically to
new data. The “means” in K-means refers to the average of the data points within each cluster,
effectively finding the center of gravity for each cluster.

In our approach to applying online K-means clustering, we process data received from an online stream in discrete windows. Each window is handled sequentially, allowing for continuous and incremental clustering. As new data arrives in each window, we perform the clustering process on that window, updating the centroids iteratively to reflect the latest data points. This dynamic updating ensures that the clustering model remains responsive to changes in the data distribution over time.

In addition to clustering, we implement a mechanism to detect drift in the data stream. Detecting drift is crucial for further analysis, as it helps identify significant changes in the underlying data patterns. By monitoring for drift, we can adjust our clustering model to maintain accuracy and relevance in changing data environments.

4.2.1. *Data Exploration*

We utilized the Seaborn and Matplotlib modules to visualize data distributions from multiple
sources, such as CO2 levels, temperature, and clusters. Seaborn offers a handy feature called
Distplot, which combines a histogram with a line plot to show how the data is spread out. This
type of plot, also called a distribution diagram, helps to see the range and variability in the
data. Seaborn's Distplot is especially handy for getting an overall view of how continuous data
variables are distributed.

<figure><img src="image_5.png" /><figcaption>Figure 4: Distribution of Data</figcaption></figure>
### 4.2.2. Applying K-Means Clustering with Micropython-ulab and K=5

K is the number of clusters to form as well as the number of centroids to generate. The initialization method with k-means allows to selection of the initial cluster centroids using sampling based on an empirical probability distribution of the point's contribution to the overall inertia.

<figure><img src="image_6.png" /><figcaption>Figure 5: Applying KMeans Clustering with Micropython-ulab and K=5</figcaption></figure>

The scatter plots in the form of a cloud of points thus show how the Temperature variable is affected by the CO2 concentration variable. We cannot deduce either a linear or non-linear correlation. While we observe a linear evolution of the 5 centroids

From the result of online k means with distance method we can analyze that the data stream is coming continuously and we don't exactly know the exact number of clusters at initial stage. The purpose of this testing is to estimate the processing and power capacity of ESP32 using micropython-ulab. Our subsequent experiment will explore DBSTREAM Clustering, which operates on density rather than distance, eliminating the need to specify the value of k initially.

### 4.2.3. Measure the Capacity of ESP32

We experimented to evaluate the ESP32's performance in processing varying data sizes across different windows using MicroPython. The results are presented in Figure 6.

Based on the table in fig 6, we can conclude that the ESP32 microcontroller can efficiently handle a stream of 5120 messages with optimized batch processing of 128 messages. In contrast, the Arduino can handle a stream of 1024 messages with the same optimized batch processing of 128 messages.

## 5. Conclusion

In this research project, we explored the application of online machine-learning algorithms on the ESP32-WROOM microcontroller for real-time data processing. We propose a generic
<table><caption>Figure 6: Message Flow, Processing Slice, and Number of Possible Iterations</caption><thead><tr><th rowspan="2">W Slice</th><th colspan="2">256 messages</th><th colspan="2">512 messages</th><th colspan="2">1024 messages</th><th colspan="2">5120 messages</th></tr><tr><th>It. Max</th><th>It. Got</th><th>It. Max</th><th>It. Got</th><th>It. Max</th><th>It. Got</th><th>It. Max</th><th>It. Got</th></tr></thead><tbody><tr><td>512</td><td>x</td><td>x</td><td>1</td><td>1</td><td>2</td><td>1</td><td>10</td><td>2</td></tr><tr><td>256</td><td>1</td><td>1</td><td>2</td><td>2</td><td>4</td><td>3</td><td>20</td><td>4</td></tr><tr><td>128</td><td>2</td><td>2</td><td>4</td><td>4</td><td>8</td><td>8</td><td>40</td><td>40</td></tr><tr><td>64</td><td>4</td><td>4</td><td>8</td><td>8</td><td>16</td><td>16</td><td>80</td><td>80</td></tr><tr><td>32</td><td>8</td><td>8</td><td>16</td><td>16</td><td>32</td><td>32</td><td>160</td><td>160</td></tr></tbody></table>

framework for data stream clustering on low-cost machines, focusing on the Internet of Things (IoT) and Edge computing contexts. Our primary focus was on implementing and evaluating the k-means clustering algorithm using CO2 and temperature data collected from various zones within a building. We successfully demonstrated that the ESP32, a low-cost and low-power device, can handle real-time data streams and perform online clustering effectively.

Our experiments revealed several key insights. The ESP32 demonstrated an ability to efficiently manage the online k-means clustering algorithm, underscoring its potential for real-world applications in resource-constrained environments. We observed that the accuracy of clustering results improved with larger window sizes; however, reinitializing clusters at each iteration often led to misclassification. Optimal results were consistently achieved with a well-initialized centroid, which reduced the necessity for multiple iterations. While the k-means algorithm performed adequately under certain conditions, it encountered difficulties with dynamic data streams and required predetermined cluster numbers. In contrast, density-based algorithms like DBSCAN and DBSTREAM emerged as more promising alternatives, offering greater accuracy and flexibility without predefined clusters.

Through our study, we highlighted the importance of addressing concept drift and anomalies in streaming data to maintain model accuracy and reliability. Our findings underscore the potential for implementing sophisticated machine learning algorithms on embedded devices, opening doors to more advanced and autonomous IoT systems.

Future work aims to adapt all River algorithms to the microcontroller context. The ultimate goal is to develop a comprehensive online machine-learning library specifically designed for microcontrollers. Additionally, we plan to create our online machine-learning algorithms depending on the specific scenarios encountered and studied in the LIGLAB.

Applying our developed system in various real-world scenarios, conducting detailed case studies, and exploring its integration with diverse machine learning frameworks and tools will help us assess its practicality and effectiveness across different applications. This comprehensive approach to future research will significantly contribute to edge computing and online machine learning, enabling more intelligent and autonomous IoT systems to operate efficiently even in resource-constrained environments.

## References

[1] Carnein (M.) et Trautmann (H.). - Optimizing data stream representation: An extensive survey on stream clustering algorithms. *Business & Information Systems Engineering (BISE)*, vol. 61, 2019, pp. 277-297.

[2] Cérin (C.), Kimura (K.) et Sow (M.). - Data stream clustering for low-cost machines. *Journal of Parallel and Distributed Computing*, 2023.

[3] Ghesmoune (M.), Lebbah (M.) et Azzag (H.). - State-of-the-art on clustering data streams. *Big Data Analytics*, vol. 1, 2016, p. 13.
Online Machine Learning for Embedded
System (ESP32)*

Christophe Cérin, Mamadou Sow, [Muhammad Kayani](mailto:muhammad.kayani@gmail.com)

LIPN, LIG - USPN, UGA - Paris, Grenoble

<figure><img src="image_7.png" /></figure>

<figure><img src="image_8.png" /></figure>

Table Of Contents

➤ Introduction

○ First elements of context

○ Motivation

➤ Problem Statement and Proposed Solution

○ Problem Definition

o Online K-Means Clustering

○ Analysis on K-Means

➤ Github Contributions

➤ Conclusion & Future Work
# Part. 1 Introduction

## Motivation

* Model that can learn from new data without revisiting past data ;

* Model robust to concept drift ;

* Inside building, CO2 and temperature sensor generate data, motivating our interest in clustering ;

* Applications: Clustering data to identify anomalies and applying regression techniques for analysis.

<figure><img src="image_9.png" /></figure>

<figure><img src="image_10.png" /></figure>

**Challenges:**
* Learn (the data produced locally)
* Compute locally

NO AI

<figure><img src="image_11.png" /></figure>

Building Automation and
Control System
> Online Machine Learning

* Batch Learning

* Continual Learning

> Online ML Challenge : Catastrophic Forgetting

> Address Online Machine Learning with
Micropython-ulab, Sklearn and River;

> River: a combination of Creme and scikit-multiflow.

> Concept Drift

Part. 2 Problem definition & Solutions
# Problem: Clustering is a Target (but not the only one)

**Option 1:** In smart buildings, data first sent to the cloud server and then process;

**Issues:**
* Data privacy and security
* Performance
* High power consumption

**Option 2:** A single machine can give "performance" and low power consumption.

<figure><img src="image_12.png" /></figure>

# Problem: Online Clustering on low-cost device ESP32

ESP32 microcontroller with WROOM-32D chip: processor frequency up to 240 MHz, Wi-Fi 2.4 GHz, Bluetooth LE, 38 GPIO pins, 520 KB RAM, 4 MB flash memory, Additional Options: USB to UART bridge, buttons, LEDs

* CPU ESP-WROOM-32 (Tensilica Xtensa LX6)

* Voltage: 3.3V

* Flash: 4000 kB

* RAM: 520 kB

* EEPROM: 448 kB

* Clock speed: 240MHz

* WiFi: Yes

* Bluetooth: Yes

* SD: No

<figure><img src="image_13.png" /></figure>
* Partitions streaming data into fixed-size windows;

* Regularly removes and replaces points to maintain data diversity;

* Detect the Drifts in windows;

* Apply the sequential k-means clustering and update the centroids;

* Save the corresponding data into file;

* Based on: Cérin, Christophe, Kimura, Keiji, Sow, Mamadou, Data stream clustering for low-cost machines, Journal Parallel Distributed Comput, https://doi.org/10.1016/j.jpdc.2022.04.009

## Online Clustering (Implementation Detail)

* Micropython;

* Ulab;

* Installation of micropython-ulab on ESP32.
  * Micropython and ulab should be on same level.

* IDE (Integrated Development Environment) : Thonny;

* Use the MQTT protocol combined with the K-means algorithm on a data flow.

<figure><img src="image_14.png" /></figure>

<figure><img src="image_15.png" /></figure>

<figure><img src="image_16.png" /></figure>

<figure><img src="image_17.png" /></figure>

<figure><img src="image_18.png" /></figure>
<figure><img src="image_19.png" /></figure>

Cérin, Sow & Kayani

Online Machine Learning for ESP32

July 3th, 2024

11/23

Online K-Means Clustering

<figure><img src="image_20.png" /></figure>

<figure><img src="image_21.png" /></figure>

<figure><img src="image_22.png" /></figure>

<figure><img src="image_23.png" /></figure>

<figure><img src="image_24.png" /></figure>

<figure><img src="image_25.png" /></figure>

Cérin, Sow & Kayani

Online Machine Learning for ESP32

July 3th, 2024

12/23
<figure><img src="image_26.png" /></figure>

<figure><img src="image_27.png" /></figure>

<table><thead><tr><th rowspan="2">W Slice</th><th colspan="2">256 messages</th><th colspan="2">512 messages</th><th colspan="2">1024 messages</th><th colspan="2">5120 messages</th></tr><tr><th>It. Max</th><th>It. Got</th><th>It. Max</th><th>It. Got</th><th>It. Max</th><th>It. Got</th><th>It. Max</th><th>It. Got</th></tr></thead><tbody><tr><td>512</td><td>x</td><td>x</td><td>1</td><td>1</td><td>2</td><td>1</td><td>10</td><td>2</td></tr><tr><td>256</td><td>1</td><td>1</td><td>2</td><td>2</td><td>4</td><td>3</td><td>20</td><td>4</td></tr><tr><td>128</td><td>2</td><td>2</td><td>4</td><td>4</td><td>8</td><td>8</td><td>40</td><td>40</td></tr><tr><td>64</td><td>4</td><td>4</td><td>8</td><td>8</td><td>16</td><td>16</td><td>80</td><td>80</td></tr><tr><td>32</td><td>8</td><td>8</td><td>16</td><td>16</td><td>32</td><td>32</td><td>160</td><td>160</td></tr></tbody></table>

Online K-Means Analysis with ESP32

➤ Successfully process the online machine algorithm on ESP32 for real streaming Data ;

➤ More data in the window leads to more accurate results (as expected) ;

➤ The number of iterations has not much impact on the clustering outcome ;

➤ Challenges with Online K-means:

* Limited storage capacity.

* Distance-centric method sometimes yield suboptimal results.
Perform the DBSCAN with same dataset get the correct
number of clusters

<figure><img src="image_28.png" /></figure>

Cérin, Sow & Kayani

Online Machine Learning for ESP32

July 3th, 2024

15/23

Part. 3 Github Contributions
* The repository contains two branches: one for Micropython+ulab, one for Arduino;

* Because the communities love both;

* The Arduino branch includes an exhaustive study on the processing of data from the Grenoble IOT Campus dataset with the Arduino IDE and on the ESP32 MicroController.

<figure><img src="image_29.png" /></figure>

GitHub

https://github.com/christophe-cerin/OnlineML_ESP32/tree/main
The main resource for our project can be found on our GitHub repository

Cérin, Sow & Kayani

Online Machine Learning for ESP32

July 3th, 2024

17/23

## GitHub contribution

* It highlights the combined use of the MQTT protocol thanks to the WIFI card integrated into ESP32 and the K-Means algorithm (the JPDC one);

* Information on the Campus IOT data acquisition hardware, energy consumption measurements and the implemented K-Means Clustering algorithm are also available online.

<figure><img src="image_30.png" /></figure>

GitHub

https://github.com/christophe-cerin/OnlineML_ESP32/tree/main
The main resource for our project can be found on our GitHub repository
<figure><img src="image_31.png" /><figcaption>## Measure with Power Profiler Kit II</figcaption></figure>

<figure><img src="image_32.png" /></figure>

Cérin, Sow & Kayani

Online Machine Learning for ESP32

July 3th, 2024

19/23

# Part. 4 Conclusion & Future Works
<figure><img src="image_33.png" /></figure>

"Times are changing"

○ Emphasizes the need for tools like **ulab** to evolve like **NumPy 2.0.0 & 2.1.0**;

○ Highlights adapting to new innovations and advancements;

○ Stresses the importance of continuous updates to keep tools effective and relevant.

<figure><img src="image_34.png" /></figure>

Adaptation of River Algorithms.

<figure><img src="image_35.png" /></figure>

Online ML algorithms specific scenarios encountered in LIGLAB.

Cérin, Sow & Kayani

Online Machine Learning for ESP32

July 3th, 2024

21/23

Conclusion & Future Works

<figure><img src="image_36.png" /></figure>

Demonstrate ESP32's capability for real-time data;

<figure><img src="image_37.png" /></figure>

Efficiently manages online k-means clustering;

<figure><img src="image_38.png" /></figure>

Misclassification observed on "real data" with reinitialized clusters;

<figure><img src="image_39.png" /></figure>

K-means encounters difficulties with dynamic data;

<figure><img src="image_40.png" /></figure>

Online DBSCAN and DB-STREAM for accuracy and flexibility;

<figure><img src="image_41.png" /></figure>

Highlight importance of addressing concept drift.
# Data Acquisition and Operation with Micropython

```
1 #!/bin/bash
2
3 # CSV file path
4 csv_file="meeting3.csv"
5 # Filename where we save the data on the local computer
6 name=$(date +%d%m%Y%H%M%N.csv)
7
8 # Read the CSV file line by line
9 while IFS=, read -r Co2 temperature
10
11 do
12   # Skip the header line
13   if [ "$timestamp" != "timestamp" ]; then
14     # Processing logic with extracted Co2($i) and temp($j)
15     i=$Co2
16     j=$temperature
17   fi
18   # Publish data using mosquitto_pub
19   /usr/bin/mosquitto_pub -h 10.188.186.20 -u root -P
20   Sunny789 -t temp -m "$i,$j"
21
22   # Append data to the local file
23   # echo "$i,$j,$k" >> ${name}
24
25   # Sleep for a short duration
26   sleep 0.05s
27
28 done < "$csv_file"
29
30 # Publish the signal to terminate
31 /usr/bin/mosquitto_pub -h localhost -t temp -m "0.0.0.0"
32
33 # Publish the file name of generated data
34 /usr/bin/mosquitto_pub -h localhost -u root -P Sunny789 -t
35 temp -m "Meeting2 Data,Coming!"
```

```
algorithm.py *
317 connect_wifi()
318 client = MQTTClient("esp32", MQTT_BROKER, MQTT_PORT,
319                       MQTT_USER, MQTT_PASSWORD)
320 client.set_callback(on_message)
321 client.connect()
322 client.subscribe(MQTTaldP)
323 print('Connected to MQTT broker')
324
325 try:
326     while True:
327         client.wait_msg()
328     finally:
329         client disconne(
330         print('Disconnected from MQTT broker')
331 )

shell > Kayani@kayani-HP-EliteB...
MPT /meeting2.sh
MicroPython v1.23.0 preview.322.951472c1e.d1rty on 2024-04-04
le with ESP32
Type "help()" for more information.
>>> Initialized Clusters !!!!!!!!!!
WiFi connected: ('10.42.0.38', '255.255.255.0', '10.42.
Connected to MOTT broker
[0] ===> [802.5455, 22.4] is assigned to cluster 0
[1] ===> [801.8182, 22.4] is assigned to cluster 0
[2] ===> [797.6364, 22.42727] is assigned to cluster 0
[3] ===> [803.9091, 22.52727] is assigned to cluster 0
[4] ===> [809.0, 22.6] is assigned to cluster 0
[5] ===> [810.9091, 22.65454] is assigned to cluster 0
[6] ===> [817.0909, 22.82727] is assigned to cluster 1
[7] ===> [833.9091, 22.92727] is assigned to cluster 1
```