Jump to content

MDM331AID/Experiment 14

From cognifront

Experiment: Smart Threshold Alerts for Data Minimization using Privacy-by-Design

Aim

To design and implement a Privacy-by-Design IoT system using a vibration sensor and ESP32 that detects excessive vibration using a predefined threshold and generates an alert only when the threshold condition is reached, thereby minimizing unnecessary sensor data transmission.

Objectives

  1. To understand Privacy-by-Design in an IoT system.
  2. To understand the concept of data minimization.
  3. To interface a vibration sensor with ESP32.
  4. To detect vibration activity using the sensor.
  5. To define a threshold for excessive vibration.
  6. To generate an EXCESSIVE VIBRATION alert when the threshold is crossed.
  7. To process vibration data locally on the ESP32.
  8. To avoid continuously transmitting raw vibration readings.
  9. To expose only the required alert information.
  10. To demonstrate data minimization through a simple web-based monitoring system.

Components Required

Sr. No. Component Quantity Purpose
1 ESP32 Development Board 1 Reads the vibration sensor and hosts the web server
2 Vibration Sensor Module 1 Detects vibration activity
3 Breadboard 1 Circuit connections
4 Jumper Wires As required Electrical connections
5 Smartphone 1 Accesses the ESP32 web page
6 USB Cable 1 Programming and powering ESP32
7 Computer with Arduino IDE 1 Programming the ESP32

Theory

Internet of Things

The Internet of Things, or IoT, is a system in which physical devices use sensors and communication technologies to collect and exchange information.

In a conventional IoT system, sensor readings may be continuously transmitted even when the application does not require all of the readings.

For example, a vibration monitoring system may continuously generate sensor readings.

If the purpose of the application is only to detect excessive vibration, the application does not necessarily need every individual sensor reading.

The ESP32 can instead process the vibration activity locally and generate an alert only when the required condition occurs.

Privacy-by-Design

Privacy-by-Design means that privacy considerations are incorporated into the design of a system from the beginning.

One important approach related to Privacy-by-Design is data minimization.

Data minimization means collecting, processing, transmitting, and storing only the information that is necessary for the intended purpose.

In this experiment, the purpose is to detect excessive vibration.

Therefore, the system does not need to continuously expose every raw vibration reading.

The ESP32 processes the vibration activity locally and generates an alert only when the predefined threshold condition is reached.

Smart Threshold Alert

A threshold is a predefined value used to determine when a particular condition has occurred.

The ESP32 monitors the vibration sensor and keeps track of vibration activity.

When the number of detected vibration events reaches the selected threshold within the monitoring period, the ESP32 considers the vibration level excessive.

The operation is:

Vibration Sensor
       |
       v
     ESP32
       |
       v
Monitor vibration activity
       |
       v
Check threshold
       |
       +----------------------+
       |                      |
       v                      v
Normal vibration       Excessive vibration
       |                      |
       v                      v
   No alert          EXCESSIVE VIBRATION

The threshold can be adjusted according to the sensor and the required application.

Data Minimization

In a conventional system, raw vibration readings may be continuously sent to another device or server.

In the proposed system:

Vibration Sensor
       |
       v
Local processing on ESP32
       |
       v
Count vibration activity
       |
       v
Check threshold
       |
       +----------------------+
       |                      |
       v                      v
Below threshold         Threshold reached
       |                      |
       v                      v
   No alert          EXCESSIVE VIBRATION

The raw vibration activity is processed locally for decision making.

Unnecessary continuous sensor data is therefore not exposed outside the device.

Sensor Connection

The vibration sensor module normally provides VCC, GND, and a digital output pin.

Vibration Sensor Pin ESP32 Description
VCC 3.3V Sensor power supply
DO or OUT GPIO 27 Digital vibration signal
GND GND Common ground

Note: The exact pin names may vary between vibration sensor modules. Verify the labels on the actual sensor before making the connections.

Connection Diagram

             Vibration Sensor
             +-------------+
             |             |
     3.3V ---| VCC         |
             |             |
 GPIO 27 <---| DO / OUT    |
             |             |
     GND ----| GND         |
             +-------------+
                    |
                    |
                  ESP32
                    |
                    |
             Wi-Fi Access Point
                    |
                    |
             Smartphone Browser
                    |
                    |
              192.168.1.4

