Technical Documentation
Camera Tuning Page
Purpose
The Camera Tuning Page is designed to allow users to input and modify variables related to camera settings in a user-friendly manner. The primary goal is to collect user-inputted values, convert them into JSON format, and then update the variables.json file.
HTML Structure
The HTML code consists of input fields with the number type, each labeled for their independent ID. Below is a snippet representing part of the form:
1 2 3 4 5 6 7 8 9 10 11 |
|
JavaScript Function: UpdateCamera()
Input Collection
The function starts by collecting values from input fields based on their unique IDs. For example:
1 |
|
Fetching variables.json
The function then fetches the variables.json file and converts the response into jsonData. It updates jsonData if any values from the input fields are not null or an empty string, parsing them into integers.
1 2 3 4 5 6 7 8 |
|
Updating and Sending Data
After updating jsonData, it is converted back to JSON format. The function then fetches a PHP file (updateJson.php) using a POST request to update the variables.json file. Error handling is implemented to log any errors in the console.
1 2 3 4 5 6 7 8 |
|
PHP: updateJson.php
The PHP file receives JSON data through a POST request, decodes it, and updates the variables.json file. It responds with success or error messages, providing appropriate status codes.
1 2 3 4 5 6 7 8 |
|
Reset Values
Purpose
The Reset Values function is designed to reset input fields to default values based on the Defaultvariables.json file.
JavaScript Function: ResetValues()
The function fetches Defaultvariables.json, extracts values, and updates the corresponding input fields.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Flask Web Application with MQTT Integration
Overview
The provided Python code represents a Flask web application designed for controlling carts, configuring broker settings, and managing camera settings. The application utilizes the Paho MQTT client library for MQTT communication and incorporates custom modules and scripts for combined server and camera functionality.
Dependencies
sys: Provides access to system-specific parameters and functions. paho.mqtt.client: The MQTT client library for handling MQTT communication. json: Facilitates JSON encoding and decoding. combinedServerAndCamera: A custom module that includes functionality for sending JSON messages (send_json_message) and running the camera (main). logging: A module for configuring and utilizing logging within the application. Flask: A lightweight web framework for building web applications in Python. subprocess: Enables the creation and management of additional processes. os: Provides a way to interact with the operating system, used for handling file paths.
Flask Web Application Initialization
Create Flask App: Initializes a Flask web application instance.
1 |
|
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Flask Routes
Main Page ("/")
GET and POST Handling: Handles both GET and POST requests for the main page ("/"). For POST requests, retrieves form data (cartID, distanceID, angleID) and sends a JSON message using the send_json_message function.
1 2 3 4 |
|
Broker Settings ("/brokerSettings") and Camera Settings ("/cameraSettings")
Render Templates: Renders templates for the broker settings and camera settings pages.
1 2 3 4 5 6 7 8 |
|
Update variables.json ("/updateJson")
POST Request Handling: Defines a route for updating variables.json via a POST request. Receives JSON data from the request body, updates the JSON file, and responds with success or error messages.
1 2 3 4 |
|
Run Camera ("/runCamera")
GET Request Handling: Defines a route for running the camera. Calls the main function from the custom module and renders the camera settings template.
1 2 3 4 |
|
Flask Application Execution
Run Application: Executes the Flask application when the script is executed directly.
1 2 |
|
Summary
This Flask web application provides a user interface for cart control, broker settings, and camera settings. It utilizes the Paho MQTT client library for communication, includes custom modules for additional functionality, and follows a modular structure with distinct routes for different functionalities. The application is designed to be executed as a standalone script, showcasing a combination of web and IoT functionalities.