graficar_variables_de_ups_en_grafana
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| graficar_variables_de_ups_en_grafana [2024/05/25 17:17] โ [Design notes:] oso | graficar_variables_de_ups_en_grafana [2024/10/17 21:42] (current) โ external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| **Objective: | **Objective: | ||
| + | {{: | ||
| + | |||
| + | ๐ //This image was created in May 2024, using Bing AI. Apparently it struggles a bit with the cable routing... ToDo: create this same prompt (raspberry pi connected to an UPS using an USB cable, photorealistic) in a couple of years.// | ||
| ===== Code ===== | ===== Code ===== | ||
| Line 23: | Line 26: | ||
| host=" | host=" | ||
| port=3306, | port=3306, | ||
| - | user="facundo",ย | + | user="f******",ย |
| - | password=" | + | password=" |
| database=" | database=" | ||
| ) | ) | ||
| Line 96: | Line 99: | ||
| </ | </ | ||
| + | ===== Database Creation ===== | ||
| + | |||
| + | To create the database and the necessary tables for storing the UPS data in MariaDB, you would use the following SQL commands: | ||
| + | |||
| + | 1. **Create the Database:** | ||
| + | |||
| + | <code sql> | ||
| + | CREATE DATABASE UPSstats; | ||
| + | </ | ||
| + | |||
| + | 2. **Use the Database:** | ||
| + | |||
| + | <code sql> | ||
| + | USE UPSstats; | ||
| + | </ | ||
| + | |||
| + | 3. **Create the `variables` Table:** | ||
| + | |||
| + | This table will store the variable names and their corresponding IDs. | ||
| + | |||
| + | <code sql> | ||
| + | CREATE TABLE variables ( | ||
| + | id_variable INT PRIMARY KEY, | ||
| + | variable_name VARCHAR(255) NOT NULL | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | 4. **Insert the Variables: | ||
| + | |||
| + | Insert the variables you are interested in tracking into the `variables` table. | ||
| + | |||
| + | <code sql> | ||
| + | INSERT INTO variables (id_variable, | ||
| + | (1, ' | ||
| + | (2, ' | ||
| + | (3, ' | ||
| + | (4, ' | ||
| + | (5, ' | ||
| + | (6, ' | ||
| + | (7, ' | ||
| + | </ | ||
| + | |||
| + | 5. **Create the `ups_data` Table:** | ||
| + | |||
| + | This table will store the actual data readings from the UPS. | ||
| + | |||
| + | <code sql> | ||
| + | CREATE TABLE ups_data ( | ||
| + | id INT AUTO_INCREMENT PRIMARY KEY, | ||
| + | id_variable INT, | ||
| + | value VARCHAR(255), | ||
| + | timestamp DATETIME, | ||
| + | FOREIGN KEY (id_variable) REFERENCES variables(id_variable) | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | With these commands, you will have a database named `UPSstats` with two tables: `variables` for storing the names and IDs of the variables, and `ups_data` for storing the actual readings along with their timestamps. Make sure to execute these commands in your MariaDB client to set up the database before running your Python script. | ||
| + | |||
| + | <code sql> | ||
| + | |||
| + | <code sql> | ||
| ===== Flask Service ===== | ===== Flask Service ===== | ||
| Line 175: | Line 239: | ||
| {{: | {{: | ||
| + | **Live site:** | ||
| + | https:// | ||
graficar_variables_de_ups_en_grafana.1716657476.txt.gz ยท Last modified: 2024/10/17 21:42 (external edit)