Working Principle

The ESP32 works as a Wi-Fi Access Point and hosts a simple web server.

The smartphone connects directly to the Wi-Fi network created by the ESP32.

The student then opens:

http://192.168.1.4

The ESP32 monitors the vibration sensor.

Each detected vibration event increases the vibration count during the monitoring period.

When the vibration count reaches the predefined threshold, the ESP32 generates an EXCESSIVE VIBRATION alert.

The web page displays the current status.

The web page automatically refreshes every 5 seconds so that the latest status can be observed.

The raw vibration activity is processed locally on the ESP32.

#include <WiFi.h>
#include <WebServer.h>

const int VIBRATION_PIN=27;
const char* ap_ssid="ESP32-Vibration-Monitor";
const char* ap_password="12345678";

WebServer server(80);

const int VIBRATION_THRESHOLD=100;
const unsigned long MONITOR_PERIOD=10000;

int vibrationCount=0;
bool excessiveVibration=false;
unsigned long periodStart=0;
int lastSensorState=LOW;

void updateVibration()
{
  int sensorState=digitalRead(VIBRATION_PIN);

  if(sensorState==HIGH && lastSensorState==LOW)
  {
    vibrationCount++;
  }

  lastSensorState=sensorState;

  if(millis()-periodStart>=MONITOR_PERIOD)
  {
    if(vibrationCount>=VIBRATION_THRESHOLD)
    {
      excessiveVibration=true;
      Serial.println("EXCESSIVE VIBRATION");
      Serial.println("Alert generated.");
    }
    else
    {
      excessiveVibration=false;
      Serial.println("NORMAL");
      Serial.println("Vibration level is within the normal range.");
    }

    Serial.print("Vibration events: ");
    Serial.println(vibrationCount);

    Serial.println("--------------------");

    vibrationCount=0;
    periodStart=millis();
  }
}

void handleRoot()
{
  updateVibration();

  String page="";

  char lt=60;
  char gt=62;

  page+=lt;
  page+="html";
  page+=gt;

  page+=lt;
  page+="head";
  page+=gt;

  page+=lt;
  page+="meta name='viewport' content='width=device-width, initial-scale=1'";
  page+=gt;

  page+=lt;
  page+="meta http-equiv='refresh' content='5'";
  page+=gt;

  page+=lt;
  page+="title";
  page+=gt;
  page+="Vibration Monitor";
  page+=lt;
  page+="/title";
  page+=gt;

  page+=lt;
  page+="/head";
  page+=gt;

  page+=lt;
  page+="body";
  page+=gt;

  page+=lt;
  page+="h1";
  page+=gt;
  page+="Smart Vibration Monitor";
  page+=lt;
  page+="/h1";
  page+=gt;

  if(excessiveVibration)
  {
    page+=lt;
    page+="h2";
    page+=gt;
    page+="EXCESSIVE VIBRATION";
    page+=lt;
    page+="/h2";
    page+=gt;

    page+=lt;
    page+="p";
    page+=gt;
    page+="Threshold crossed. Alert generated.";
    page+=lt;
    page+="/p";
    page+=gt;
  }
  else
  {
    page+=lt;
    page+="h2";
    page+=gt;
    page+="NORMAL";
    page+=lt;
    page+="/h2";
    page+=gt;

    page+=lt;
    page+="p";
    page+=gt;
    page+="Vibration level is within the normal range.";
    page+=lt;
    page+="/p";
    page+=gt;
  }

  page+=lt;
  page+="p";
  page+=gt;
  page+="Page refreshes every 5 seconds.";
  page+=lt;
  page+="/p";
  page+=gt;

  page+=lt;
  page+="/body";
  page+=gt;

  page+=lt;
  page+="/html";
  page+=gt;

  server.send(200,"text/html",page);
}

