Merge branch 'burak' of https://github.com/6028570/GoodGarden into atilla
This commit is contained in:
13
.hintrc
Normal file
13
.hintrc
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": [
|
||||
"development"
|
||||
],
|
||||
"hints": {
|
||||
"axe/text-alternatives": [
|
||||
"default",
|
||||
{
|
||||
"image-alt": "off"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
239
battery_voltage_events.py
Normal file
239
battery_voltage_events.py
Normal file
@@ -0,0 +1,239 @@
|
||||
import mysql.connector
|
||||
import requests
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import time
|
||||
|
||||
# Functie om verbinding te maken met de database
|
||||
def database_connect():
|
||||
return mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="",
|
||||
database="goodgarden"
|
||||
)
|
||||
|
||||
def calculate_timestamp(gateway_receive_time):
|
||||
# Converteer de stringrepresentatie naar een datetime-object in UTC
|
||||
datetime_obj_utc = datetime.strptime(gateway_receive_time, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
|
||||
|
||||
# Voeg het tijdsverschil van 1 uur toe voor de Nederlandse tijdzone (UTC+1)
|
||||
datetime_obj_nl = datetime_obj_utc + timedelta(hours=1)
|
||||
|
||||
# Formateer het datetime-object als een leesbare datumstring
|
||||
formatted_date = datetime_obj_nl.strftime("%Y-%m-%d %H:%M:%S")
|
||||
return formatted_date
|
||||
# Functie voor het aanmaken van gegevens in de database
|
||||
def create_data(url, access_token, repeat_count=5):
|
||||
for _ in range(repeat_count):
|
||||
try:
|
||||
headers = {"Authorization": f"Token {access_token}"}
|
||||
response = requests.get(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
print(f"Data from {url}:\n")
|
||||
|
||||
# Check if data is a list (records directly under the root)
|
||||
if isinstance(data, list):
|
||||
records = data
|
||||
elif isinstance(data, dict) and 'results' in data:
|
||||
records = data['results']
|
||||
else:
|
||||
print(f"Unexpected data format received: {data}")
|
||||
continue
|
||||
|
||||
for record in records:
|
||||
# Now, record is assumed to be a dictionary
|
||||
timestamp = record.get('timestamp', '')
|
||||
gateway_receive_time = record.get('gateway_receive_time', '')
|
||||
device = record.get('device', '')
|
||||
value = record.get('value', '')
|
||||
|
||||
# Voeg de timestamp-berekening toe
|
||||
calculated_timestamp = calculate_timestamp(gateway_receive_time)
|
||||
|
||||
print(f"\nInserted data: Timestamp: {calculated_timestamp}, Device: {device}, Battery Voltage: {value}V")
|
||||
if float(value) < 3.0:
|
||||
print("Waarschuwing: Batterijspanning is lager dan 3.0 volt. Opladen aanbevolen.\n")
|
||||
# Controleer of de batterijspanning hoger is dan 4.2 volt en geef een melding
|
||||
elif float(value) > 4.2:
|
||||
print("Melding: Batterijspanning is hoger dan 4.2 volt. Batterij is vol.\n")
|
||||
else:
|
||||
print("Melding: Batterijspanning is binnen het gewenste bereik.\n\n")
|
||||
|
||||
# Insert data into the database
|
||||
insert_data(record)
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error fetching data from {url}: {e}")
|
||||
|
||||
print("Waiting for the next create action...\n")
|
||||
time.sleep(2)
|
||||
|
||||
def insert_data(record):
|
||||
mydb = database_connect()
|
||||
if mydb.is_connected():
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
# Hier moet je de juiste kolomnamen en gegevensindeling aanpassen op basis van de API-respons
|
||||
insert_query = """
|
||||
INSERT INTO goodgarden.battery_voltage_events (timestamp, gateway_receive_time, device, value)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
"""
|
||||
|
||||
try:
|
||||
# Voer de query uit zonder de timestamp te berekenen
|
||||
timestamp = record.get('timestamp', '')
|
||||
gateway_receive_time = record.get('gateway_receive_time', '')
|
||||
device = record.get('device', '')
|
||||
value = record.get('value', '')
|
||||
|
||||
print(f"Inserting data: timestamp={timestamp}, gateway_receive_time={gateway_receive_time}, device={device}, value={value}\n") # Print de ingevoerde gegevens
|
||||
|
||||
mycursor.execute(insert_query, (timestamp, gateway_receive_time, device, value))
|
||||
|
||||
# Bevestig de wijzigingen
|
||||
mydb.commit()
|
||||
|
||||
print("Data inserted into the database.")
|
||||
|
||||
except mysql.connector.Error as err:
|
||||
print(f"Error: {err}")
|
||||
|
||||
finally:
|
||||
# Sluit cursor en verbinding
|
||||
mycursor.close()
|
||||
mydb.close()
|
||||
|
||||
# Functie voor het lezen van gegevens uit de database
|
||||
def read_data(url, access_token, repeat_count=5):
|
||||
for _ in range(repeat_count):
|
||||
try:
|
||||
headers = {"Authorization": f"Token {access_token}"}
|
||||
response = requests.get(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
print(f"Data from {url}:\n")
|
||||
|
||||
for record in data['results']:
|
||||
timestamp = record.get('timestamp', '')
|
||||
device = record.get('device', '')
|
||||
value = record.get('value', '')
|
||||
print(f"Timestamp: {timestamp}, Device: {device}, Battery Voltage: {value}V\n")
|
||||
|
||||
if float(value) < 3.0:
|
||||
print("Waarschuwing: Batterijspanning is lager dan 3.0 volt. Opladen aanbevolen.\n")
|
||||
# Controleer of de batterijspanning hoger is dan 4.2 volt en geef een melding
|
||||
elif float(value) > 4.2:
|
||||
print("Melding: Batterijspanning is hoger dan 4.2 volt. Batterij is vol.\n")
|
||||
else:
|
||||
print("Melding: Batterijspanning is binnen het gewenste bereik.\n\n")
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error fetching data from {url}: {e}")
|
||||
|
||||
print("Waiting for the next read action...\n")
|
||||
time.sleep(300)
|
||||
|
||||
# Functie voor het bijwerken van gegevens in de database
|
||||
def update_data(record_id):
|
||||
try:
|
||||
mydb = database_connect()
|
||||
|
||||
if mydb.is_connected():
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
# Controleer of het record bestaat voordat je het bijwerkt
|
||||
mycursor.execute("SELECT * FROM goodgarden.battery_voltage_events WHERE id = %s", (record_id,))
|
||||
existing_record = mycursor.fetchone()
|
||||
|
||||
if not existing_record:
|
||||
print(f"Record with ID {record_id} not found. Update operation aborted.")
|
||||
return
|
||||
|
||||
# Vraag de gebruiker om nieuwe waarden voor de andere velden
|
||||
new_timestamp = input("Enter new timestamp: ")
|
||||
new_gateway_receive_time = input("Enter new gateway_receive_time: ")
|
||||
new_device = input("Enter new device: ")
|
||||
new_value = input("Enter new value: ")
|
||||
|
||||
# Hier moet je de juiste kolomnamen aanpassen op basis van de structuur van je database
|
||||
update_query = """
|
||||
UPDATE goodgarden.battery_voltage_events
|
||||
SET timestamp = %s, gateway_receive_time = %s, device = %s, value = %s
|
||||
WHERE id = %s
|
||||
"""
|
||||
|
||||
# Voer de query uit
|
||||
print(f"Executing update query: {update_query}")
|
||||
print(f"Updating record with ID {record_id} to new values - timestamp: {new_timestamp}, gateway_receive_time: {new_gateway_receive_time}, device: {new_device}, value: {new_value}")
|
||||
|
||||
mycursor.execute(update_query, (new_timestamp, new_gateway_receive_time, new_device, new_value, record_id))
|
||||
|
||||
# Bevestig de wijzigingen
|
||||
mydb.commit()
|
||||
|
||||
print(f"Update executed. Rowcount: {mycursor.rowcount}")
|
||||
|
||||
except mysql.connector.Error as update_err:
|
||||
print(f"Error updating data: {update_err}")
|
||||
finally:
|
||||
# Zorg ervoor dat je altijd de cursor en de databaseverbinding sluit
|
||||
if 'mycursor' in locals() and mycursor is not None:
|
||||
mycursor.close()
|
||||
if 'mydb' in locals() and mydb.is_connected():
|
||||
mydb.close()
|
||||
|
||||
# Functie voor het verwijderen van gegevens uit de database
|
||||
def delete_data(record_id):
|
||||
mydb = database_connect()
|
||||
if mydb.is_connected():
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
# Hier moet je de juiste kolomnamen aanpassen op basis van de structuur van je database
|
||||
delete_query = """
|
||||
DELETE FROM goodgarden.battery_voltage_events
|
||||
WHERE id = %s
|
||||
"""
|
||||
|
||||
# Voer de query uit
|
||||
mycursor.execute(delete_query, (record_id,))
|
||||
|
||||
# Bevestig de wijzigingen
|
||||
mydb.commit()
|
||||
|
||||
# Sluit cursor en verbinding
|
||||
mycursor.close()
|
||||
mydb.close()
|
||||
|
||||
print(f"Data with ID {record_id} deleted.")
|
||||
|
||||
# Functie voor het aanmaken van gegevens in de database op basis van batterijspanningsinformatie
|
||||
if __name__ == "__main__":
|
||||
url = "https://garden.inajar.nl/api/battery_voltage_events/?format=json"
|
||||
access_token = "33bb3b42452306c58ecedc3c86cfae28ba22329c" # Vervang dit door je werkelijke toegangstoken
|
||||
|
||||
# Je kunt repeat_count wijzigen om te bepalen hoe vaak je de bewerking wilt herhalen
|
||||
repeat_count = 10
|
||||
|
||||
# Keuze voor de bewerking
|
||||
operation_choice = input("Choose operation (C for Create, R for Read, U for Update, D for Delete): ").upper()
|
||||
|
||||
if operation_choice == "C":
|
||||
# Maak gegevens aan
|
||||
create_data(url, access_token, repeat_count)
|
||||
elif operation_choice == "R":
|
||||
# Lees gegevens
|
||||
read_data(url, access_token, repeat_count)
|
||||
elif operation_choice == "U":
|
||||
# Update gegevens
|
||||
record_id = int(input("Enter record ID to update: "))
|
||||
# Call the update_data function without additional arguments
|
||||
update_data(record_id)
|
||||
elif operation_choice == "D":
|
||||
# Verwijder gegevens
|
||||
record_id = int(input("Enter record ID to delete: "))
|
||||
delete_data(record_id)
|
||||
else:
|
||||
print("Invalid operation choice. Please choose C, R, U, or D.")
|
||||
421
goodgarden.sql
Normal file
421
goodgarden.sql
Normal file
@@ -0,0 +1,421 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 5.2.1
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: 127.0.0.1
|
||||
-- Gegenereerd op: 14 feb 2024 om 14:36
|
||||
-- Serverversie: 10.4.28-MariaDB
|
||||
-- PHP-versie: 8.2.4
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */
|
||||
;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */
|
||||
;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */
|
||||
;
|
||||
/*!40101 SET NAMES utf8mb4 */
|
||||
;
|
||||
|
||||
--
|
||||
-- Database: `goodgarden`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabelstructuur voor tabel `battery_voltage_events`
|
||||
--
|
||||
|
||||
CREATE TABLE `battery_voltage_events` (
|
||||
`id` int(10) UNSIGNED NOT NULL, `timestamp` int(11) DEFAULT NULL, `gateway_receive_time` varchar(50) DEFAULT NULL, `device` int(11) DEFAULT NULL, `value` decimal(10, 5) DEFAULT NULL
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Gegevens worden geëxporteerd voor tabel `battery_voltage_events`
|
||||
--
|
||||
|
||||
INSERT INTO
|
||||
`battery_voltage_events` (
|
||||
`id`, `timestamp`, `gateway_receive_time`, `device`, `value`
|
||||
)
|
||||
VALUES (
|
||||
1, 1707825721, '2024-02-13T12:02:01Z', 256, 4.09890
|
||||
),
|
||||
(
|
||||
2, 1707837460, '2024-02-13T15:17:40Z', 322, 4.10501
|
||||
),
|
||||
(
|
||||
3, 1707825721, '2024-02-13T12:02:01Z', 256, 4.09890
|
||||
),
|
||||
(
|
||||
4, 1707837460, '2024-02-13T15:17:40Z', 322, 4.10501
|
||||
),
|
||||
(
|
||||
5, 1707825721, '2024-02-13T12:02:01Z', 256, 4.09890
|
||||
),
|
||||
(
|
||||
6, 1707837460, '2024-02-13T15:17:40Z', 322, 4.10501
|
||||
),
|
||||
(
|
||||
7, 1707825721, '2024-02-13T12:02:01Z', 256, 4.09890
|
||||
),
|
||||
(
|
||||
8, 1707837460, '2024-02-13T15:17:40Z', 322, 4.10501
|
||||
),
|
||||
(
|
||||
9, 1707825721, '2024-02-13T12:02:01Z', 256, 4.09890
|
||||
),
|
||||
(
|
||||
10, 1707837460, '2024-02-13T15:17:40Z', 322, 4.10501
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabelstructuur voor tabel `devices`
|
||||
--
|
||||
|
||||
CREATE TABLE `devices` (
|
||||
`id` int(10) UNSIGNED NOT NULL, `serial_number` varchar(255) DEFAULT NULL, `name` varchar(255) DEFAULT NULL, `label` varchar(255) DEFAULT NULL, `last_seen` int(11) DEFAULT NULL, `last_battery_voltage` float DEFAULT NULL
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Gegevens worden geëxporteerd voor tabel `devices`
|
||||
--
|
||||
|
||||
INSERT INTO
|
||||
`devices` (
|
||||
`id`, `serial_number`, `name`, `label`, `last_seen`, `last_battery_voltage`
|
||||
)
|
||||
VALUES (
|
||||
1, '0033889B1BAB1169', 'firefly2_0051', 'The Field', 1707765066, 4.09768
|
||||
),
|
||||
(
|
||||
2, '006FE1FC316ED7D8', 'firefly2_0111', 'The Field', 1707764966, 4.10745
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabelstructuur voor tabel `fetch`
|
||||
--
|
||||
|
||||
CREATE TABLE `fetch` (
|
||||
`id` int(10) UNSIGNED NOT NULL, `timestamp` int(11) DEFAULT NULL, `gateway_receive_time` varchar(50) DEFAULT NULL, `device` int(11) DEFAULT NULL, `value` decimal(10, 5) DEFAULT NULL
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Gegevens worden geëxporteerd voor tabel `fetch`
|
||||
--
|
||||
|
||||
INSERT INTO
|
||||
`fetch` (
|
||||
`id`, `timestamp`, `gateway_receive_time`, `device`, `value`
|
||||
)
|
||||
VALUES (
|
||||
70, 1707851215, '2024-02-13T19:06:55Z', 322, 0.00000
|
||||
),
|
||||
(
|
||||
71, 1707851215, '2024-02-13T19:06:55Z', 322, 1.52000
|
||||
),
|
||||
(
|
||||
72, 1707851215, '2024-02-13T19:06:55Z', 322, 12.06000
|
||||
),
|
||||
(
|
||||
73, 1707825721, '2024-02-13T12:02:01Z', 256, 4.09890
|
||||
),
|
||||
(
|
||||
74, 1707837460, '2024-02-13T15:17:40Z', 322, 4.10501
|
||||
),
|
||||
(75, 0, '', 0, 0.00000),
|
||||
(76, 0, '', 0, 0.00000),
|
||||
(
|
||||
77, 1707844638, '2024-02-13T17:17:18Z', 322, 0.00000
|
||||
),
|
||||
(
|
||||
78, 1707851099, '2024-02-13T19:04:59Z', 256, 0.00000
|
||||
),
|
||||
(
|
||||
79, 1707844638, '2024-02-13T17:17:18Z', 322, 71.08984
|
||||
),
|
||||
(
|
||||
80, 1707851099, '2024-02-13T19:04:59Z', 256, 66.72949
|
||||
),
|
||||
(
|
||||
81, 1707851215, '2024-02-13T19:06:55Z', 322, 0.00000
|
||||
),
|
||||
(
|
||||
82, 1707851215, '2024-02-13T19:06:55Z', 322, 1.52000
|
||||
),
|
||||
(
|
||||
83, 1707851215, '2024-02-13T19:06:55Z', 322, 12.06000
|
||||
),
|
||||
(84, 0, '', 0, 0.00000),
|
||||
(85, 0, '', 0, 0.00000),
|
||||
(
|
||||
86, 1707844638, '2024-02-13T17:17:18Z', 322, 0.00000
|
||||
),
|
||||
(
|
||||
87, 1707851099, '2024-02-13T19:04:59Z', 256, 0.00000
|
||||
),
|
||||
(
|
||||
88, 1707844638, '2024-02-13T17:17:18Z', 322, 71.08984
|
||||
),
|
||||
(
|
||||
89, 1707851099, '2024-02-13T19:04:59Z', 256, 66.72949
|
||||
),
|
||||
(
|
||||
90, 1707825721, '2024-02-13T12:02:01Z', 256, 4.09890
|
||||
),
|
||||
(
|
||||
91, 1707837460, '2024-02-13T15:17:40Z', 322, 4.10501
|
||||
),
|
||||
(92, 0, '', 0, 0.00000),
|
||||
(93, 0, '', 0, 0.00000),
|
||||
(
|
||||
94, 1707844638, '2024-02-13T17:17:18Z', 322, 0.00000
|
||||
),
|
||||
(
|
||||
95, 1707851099, '2024-02-13T19:04:59Z', 256, 0.00000
|
||||
),
|
||||
(
|
||||
96, 1707844638, '2024-02-13T17:17:18Z', 322, 71.08984
|
||||
),
|
||||
(
|
||||
97, 1707851099, '2024-02-13T19:04:59Z', 256, 66.72949
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabelstructuur voor tabel `par_events`
|
||||
--
|
||||
|
||||
CREATE TABLE `par_events` (
|
||||
`id` int(10) UNSIGNED NOT NULL, `timestamp` int(11) DEFAULT NULL, `gateway_receive_time` varchar(50) DEFAULT NULL, `device` int(11) DEFAULT NULL, `value` decimal(10, 5) DEFAULT NULL
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Gegevens worden geëxporteerd voor tabel `par_events`
|
||||
--
|
||||
|
||||
INSERT INTO
|
||||
`par_events` (
|
||||
`id`, `timestamp`, `gateway_receive_time`, `device`, `value`
|
||||
)
|
||||
VALUES (
|
||||
1, 1707844638, '2024-02-13T17:17:18Z', 322, 0.00000
|
||||
),
|
||||
(
|
||||
2, 1707851099, '2024-02-13T19:04:59Z', 256, 0.00000
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabelstructuur voor tabel `relative_humidity_events`
|
||||
--
|
||||
|
||||
CREATE TABLE `relative_humidity_events` (
|
||||
`id` int(10) UNSIGNED NOT NULL, `timestamp` int(11) DEFAULT NULL, `gateway_receive_time` varchar(50) DEFAULT NULL, `device` int(11) DEFAULT NULL, `value` decimal(10, 5) DEFAULT NULL
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Gegevens worden geëxporteerd voor tabel `relative_humidity_events`
|
||||
--
|
||||
|
||||
INSERT INTO
|
||||
`relative_humidity_events` (
|
||||
`id`, `timestamp`, `gateway_receive_time`, `device`, `value`
|
||||
)
|
||||
VALUES (
|
||||
3, 1707844638, '2024-02-13T17:17:18Z', 322, 71.08984
|
||||
),
|
||||
(
|
||||
4, 1707851099, '2024-02-13T19:04:59Z', 256, 66.72949
|
||||
),
|
||||
(
|
||||
5, 1707844638, '2024-02-13T17:17:18Z', 322, 71.08984
|
||||
),
|
||||
(
|
||||
6, 1707851099, '2024-02-13T19:04:59Z', 256, 66.72949
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabelstructuur voor tabel `soil_electric_conductivity_events`
|
||||
--
|
||||
|
||||
CREATE TABLE `soil_electric_conductivity_events` (
|
||||
`id` int(10) UNSIGNED NOT NULL, `timestamp` int(11) DEFAULT NULL, `gateway_receive_time` varchar(50) DEFAULT NULL, `device` int(11) DEFAULT NULL, `value` decimal(10, 5) DEFAULT NULL
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Gegevens worden geëxporteerd voor tabel `soil_electric_conductivity_events`
|
||||
--
|
||||
|
||||
INSERT INTO
|
||||
`soil_electric_conductivity_events` (
|
||||
`id`, `timestamp`, `gateway_receive_time`, `device`, `value`
|
||||
)
|
||||
VALUES (
|
||||
3, 1707851215, '2024-02-13T19:06:55Z', 322, 0.00000
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabelstructuur voor tabel `soil_relative_permittivity_events`
|
||||
--
|
||||
|
||||
CREATE TABLE `soil_relative_permittivity_events` (
|
||||
`id` int(10) UNSIGNED NOT NULL, `timestamp` int(11) DEFAULT NULL, `gateway_receive_time` varchar(50) DEFAULT NULL, `device` int(11) DEFAULT NULL, `value` decimal(10, 5) DEFAULT NULL
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Gegevens worden geëxporteerd voor tabel `soil_relative_permittivity_events`
|
||||
--
|
||||
|
||||
INSERT INTO
|
||||
`soil_relative_permittivity_events` (
|
||||
`id`, `timestamp`, `gateway_receive_time`, `device`, `value`
|
||||
)
|
||||
VALUES (
|
||||
3, 1707851215, '2024-02-13T19:06:55Z', 322, 1.52000
|
||||
);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabelstructuur voor tabel `soil_temperature_events`
|
||||
--
|
||||
|
||||
CREATE TABLE `soil_temperature_events` (
|
||||
`id` int(10) NOT NULL, `timestamp` int(11) DEFAULT NULL, `gateway_receive_time` varchar(50) DEFAULT NULL, `device` int(11) DEFAULT NULL, `value` decimal(10, 5) DEFAULT NULL
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Gegevens worden geëxporteerd voor tabel `soil_temperature_events`
|
||||
--
|
||||
|
||||
INSERT INTO
|
||||
`soil_temperature_events` (
|
||||
`id`, `timestamp`, `gateway_receive_time`, `device`, `value`
|
||||
)
|
||||
VALUES (
|
||||
3, 1707851215, '2024-02-13T19:06:55Z', 322, 12.06000
|
||||
);
|
||||
|
||||
--
|
||||
-- Indexen voor geëxporteerde tabellen
|
||||
--
|
||||
|
||||
--
|
||||
-- Indexen voor tabel `battery_voltage_events`
|
||||
--
|
||||
ALTER TABLE `battery_voltage_events` ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexen voor tabel `devices`
|
||||
--
|
||||
ALTER TABLE `devices` ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexen voor tabel `fetch`
|
||||
--
|
||||
ALTER TABLE `fetch` ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexen voor tabel `par_events`
|
||||
--
|
||||
ALTER TABLE `par_events` ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexen voor tabel `relative_humidity_events`
|
||||
--
|
||||
ALTER TABLE `relative_humidity_events` ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexen voor tabel `soil_electric_conductivity_events`
|
||||
--
|
||||
ALTER TABLE `soil_electric_conductivity_events`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexen voor tabel `soil_relative_permittivity_events`
|
||||
--
|
||||
ALTER TABLE `soil_relative_permittivity_events`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexen voor tabel `soil_temperature_events`
|
||||
--
|
||||
ALTER TABLE `soil_temperature_events` ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor geëxporteerde tabellen
|
||||
--
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor een tabel `battery_voltage_events`
|
||||
--
|
||||
ALTER TABLE `battery_voltage_events`
|
||||
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 11;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor een tabel `devices`
|
||||
--
|
||||
ALTER TABLE `devices`
|
||||
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 3;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor een tabel `fetch`
|
||||
--
|
||||
ALTER TABLE `fetch`
|
||||
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 98;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor een tabel `par_events`
|
||||
--
|
||||
ALTER TABLE `par_events`
|
||||
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 3;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor een tabel `relative_humidity_events`
|
||||
--
|
||||
ALTER TABLE `relative_humidity_events`
|
||||
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 7;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor een tabel `soil_electric_conductivity_events`
|
||||
--
|
||||
ALTER TABLE `soil_electric_conductivity_events`
|
||||
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 4;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor een tabel `soil_relative_permittivity_events`
|
||||
--
|
||||
ALTER TABLE `soil_relative_permittivity_events`
|
||||
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 4;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT voor een tabel `soil_temperature_events`
|
||||
--
|
||||
ALTER TABLE `soil_temperature_events`
|
||||
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 4;
|
||||
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */
|
||||
;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */
|
||||
;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */
|
||||
;
|
||||
50
src/get_data.php
Normal file
50
src/get_data.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// Database-verbinding instellen (vervang deze gegevens door je eigen databasegegevens)
|
||||
$servername = "localhost";
|
||||
$username = "root";
|
||||
$password = "";
|
||||
$dbname = "goodgarden";
|
||||
|
||||
// Verbinding maken met de database
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
// Controleren op een geslaagde verbinding
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Query om gegevens op te halen uit de tabel devices
|
||||
$query_devices = "SELECT * FROM devices";
|
||||
$result_devices = $conn->query($query_devices);
|
||||
|
||||
// Query om gegevens op te halen uit de tabel battery_voltage_events
|
||||
$query_battery_voltage = "SELECT * FROM battery_voltage_events";
|
||||
$result_battery_voltage = $conn->query($query_battery_voltage);
|
||||
|
||||
// Query om gegevens op te halen uit de tabel fetch
|
||||
$query_fetch = "SELECT * FROM fetch";
|
||||
$result_fetch = $conn->query($query_fetch);
|
||||
|
||||
// Array om resultaten op te slaan
|
||||
$data = array();
|
||||
|
||||
// Controleren of er resultaten zijn van de tabel devices
|
||||
if ($result_devices->num_rows > 0) {
|
||||
$data['devices'] = $result_devices->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
// Controleren of er resultaten zijn van de tabel battery_voltage_events
|
||||
if ($result_battery_voltage->num_rows > 0) {
|
||||
$data['battery_voltage_events'] = $result_battery_voltage->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
// Controleren of er resultaten zijn van de tabel fetch
|
||||
if ($result_fetch->num_rows > 0) {
|
||||
$data['fetch'] = $result_fetch->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
// Gegevens als JSON-uitvoer
|
||||
echo json_encode($data);
|
||||
|
||||
// Verbinding sluiten
|
||||
$conn->close();
|
||||
@@ -111,5 +111,3 @@ function drawLineChart()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawLineChart();
|
||||
@@ -53,7 +53,7 @@
|
||||
<table class="kas-table-1">
|
||||
<tr>
|
||||
<td>Aantal geplant:</td>
|
||||
<td>2</td>
|
||||
<td id="totale_planten">Loading...</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Succesvolle Oogst:</td>
|
||||
@@ -105,5 +105,15 @@
|
||||
</article>
|
||||
</section>
|
||||
</section>
|
||||
</body>
|
||||
<script>
|
||||
// JavaScript-code om gegevens op te halen van het PHP-bestand
|
||||
fetch('get_data.php')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('totale_planten').innerHTML = data.totale_planten;
|
||||
// Voeg andere velden toe op dezelfde manier
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
8
src/py/calculate.py
Normal file
8
src/py/calculate.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# In calculate.py
|
||||
|
||||
|
||||
# Doe je berekeningen hier, vervang 42 door je berekende waarde
|
||||
calculated_value = 42
|
||||
|
||||
# Print het resultaat, dat zal worden gelezen door de PythonShell.run callback
|
||||
print(calculated_value)
|
||||
Reference in New Issue
Block a user