Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2023sric:hardwaremonitor [2024/05/29 16:53]
ionel.patrascu3101 [ESP8266]
iothings:proiecte:2023sric:hardwaremonitor [2024/05/29 18:47] (current)
ionel.patrascu3101 [Smart Hardware Monitor]
Line 4: Line 4:
   * Email: ionel.patrascu3101@stud.acs.pub.ro   * Email: ionel.patrascu3101@stud.acs.pub.ro
   * Master: SRIC   * Master: SRIC
 +  * [[https://​youtu.be/​zqtbRrcpSKQ|Demo]]
  
 ====== Introduction ====== ====== Introduction ======
Line 209: Line 210:
 } }
 </​code>​ </​code>​
 +
 +=== Loop function ===
 +
 +
 +The ''​loop()''​ function is the heart of the ESP8266 program, continuously executing its code to manage the display and respond to user input. It starts by checking for button presses on the joystick. If the button is pressed, the code checks how long it has been pressed. If the button is pressed for more than 2 seconds, the ''​isBlocked''​ flag is toggled, effectively enabling or disabling the automatic state change mechanism. If the button is pressed for less than 2 seconds and the display is not blocked, the current display state is changed to the next state.
 +
 +Next, the function reads the analog value from the joystick'​s X-axis. If the value is below a certain threshold, indicating a leftward movement, the current state is changed to the previous state. Conversely, if the value is above another threshold, indicating a rightward movement, the state is changed to the next state.
 +
 +The function then checks if the display is blocked. If not, it checks if the ''​stateChangeInterval''​ has elapsed since the last state change. If so, the state is automatically changed to the next state.
 +
 +Finally, the function sends a request to the server to retrieve updated hardware data and then calls the appropriate display function based on the current state. The ''​delay()''​ function is used to introduce a short pause before the loop restarts.
 +
 +<code c>
 +void loop() {
 +  // Check if the button is pressed
 +  // If the button is pressed for more than 2 seconds, block the display
 +  if (digitalRead(KEY_PIN) == LOW) {
 +    if (buttonPressTime == 0) { // Button just pressed
 +      buttonPressTime = millis();
 +    } else if (millis() - buttonPressTime > 2000) { 
 +      // Button pressed for more than 2 seconds
 +      // Enable/​disable display blocking mechanism
 +      isBlocked = !isBlocked;
 +      buttonPressTime = 0;
 +    }
 +    // If the button is pressed less than 2 seconds, change the display state
 +    // if the display is not blocked
 +  } else if (buttonPressTime != 0) { 
 +    if (!isBlocked) {
 +      currentState = static_cast<​DisplayState>​((currentState + 1) % NUM_STATES);​
 +    }
 +    buttonPressTime = 0;
 +  }
 +  // Check the joystick value to change the display state
 +  int joystickValue = analogRead(X_PIN);​
 +  // Check if the joystick is moved left or right
 +  if (joystickValue < JOYSTICK_THRESHOLD / 2) { 
 +    // Joystick moved left -> Change the display state to the previous state
 +    currentState = static_cast<​DisplayState>​((currentState - 1 + NUM_STATES) % NUM_STATES);​
 +    lastStateChangeTime = millis();
 +  } else if (joystickValue > JOYSTICK_THRESHOLD * 3 / 2) { 
 +    // Joystick moved right -> Change the display state to the next state
 +    currentState = static_cast<​DisplayState>​((currentState + 1) % NUM_STATES);​
 +    lastStateChangeTime = millis();
 +  }
 +  // Update the display based on the current state if the display is not blocked
 +  if (!isBlocked) {
 +    // Change the display state every stateChangeInterval milliseconds
 +    if (millis() - lastStateChangeTime > stateChangeInterval) {
 +      currentState = static_cast<​DisplayState>​((currentState + 1) % NUM_STATES);​
 +      lastStateChangeTime = millis();
 +    }
 +  }
 +  // Call the appropriate function to retrieve updated data and then display it
 +  // based on the current state and then wait for actionDelay/​4 milliseconds
 +  sendRequest();​
 +  switch (currentState) {
 +    case OVERALL:
 +        displayOverall();​
 +        break;
 +    case CPU:
 +        displayCPU();​
 +        break;
 +    case GPU:
 +        displayGPU();​
 +        break;
 +    case RAM:
 +        displayRAM();​
 +        break;
 +    }
 +  ​
 +  delay(actionDelay/​4);​
 +}
 +</​code>​
 +
 +=== Display Functions ===
 +
 +The ''​displayOverall()''​ function is responsible for displaying a concise summary of the system'​s overall performance on the LCD screen. It retrieves the CPU load, CPU temperature,​ GPU load, and GPU temperature from the JSON document populated by the sendRequest() function. It then formats this information and displays it on the LCD in two lines.
 +
 +The function first clears the LCD screen using ''​lcd.clear()''​. Then, it sets the cursor position to the beginning of the first line (0, 0) using ''​lcd.setCursor()''​ and prints the CPU load and temperature in the format ''"​CPU:​ XX.X% XX.XC"''​. It repeats this process for the GPU on the second line (0, 1), displaying the GPU load and temperature in the same format.
 +<code c>
 +void displayOverall() {
 +  float cpuLoad = doc["/​intelcpu/​0"​]["/​intelcpu/​0/​load/​0"​];​
 +  float cpuTemp = doc["/​intelcpu/​0"​]["/​intelcpu/​0/​temperature/​0"​];​
 +  float gpuLoad = calculateGpuLoad();​ // There are five GPU sensors, we will the one with the highest load
 +  float gpuTemp = doc["/​nvidiagpu/​0"​]["/​nvidiagpu/​0/​temperature/​0"​];​
 +  lcd.clear();​
 +  lcd.setCursor(0,​ 0);
 +  lcd.printf("​CPU:​ %.1f%% %.1fC",​ cpuLoad, cpuTemp);
 +  lcd.setCursor(0,​ 1);
 +  lcd.printf("​GPU:​ %.1f%% %.1fC",​ gpuLoad, gpuTemp);
 +}
 +</​code>​
 +
 +Similar functions, ''​displayCPU()'',​ ''​displayGPU()'',​ and ''​displayRAM()'',​ are implemented to provide more detailed information about each hardware component, respectively. These functions follow a similar structure, retrieving relevant data from the JSON document and displaying it on the LCD in a user-friendly format.
 +
 +====== Results ======
 +
 +{{:​iothings:​proiecte:​2023sric:​hardwaremonitor:​connect.png |}} This section presents the visual results of the implemented system, showcasing the information displayed on the LCD screen for each of the four display states.
 +
 +===== Overall Page =====
 +{{:​iothings:​proiecte:​2023sric:​hardwaremonitor:​overall.png |}}
 +
 +The "​Overall"​ page provides a concise overview of the system'​s performance,​ displaying the CPU load and temperature alongside the GPU load and temperature. This page offers a quick glance at the system'​s general health and resource utilization.
 +
 +===== CPU Page =====
 +{{:​iothings:​proiecte:​2023sric:​hardwaremonitor:​cpu.png |}}
 +
 +The "​CPU"​ page provides more detailed information about the CPU, displaying the CPU load, temperature,​ frequency, and power consumption. This page allows for a more in-depth analysis of the CPU's performance and resource usage.
 +
 +===== GPU Page =====
 +{{:​iothings:​proiecte:​2023sric:​hardwaremonitor:​gpu.png |}}
 +
 +The "​GPU"​ page focuses on the GPU's performance,​ displaying the GPU load, temperature,​ memory usage, and power consumption. This page provides insights into the GPU's workload and resource utilization.
 +
 +===== RAM Page =====
 +
 +{{:​iothings:​proiecte:​2023sric:​hardwaremonitor:​ram.png |}}
 +The "​RAM"​ page displays the RAM usage, showing the amount of RAM currently used and available. This page helps monitor the system'​s memory utilization and identify potential memory constraints.
 +
 +===== Real-World Setup =====
 +
 +{{ :​iothings:​proiecte:​2023sric:​hardwaremonitor:​project.jpg?​600 |}}
 +This image showcases the actual physical setup of the project. The ESP8266 microcontroller is connected to the LCD display and the joystick, allowing for user interaction and real-time display updates. The ESP8266 communicates with the server to retrieve system hardware data, providing a seamless and informative experience for the user. This image highlights the practical implementation of the project, demonstrating its functionality and user-friendliness.
 +
 +
 +====== Conclusion and Future Work ======
 +The project successfully demonstrates the implementation of a real-time system hardware monitoring solution using an ESP8266 microcontroller,​ an LCD display, and a joystick for user interaction. The system effectively retrieves system hardware data from a server via a Flask API and displays it on the LCD in a user-friendly format. The user can navigate between different display states showcasing various system metrics using the joystick and its button. The system provides a valuable tool for monitoring system performance without interrupting the user's primary activity.
 +
 +Future work could focus on enhancing the user experience and functionality of the system. One potential improvement would be to replace the current LCD display with a larger, more visually appealing display. A graphical user interface (GUI) could be developed to present the information in a more intuitive and engaging way. Additionally,​ exploring the integration of additional sensors, such as temperature sensors or fan speed sensors, could provide a more comprehensive view of the system'​s health and performance.
 +
 +
 +====== References ======
 +  * OpenHardwareMonitor Library: https://​github.com/​OpenHardwareMonitor/​OpenHardwareMonitor
 +  * Flask Web Framework: https://​flask.palletsprojects.com/​
 +  * ESP8266 WiFi Library: https://​github.com/​esp8266/​Arduino
 +  * ESP8266 HTTPClient Library: https://​github.com/​esp8266/​Arduino/​tree/​master/​libraries/​ESP8266HTTPClient
 +  * ArduinoJson Library: https://​arduinojson.org/​
 +  * LiquidCrystal_I2C Library: https://​github.com/​johnrickman/​LiquidCrystal_I2C
 +  * How to Use I2C LCD with ESP32 on Arduino IDE (ESP8266 compatible):​ https://​randomnerdtutorials.com/​esp32-esp8266-i2c-lcd-arduino-ide/​
 +  * ESP8266 Pinout Reference: https://​randomnerdtutorials.com/​esp8266-pinout-reference-gpios/​
iothings/proiecte/2023sric/hardwaremonitor.1716990780.txt.gz · Last modified: 2024/05/29 16:53 by ionel.patrascu3101
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0