void setup()
{
  Serial.begin(115200);

  pinMode(VIBRATION_PIN,INPUT);

  periodStart=millis();

  WiFi.softAPConfig(
    IPAddress(192,168,1,4),
    IPAddress(192,168,1,1),
    IPAddress(255,255,255,0)
  );

  WiFi.softAP(ap_ssid,ap_password);

  Serial.println("ESP32 Access Point started");
  Serial.print("IP Address: ");
  Serial.println(WiFi.softAPIP());

  server.on("/",handleRoot);
  server.begin();

  Serial.println("Web server started");
  Serial.println("--------------------");
}

void loop()
{
  updateVibration();
  server.handleClient();
}

Code Explanation

Code or Function Explanation
WiFi.h Provides ESP32 Wi-Fi functionality.
WebServer.h Provides web server functionality.
VIBRATION_PIN Defines GPIO 27 as the vibration sensor input.
WiFi.softAP Creates a Wi-Fi Access Point using the ESP32.
WiFi.softAPConfig Sets the Access Point IP address to 192.168.1.4.
WebServer server(80) Creates an HTTP web server on port 80.
VIBRATION_THRESHOLD Defines the number of vibration events required to generate an alert.
MONITOR_PERIOD Defines the time interval over which vibration events are counted.
vibrationCount Stores the number of detected vibration events.
excessiveVibration Stores whether the excessive-vibration condition has been detected.
digitalRead Reads the digital output of the vibration sensor.
updateVibration Detects vibration events and checks the threshold.
handleRoot Generates the web page displayed on the smartphone.
server.send Sends the web page to the browser.
server.handleClient Processes browser requests.

Access Point

The ESP32 creates its own Wi-Fi network.

The network name is:

ESP32-Vibration-Monitor

The IP address is:

192.168.1.4

The smartphone can therefore access the web page using:

http://192.168.1.4

Vibration Detection

The ESP32 reads the digital output of the vibration sensor:

int sensorState = digitalRead(VIBRATION_PIN);

When a vibration event causes the sensor output to change from LOW to HIGH, the vibration count is increased.

if (sensorState == HIGH && lastSensorState == LOW)
{
  vibrationCount++;
}

This allows the ESP32 to count vibration events locally.

Threshold Detection

The program uses a vibration threshold:

const int VIBRATION_THRESHOLD = 5;

The monitoring period is:

const unsigned long MONITOR_PERIOD = 10000;

This means that the ESP32 counts vibration events during a 10 second period.

If the number of detected events is 5 or more, the system generates the excessive vibration alert.

The threshold can be changed depending on the sensor and demonstration requirements.

Calibration of Vibration Threshold

The threshold should be tested before performing the main experiment.

  1. Upload the program to the ESP32.
  2. Open the Arduino IDE Serial Monitor.
  3. Keep the vibration sensor stationary.
  4. Observe the system under normal conditions.
  5. Tap or shake the vibration sensor several times.
  6. Observe how the sensor responds.
  7. Select a suitable vibration threshold.
  8. Change the VIBRATION_THRESHOLD value if required.
  9. Upload the program again.
  10. Verify that normal vibration does not unnecessarily generate an alert.
  11. Verify that repeated vibration generates the alert.

For a simple classroom demonstration, the threshold can be kept low so that students can easily trigger the alert by tapping or shaking the sensor.

Procedure

  1. Connect the vibration sensor to the ESP32.
  2. Connect VCC to 3.3V.
  3. Connect GND to GND.
  4. Connect the digital output of the vibration sensor to GPIO 27.
  5. Connect the ESP32 to the computer.
  6. Open Arduino IDE.
  7. Select the appropriate ESP32 board.
  8. Select the appropriate COM port.
  9. Upload the program.
  10. Open the Serial Monitor.
  11. Verify that the ESP32 Access Point has started.
  12. Connect the smartphone to ESP32-Vibration-Monitor.
  13. Open the smartphone browser.
  14. Enter http://192.168.1.4.
  15. Observe the NORMAL status.
  16. Keep the vibration sensor stationary.
  17. Tap or shake the sensor repeatedly.
  18. Generate several vibration events within the monitoring period.
  19. Observe the EXCESSIVE VIBRATION alert.
  20. Wait for the next monitoring period and observe the status.
  21. Verify that the web page refreshes automatically every 5 seconds.
  22. Perform the data minimization demonstration.

Observations and Output

Normal Condition

