diff --git a/docs/codeDocumentation.md b/docs/codeDocumentation.md
index cf3c2ac..69992d5 100644
--- a/docs/codeDocumentation.md
+++ b/docs/codeDocumentation.md
@@ -7,35 +7,31 @@ The provided codebase consists of two primary files: `index.js` (running on the
Together, these files create a web-based interface for using Tasmota-powered devices as a timer. The following description outlines the functionality and interactions between these files.
-# index.html
+# File: index.html
The `index.html` file is a web page designed to control the timerfunction on a Tasmota devices via a simple user interface. It contains several HTML elements, JavaScript functions, and CSS references to facilitate control and status monitoring of the Tasmota timer. This part is rendered and executed at the client side, to create a GUI and define actions for its control elements. The static file index.html together with the ascociated stylesheet (`index.css`) are served by a call to index.js.
-
-Details on HTML Structure
+##Details on HTML Structure
-
Head Section:
+*Head Section:*
- Sets up meta tags for character set and viewport settings.
- Includes app title and links to an external CSS stylesheet for styling (
index.css
).
-Body Section:
+*Body Section:*
- Formats app including its title image (header.png).
- A
div
with the ID controls
including a dropdown menu for selecting a device, a switch to toggle device power, Inputs for setting timer duration in hours and minutes and Buttons to set and clear timers.
- A
div
with the ID log
displays the current timer status, last user action, and error messages when aplicable.
-
-
-Details on JavaScript functionality
-
Embedded within the HTML file, the JavaScript handles the interaction logic:
+Embedded within the HTML file, the JavaScript handles the interaction using the following logic:
-
Initialization and WebSocket Setup:
+*Initialization and WebSocket Setup:*
- The WebSocket connection is established with the server.
- Functions to update the device status and handle WebSocket events are defined.
-Device Control Functions:
+*Device Control Functions:*
togglePower()
: Toggles the power state of the selected device and updates the status display.
setTimerWithDelta()
: Sets a timer based on user input for hours and minutes and enables timers on the device.
clearTimer()
: Clears any active timers on the device and updates the status display.
@@ -43,42 +39,43 @@ The `index.html` file is a web page designed to control the timerfunction on a T
deviceChanged()
: Updates the status display when a different device is selected.
-Utility Functions:
+*Utility Functions:*
getLocalTimeString()
: Returns the current local time as a formatted string.
getSelectedDevice()
: Retrieves the currently selected device from the dropdown menu.
sendCommand()
: Sends commands to the server to interact with the device, handling responses and errors appropriately.
-Event Listeners:
+*Event Listeners:*
- On page load, the list of devices is fetched from the server, and the first device is selected by default.
- Periodic updates to device status are set to occur every minute.
-
-# index.js
+# File: index.js
-The index.js
file implements the server-side logic using Node.js, handling HTTP requests to interact with Tasmota devices. It reads configuration settings, manages user authentication, and serves static files and API endpoints. This part is executed at the server side.
+The index.js
file implements the server-side logic using Node.js, handling HTTP requests to interact with Tasmota devices. It reads configuration settings, manages user authentication, and serves static files and API endpoints. This part is executed at the server side. The following functionality is provided:
-
-Server Setup and Configuration
+## Server Setup and Configuration
+
+Dependencies and Initialization:*
-
Dependencies and Initialization:
- Requires essential modules:
http
, fs
, path
, crypto
, and url
.
- Initializes server settings like hostname, port, and debug mode.
- Defines utility functions for password hashing, input sanitization, and authentication.
-Configuration File Loading:
+*Configuration File Loading:*
+
Reads and parses config.json
and settings.json
to load user credentials and device accounts.
-
-
-HTTP Server
-
-Server Creation:
+
+## HTTP Server
+
+*Server Creation:*
+
Creates an HTTP server to listen for incoming requests.
-Request Handling:
+*Request Handling:*
+
Handles different routes based on the request URL:
POST /login
: Authenticates users using credentials from the request body.
- Serves static files (
index.html
, styles.css
, favicon.ico
, and header.png
).
@@ -86,7 +83,8 @@ Handles different routes based on the request URL:
- The following device-specific routes are defined (
/setPower
, /getTime
, /setTimer
, /clearTimer
, /getTimerStatus
, /getPowerStatus
, /enableTimers
, /disableTimers
).
-Command Execution:
+*Command Execution:*
+
Defines functions to handle device commands:
handleSetPower()
: Sets the power state of a device.
handleSetTimer()
: Sets a timer on a device.
@@ -95,7 +93,8 @@ Handles different routes based on the request URL:
handleEnableTimers()
, handleDisableTimers()
Enables or disables timers on a device.
-Utility Functions:
+*Utility Functions:*
+
isAuthorized()
: Checks if a request contains valid authentication credentials.
serveStaticFile()
: Serves static files from the server's public directory.
logMessage()
: Logs messages to a file if debug mode is enabled.
@@ -104,7 +103,6 @@ Handles different routes based on the request URL:
getCurrentDeviceTime()
: Get the current time from the Tasmota device.
sanitizeInput()
: Sanitize input to prevent XSS attacks.
-
## Logging and Debugging