When the vibration sensor is stationary or experiences only minor vibration:

Sensor Condition : Normal
System Status    : NORMAL
Alert            : None

The system does not generate an alert.

Excessive Vibration Condition

When repeated vibration events cross the predefined threshold:

Sensor Condition : Excessive vibration
System Status    : ALERT
Alert            : EXCESSIVE VIBRATION

The ESP32 generates the alert locally.

Smartphone Output

Normal condition:

SMART VIBRATION MONITOR

NORMAL

Vibration level is within
the normal range.

Page refreshes every 5 seconds.

Excessive vibration condition:

SMART VIBRATION MONITOR

EXCESSIVE VIBRATION

Threshold crossed.
Alert generated.

Page refreshes every 5 seconds.

Demonstration of Data Minimization

The main purpose of this experiment is to demonstrate that unnecessary raw sensor information does not need to be continuously transmitted.

Conventional System

In a conventional IoT system, every sensor event or sensor reading could be transmitted to a server.

For example:

Vibration event detected
Vibration event detected
Vibration event detected
Vibration event detected
Vibration event detected

The server would receive a continuous stream of sensor information.

Privacy-by-Design System

In the proposed system, the ESP32 processes the vibration activity locally.

The ESP32 counts the vibration events and compares the count with the threshold.

The process is:

Vibration activity
       |
       v
Local processing
       |
       v
Count events
       |
       v
Check threshold
       |
       +---------------------+
       |                     |
       v                     v
Below threshold        Threshold reached
       |                     |
       v                     v
   No alert          EXCESSIVE VIBRATION

The raw vibration activity is not required outside the ESP32 for the basic application.

Only the required alert needs to be exposed.

Data Inspection Demonstration

The data inspection demonstration is used to compare the amount of information exposed by two system designs.

The demonstration is educational and is intended to show the effect of data minimization.

Conventional Design

A conventional system may continuously expose individual vibration events:

Vibration event
Vibration event
Vibration event
Vibration event
Vibration event

An observer can therefore obtain detailed information about the vibration activity.

Privacy-by-Design Design

The Privacy-by-Design system processes the vibration activity locally.

When the vibration count is below the threshold:

No alert

When the threshold is reached:

EXCESSIVE VIBRATION

The application therefore exposes only the information required for the intended purpose.

Demonstration Steps

  1. Connect the smartphone to the ESP32 Access Point.
  2. Open the ESP32 web page.
  3. Observe the NORMAL condition.
  4. Tap or shake the vibration sensor repeatedly.
  5. Generate enough vibration events to cross the threshold.
  6. Observe the EXCESSIVE VIBRATION alert.
  7. Inspect the application data using an appropriate network inspection or server logging method.
  8. Observe that the application does not need to continuously expose every vibration event.
  9. Explain that the ESP32 processes the vibration activity locally before generating the alert.

Note: This demonstration is about data minimization. It does not claim that HTTP communication is encrypted or completely secure.

Conventional System vs Privacy-by-Design System

Feature Conventional System Privacy-by-Design System
Sensor processing May be performed at server Performed locally on ESP32
Vibration events May be continuously transmitted Processed locally
Normal activity May be transmitted No unnecessary transmission
Threshold detection May be performed at server Performed on ESP32
Alert May contain detailed sensor information Only required alert is exposed
Data volume Higher Lower
Data exposure Higher Minimized

Why This is Privacy-by-Design

The experiment demonstrates Privacy-by-Design through the following design decisions:

  1. Local Processing: Vibration activity is processed on the ESP32.
  2. Data Minimization: Individual vibration events do not need to be continuously transmitted.
  3. Purpose Limitation: The system only needs to detect excessive vibration.
  4. Smart Thresholding: An alert is generated only when the vibration threshold is crossed.
  5. Reduced Data Exposure: Unnecessary sensor information is not exposed.
  6. Privacy by Default: The system is designed to minimize data exposure from the beginning.

The main principle demonstrated is:

Do not transmit unnecessary information
when the application does not require it.

Automatic Page Refresh

The web page automatically refreshes every 5 seconds.

This is implemented using the page refresh setting in the generated web page.

The refresh interval allows the student to observe the latest vibration status without manually refreshing the browser.

The refresh interval is:

5 seconds

Therefore, after generating vibration activity, the student can wait for the next page refresh to observe the updated alert status.

Advantages

  1. Reduces unnecessary sensor data transmission.
  2. Processes vibration information locally.
  3. Reduces the amount of sensor information exposed outside the device.
  4. Allows fast local decision making.
  5. Demonstrates data minimization clearly.
  6. Does not require an external cloud server.
  7. Can be demonstrated easily using a smartphone.
  8. Vibration can be generated manually by tapping or shaking the sensor.
  9. The web page automatically refreshes every 5 seconds.
  10. Can be extended to industrial machine monitoring applications.

Limitations

  1. The vibration sensor module provides a simple indication of vibration and may not provide precise vibration measurements.
  2. The sensor may respond differently depending on the strength and duration of vibration.
  3. The threshold must be calibrated for the actual sensor and application.
  4. Environmental vibration may cause unwanted detections.
  5. The HTTP communication used in this experiment is not encrypted.
  6. This experiment demonstrates data minimization and not complete IoT security.
  7. A real industrial vibration monitoring system would normally use a more precise vibration sensor and appropriate signal processing.

Result

The smart threshold alert system was successfully implemented using a vibration sensor and ESP32.

The ESP32 locally monitored vibration activity and counted vibration events during a predefined monitoring period.

When the number of vibration events reached the selected threshold, the system generated an EXCESSIVE VIBRATION alert.

The alert was displayed on a smartphone through the ESP32 web server using:

http://192.168.1.4

The web page automatically refreshed every 5 seconds.

The experiment demonstrated that raw vibration activity does not need to be continuously exposed when the application only requires an excessive-vibration alert.

Thus, the experiment demonstrated data minimization through local processing and smart threshold alerts as a practical Privacy-by-Design approach.

Viva Questions

Q1. What is Privacy-by-Design?

Ans: Privacy-by-Design means incorporating privacy considerations into the design of a system from the beginning.

Q2. What is data minimization?

Ans: Data minimization means collecting, processing, transmitting, and storing only the data required for the intended purpose.

Q3. Why is a vibration sensor used in this experiment?

Ans: A vibration sensor is used because vibration can be generated manually by tapping or shaking the sensor, making the alert easy to demonstrate.

Q4. What does excessive vibration represent in this experiment?

Ans: Excessive vibration represents a condition in which the number of vibration events has crossed the predefined threshold.

Q5. Why is the raw vibration activity not continuously transmitted?

Ans: The application only needs to know whether excessive vibration has occurred. Therefore, continuously transmitting every vibration event is unnecessary.

Q6. Where is the vibration threshold checked?

Ans: The threshold is checked locally on the ESP32.

Q7. What happens when the threshold is not crossed?

Ans: No excessive-vibration alert is generated.

Q8. What happens when the threshold is crossed?

Ans: The ESP32 detects excessive vibration and generates the EXCESSIVE VIBRATION alert.

Q9. What is the purpose of the data inspection demonstration?

Ans: It demonstrates how data minimization reduces the amount of unnecessary sensor information exposed outside the device.

Q10. What information is required when the threshold is crossed?

Ans: The required information is the EXCESSIVE VIBRATION alert.

Q11. Why does the web page refresh every 5 seconds?

Ans: The page refreshes every 5 seconds so that the smartphone can display the latest system status automatically.

Q12. Is the system completely secure?

Ans: No. The main purpose is to demonstrate data minimization and Privacy-by-Design. The HTTP communication used here is not encrypted.

Q13. Does data minimization mean that no data is transmitted?

Ans: No. It means that only the data necessary for the intended purpose should be transmitted or exposed.

Q14. Why is local processing useful?

Ans: Local processing allows the ESP32 to make decisions using sensor data without unnecessarily exposing the raw sensor activity.

Q15. What is a smart threshold alert?

Ans: A smart threshold alert is generated when sensor activity crosses a predefined threshold representing a meaningful condition.

Q16. What is the main principle demonstrated by this experiment?

Ans: The main principle is data minimization. Sensor activity is processed locally and only the required alert is exposed.