week3.2
This commit is contained in:
123
DUMMY.json
Normal file
123
DUMMY.json
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
|
||||||
|
// Deze spanningswaarden zijn relatief hoog, wat suggereert dat de batterijen van de sensoren goed opgeladen zijn. De meeste sensorapparaten gebruiken batterijen die een nominale spanning van ongeveer 3,7 volt hebben (typisch voor lithium-ion batterijen) en kunnen worden beschouwd als "volledig opgeladen" wanneer ze een spanning dicht bij of iets boven 4,1 volt bereiken
|
||||||
|
"battery_voltage_events": [
|
||||||
|
{
|
||||||
|
"timestamp": 1707825721,
|
||||||
|
"gateway_receive_time": "2024-02-13T12:02:01Z",
|
||||||
|
"device": 256,
|
||||||
|
"value": 4.098901271820068
|
||||||
|
// Volledig opgeladen: Rond 4.2 volt.
|
||||||
|
// Nominale spanning: Ongeveer 3.7 volt.
|
||||||
|
// Kritiek laag: Minder dan 3.0 volt.
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"timestamp": 1707837460,
|
||||||
|
"gateway_receive_time": "2024-02-13T15:17:40Z",
|
||||||
|
"device": 322,
|
||||||
|
"value": 4.105006217956543
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"id": 256,
|
||||||
|
"serial_number": "0033889B1BAB1169",
|
||||||
|
"name": "firefly2_0051",
|
||||||
|
"label": "The Field",
|
||||||
|
"last_seen": 1707765066,
|
||||||
|
"last_battery_voltage": 4.09768009185791
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 322,
|
||||||
|
"serial_number": "006FE1FC316ED7D8",
|
||||||
|
"name": "firefly2_0111",
|
||||||
|
"label": "The Field",
|
||||||
|
"last_seen": 1707764966,
|
||||||
|
"last_battery_voltage": 4.107448101043701
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Fotosyntese??? (zonlicht)
|
||||||
|
"par_events": [
|
||||||
|
{
|
||||||
|
"timestamp": 1707844638,
|
||||||
|
"gateway_receive_time": "2024-02-13T17:17:18Z",
|
||||||
|
"device": 322,
|
||||||
|
"value": 0.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"timestamp": 1707851099,
|
||||||
|
"gateway_receive_time": "2024-02-13T19:04:59Z",
|
||||||
|
"device": 256,
|
||||||
|
"value": 0.0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Luchtvochtigheid
|
||||||
|
"relative_humidity_events": [
|
||||||
|
{
|
||||||
|
"timestamp": 1707844638,
|
||||||
|
"gateway_receive_time": "2024-02-13T17:17:18Z",
|
||||||
|
"device": 322,
|
||||||
|
"value": 71.08984375
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"timestamp": 1707851099,
|
||||||
|
"gateway_receive_time": "2024-02-13T19:04:59Z",
|
||||||
|
"device": 256,
|
||||||
|
"value": 66.7294921875
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// De "soil_electric_conductivity_events" gegevens wijzen op metingen van de elektrische geleidbaarheid (EC) van de bodem, een indicator van de hoeveelheid oplosbare zouten of voedingsstoffen in de bodem. EC wordt gemeten in Siemens per meter (S/m) of, voor bodemmetingen, vaak in milliSiemens per centimeter (mS/cm). Een hogere EC-waarde duidt op een hogere concentratie van opgeloste zouten, wat belangrijk is voor het bepalen van de voedingsstatus van de bodem en het beheren van de bemesting voor optimale plantengroei.
|
||||||
|
"soil_electric_conductivity_events": [
|
||||||
|
{
|
||||||
|
"timestamp": 1707851215,
|
||||||
|
"gateway_receive_time": "2024-02-13T19:06:55Z",
|
||||||
|
"device": 322,
|
||||||
|
"value": 0.0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// In de context van bodemmetingen, geeft deze waarde inzicht in het vochtgehalte van de bodem, omdat water een relatief hoge diëlektrische constante heeft in vergelijking met droge bodem of lucht.
|
||||||
|
"soil_relative_permittivity_events": [
|
||||||
|
{
|
||||||
|
"timestamp": 1707851215,
|
||||||
|
"gateway_receive_time": "2024-02-13T19:06:55Z",
|
||||||
|
"device": 322,
|
||||||
|
"value": 1.52
|
||||||
|
// Een waarde van 1.52 is relatief laag en suggereert dat de bodem droog kan zijn op het moment van meting. Ter referentie, de diëlektrische constante van lucht is ongeveer 1, terwijl water een diëlektrische constante heeft van ongeveer 80 bij kamertemperatuur.
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//De "soil_temperature_events" gegevens bevatten informatie over de temperatuur van de bodem op een specifiek tijdstip. De waarde geeft de temperatuur van de bodem aan in graden Celsius (°C).
|
||||||
|
"soil_temperature_events": [
|
||||||
|
{
|
||||||
|
"timestamp": 1707851215,
|
||||||
|
"gateway_receive_time": "2024-02-13T19:06:55Z",
|
||||||
|
"device": 322,
|
||||||
|
"value": 12.06
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
35
ReadMe.md
Normal file
35
ReadMe.md
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# GoodGarden
|
||||||
|
|
||||||
|
Welkom bij ons project genaamd "GoodGarden". Wij hebben besloten om er een monolitisch project van te maken. Alles is te vinden binnen deze repository.
|
||||||
|
|
||||||
|
### Vereisten
|
||||||
|
|
||||||
|
* Python
|
||||||
|
* Node.Js
|
||||||
|
* XAMPP (of andere naar keuze)
|
||||||
|
|
||||||
|
### Installeren
|
||||||
|
|
||||||
|
Zorg dat je in de hoofdmap "GoodGarden" zit. Kijk in je path: "../GoodGarden". Als je in de correcte map zit moet je de volgende items installeren:
|
||||||
|
|
||||||
|
- npm install electron
|
||||||
|
- npm install express
|
||||||
|
- npm install body-parser
|
||||||
|
- npm install python-shell
|
||||||
|
|
||||||
|
- pip install mysql-connector-python
|
||||||
|
- pip install requests
|
||||||
|
|
||||||
|
## Gebruik
|
||||||
|
|
||||||
|
Een paar voorbeelden van nuttig gebruik van dit project of hoe het gebruikt kan worden.
|
||||||
|
|
||||||
|
## Versiebeheer
|
||||||
|
|
||||||
|
We gebruiken [SemVer](http://semver.org/) voor versiebeheer. Voor de beschikbare versies, zie de [tags op deze repository](https://example.com/tags).
|
||||||
|
|
||||||
|
## Auteurs
|
||||||
|
|
||||||
|
* **Jouw Naam** - *Initieel werk* - [Gebruikersnaam](https://example.com/)
|
||||||
|
|
||||||
|
Zie ook de lijst van [bijdragers](https://example.com/contributors) die hebben bijgedragen aan dit project.
|
||||||
@@ -2,7 +2,7 @@ import mysql.connector
|
|||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# Functie om verbinding te maken met de database
|
# Function to make a connection to the database
|
||||||
def database_connect():
|
def database_connect():
|
||||||
return mysql.connector.connect(
|
return mysql.connector.connect(
|
||||||
host="localhost",
|
host="localhost",
|
||||||
@@ -11,8 +11,8 @@ def database_connect():
|
|||||||
database="goodgarden"
|
database="goodgarden"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Functie voor het aanmaken van gegevens in de database
|
# Function for creating data in the database based on battery voltage information from the API
|
||||||
def create_data(url, access_token, repeat_count=5):
|
def create_data_from_api(url, access_token, repeat_count=5):
|
||||||
for _ in range(repeat_count):
|
for _ in range(repeat_count):
|
||||||
try:
|
try:
|
||||||
headers = {
|
headers = {
|
||||||
@@ -22,29 +22,60 @@ def create_data(url, access_token, repeat_count=5):
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
print(f"Data from {url}:")
|
insert_data(data['results'])
|
||||||
print(data)
|
|
||||||
insert_data(data)
|
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"Error fetching data from {url}: {e}")
|
print(f"Error fetching data from {url}: {e}")
|
||||||
|
|
||||||
# Wacht een bepaalde tijd (bijv. 1 seconde) voordat de volgende oproep wordt gedaan
|
# Wait for a certain time (e.g., 1 second) before making the next API call
|
||||||
print("Waiting for the next create action...")
|
print("Waiting for the next create action...")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# Functie voor het invoegen van gegevens in de database
|
# Function for inserting data into the database
|
||||||
def insert_data(data):
|
def insert_data(data):
|
||||||
mydb = database_connect()
|
mydb = database_connect()
|
||||||
if mydb.is_connected():
|
if mydb.is_connected():
|
||||||
mycursor = mydb.cursor()
|
mycursor = mydb.cursor()
|
||||||
|
|
||||||
|
# Adjust column names and data format based on the API response
|
||||||
|
insert_query = """
|
||||||
|
INSERT INTO goodgarden.battery_voltage_events (timestamp, gateway_receive_time, device, value)
|
||||||
|
VALUES (%s, %s, %s, %s)
|
||||||
|
"""
|
||||||
|
for record in data:
|
||||||
|
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}")
|
||||||
|
|
||||||
|
# Execute the query
|
||||||
|
mycursor.execute(insert_query, (timestamp, gateway_receive_time, device, value))
|
||||||
|
|
||||||
|
# Confirm the changes
|
||||||
|
mydb.commit()
|
||||||
|
|
||||||
|
# Close cursor and connection
|
||||||
|
mycursor.close()
|
||||||
|
mydb.close()
|
||||||
|
|
||||||
|
print("Data inserted into the database.")
|
||||||
|
# Functie voor het aanmaken van gegevens in de database op basis van batterijspanningsinformatie
|
||||||
|
def create_data_from_battery_info(battery_info, repeat_count=5):
|
||||||
|
for _ in range(repeat_count):
|
||||||
|
try:
|
||||||
# Hier moet je de juiste kolomnamen en gegevensindeling aanpassen op basis van de API-respons
|
# Hier moet je de juiste kolomnamen en gegevensindeling aanpassen op basis van de API-respons
|
||||||
insert_query = """
|
insert_query = """
|
||||||
INSERT INTO goodgarden.battery_voltage_events (timestamp, gateway_receive_time, device, value)
|
INSERT INTO goodgarden.battery_voltage_events (timestamp, gateway_receive_time, device, value)
|
||||||
VALUES (%s, %s, %s, %s)
|
VALUES (%s, %s, %s, %s)
|
||||||
"""
|
"""
|
||||||
for record in data['results']: # Pas dit aan op basis van de werkelijke structuur van de JSON
|
|
||||||
|
mydb = database_connect()
|
||||||
|
if mydb.is_connected():
|
||||||
|
mycursor = mydb.cursor()
|
||||||
|
|
||||||
|
for record in battery_info:
|
||||||
timestamp = record.get('timestamp', '')
|
timestamp = record.get('timestamp', '')
|
||||||
gateway_receive_time = record.get('gateway_receive_time', '')
|
gateway_receive_time = record.get('gateway_receive_time', '')
|
||||||
device = record.get('device', '')
|
device = record.get('device', '')
|
||||||
@@ -55,6 +86,14 @@ def insert_data(data):
|
|||||||
# Voer de query uit
|
# Voer de query uit
|
||||||
mycursor.execute(insert_query, (timestamp, gateway_receive_time, device, value))
|
mycursor.execute(insert_query, (timestamp, gateway_receive_time, device, value))
|
||||||
|
|
||||||
|
# Controleer of de batterijspanning lager is dan 4.5 volt en geef een melding
|
||||||
|
if float(value) < 3.4:
|
||||||
|
print("Waarschuwing: Batterijspanning is lager dan 3.4 volt. Opladen aanbevolen.")
|
||||||
|
# Controleer of de batterijspanning hoger is dan 4.3 volt en geef een melding
|
||||||
|
elif float(value) > 3.9:
|
||||||
|
print("Melding: Batterijspanning is hoger dan 3.9 volt. Batterij is vol.")
|
||||||
|
|
||||||
|
|
||||||
# Bevestig de wijzigingen
|
# Bevestig de wijzigingen
|
||||||
mydb.commit()
|
mydb.commit()
|
||||||
|
|
||||||
@@ -64,7 +103,15 @@ def insert_data(data):
|
|||||||
|
|
||||||
print("Data inserted into the database.")
|
print("Data inserted into the database.")
|
||||||
|
|
||||||
# Functie voor het lezen van gegevens uit de database
|
except mysql.connector.Error as e:
|
||||||
|
print(f"Error inserting data into the database: {e}")
|
||||||
|
|
||||||
|
# Wacht een bepaalde tijd (bijv. 1 seconde) voordat de volgende oproep wordt gedaan
|
||||||
|
print("Waiting for the next create action...")
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
# Function for reading data from the database
|
||||||
def read_data(url, access_token, repeat_count=5):
|
def read_data(url, access_token, repeat_count=5):
|
||||||
for _ in range(repeat_count):
|
for _ in range(repeat_count):
|
||||||
try:
|
try:
|
||||||
@@ -81,11 +128,11 @@ def read_data(url, access_token, repeat_count=5):
|
|||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"Error fetching data from {url}: {e}")
|
print(f"Error fetching data from {url}: {e}")
|
||||||
|
|
||||||
# Wacht een bepaalde tijd (bijv. 1 seconde) voordat de volgende oproep wordt gedaan
|
# Wait for a certain time (e.g., 1 second) before making the next API call
|
||||||
print("Waiting for the next read action...")
|
print("Waiting for the next read action...")
|
||||||
time.sleep(300)
|
time.sleep(300)
|
||||||
|
|
||||||
# Functie voor het bijwerken van gegevens in de database
|
# Function for updating data in the database
|
||||||
def update_data(record_id):
|
def update_data(record_id):
|
||||||
try:
|
try:
|
||||||
mydb = database_connect()
|
mydb = database_connect()
|
||||||
@@ -93,7 +140,6 @@ def update_data(record_id):
|
|||||||
if mydb.is_connected():
|
if mydb.is_connected():
|
||||||
mycursor = mydb.cursor()
|
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,))
|
mycursor.execute("SELECT * FROM goodgarden.battery_voltage_events WHERE id = %s", (record_id,))
|
||||||
existing_record = mycursor.fetchone()
|
existing_record = mycursor.fetchone()
|
||||||
|
|
||||||
@@ -101,26 +147,22 @@ def update_data(record_id):
|
|||||||
print(f"Record with ID {record_id} not found. Update operation aborted.")
|
print(f"Record with ID {record_id} not found. Update operation aborted.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Vraag de gebruiker om nieuwe waarden voor de andere velden
|
|
||||||
new_timestamp = input("Enter new timestamp: ")
|
new_timestamp = input("Enter new timestamp: ")
|
||||||
new_gateway_receive_time = input("Enter new gateway_receive_time: ")
|
new_gateway_receive_time = input("Enter new gateway_receive_time: ")
|
||||||
new_device = input("Enter new device: ")
|
new_device = input("Enter new device: ")
|
||||||
new_value = input("Enter new value: ")
|
new_value = input("Enter new value: ")
|
||||||
|
|
||||||
# Hier moet je de juiste kolomnamen aanpassen op basis van de structuur van je database
|
|
||||||
update_query = """
|
update_query = """
|
||||||
UPDATE goodgarden.battery_voltage_events
|
UPDATE goodgarden.battery_voltage_events
|
||||||
SET timestamp = %s, gateway_receive_time = %s, device = %s, value = %s
|
SET timestamp = %s, gateway_receive_time = %s, device = %s, value = %s
|
||||||
WHERE id = %s
|
WHERE id = %s
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Voer de query uit
|
|
||||||
print(f"Executing update query: {update_query}")
|
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}")
|
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))
|
mycursor.execute(update_query, (new_timestamp, new_gateway_receive_time, new_device, new_value, record_id))
|
||||||
|
|
||||||
# Bevestig de wijzigingen
|
|
||||||
mydb.commit()
|
mydb.commit()
|
||||||
|
|
||||||
print(f"Update executed. Rowcount: {mycursor.rowcount}")
|
print(f"Update executed. Rowcount: {mycursor.rowcount}")
|
||||||
@@ -128,32 +170,26 @@ def update_data(record_id):
|
|||||||
except mysql.connector.Error as update_err:
|
except mysql.connector.Error as update_err:
|
||||||
print(f"Error updating data: {update_err}")
|
print(f"Error updating data: {update_err}")
|
||||||
finally:
|
finally:
|
||||||
# Zorg ervoor dat je altijd de cursor en de databaseverbinding sluit
|
|
||||||
if 'mycursor' in locals() and mycursor is not None:
|
if 'mycursor' in locals() and mycursor is not None:
|
||||||
mycursor.close()
|
mycursor.close()
|
||||||
if 'mydb' in locals() and mydb.is_connected():
|
if 'mydb' in locals() and mydb.is_connected():
|
||||||
mydb.close()
|
mydb.close()
|
||||||
|
|
||||||
|
# Function for deleting data from the database
|
||||||
# Functie voor het verwijderen van gegevens uit de database
|
|
||||||
def delete_data(record_id):
|
def delete_data(record_id):
|
||||||
mydb = database_connect()
|
mydb = database_connect()
|
||||||
if mydb.is_connected():
|
if mydb.is_connected():
|
||||||
mycursor = mydb.cursor()
|
mycursor = mydb.cursor()
|
||||||
|
|
||||||
# Hier moet je de juiste kolomnamen aanpassen op basis van de structuur van je database
|
|
||||||
delete_query = """
|
delete_query = """
|
||||||
DELETE FROM goodgarden.battery_voltage_events
|
DELETE FROM goodgarden.battery_voltage_events
|
||||||
WHERE id = %s
|
WHERE id = %s
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Voer de query uit
|
|
||||||
mycursor.execute(delete_query, (record_id,))
|
mycursor.execute(delete_query, (record_id,))
|
||||||
|
|
||||||
# Bevestig de wijzigingen
|
|
||||||
mydb.commit()
|
mydb.commit()
|
||||||
|
|
||||||
# Sluit cursor en verbinding
|
|
||||||
mycursor.close()
|
mycursor.close()
|
||||||
mydb.close()
|
mydb.close()
|
||||||
|
|
||||||
@@ -161,27 +197,19 @@ def delete_data(record_id):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
url = "https://garden.inajar.nl/api/battery_voltage_events/?format=json"
|
url = "https://garden.inajar.nl/api/battery_voltage_events/?format=json"
|
||||||
access_token = "33bb3b42452306c58ecedc3c86cfae28ba22329c" # Vervang dit door je werkelijke toegangstoken
|
access_token = "33bb3b42452306c58ecedc3c86cfae28ba22329c" # Replace this with your actual access token
|
||||||
|
|
||||||
# Je kunt repeat_count wijzigen om te bepalen hoe vaak je de bewerking wilt herhalen
|
|
||||||
repeat_count = 10
|
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()
|
operation_choice = input("Choose operation (C for Create, R for Read, U for Update, D for Delete): ").upper()
|
||||||
|
|
||||||
if operation_choice == "C":
|
if operation_choice == "C":
|
||||||
# Maak gegevens aan
|
create_data_from_api(url, access_token, repeat_count)
|
||||||
create_data(url, access_token, repeat_count)
|
|
||||||
elif operation_choice == "R":
|
elif operation_choice == "R":
|
||||||
# Lees gegevens
|
|
||||||
read_data(url, access_token, repeat_count)
|
read_data(url, access_token, repeat_count)
|
||||||
elif operation_choice == "U":
|
elif operation_choice == "U":
|
||||||
# Update gegevens
|
|
||||||
record_id = int(input("Enter record ID to update: "))
|
record_id = int(input("Enter record ID to update: "))
|
||||||
# Call the update_data function without additional arguments
|
|
||||||
update_data(record_id)
|
update_data(record_id)
|
||||||
elif operation_choice == "D":
|
elif operation_choice == "D":
|
||||||
# Verwijder gegevens
|
|
||||||
record_id = int(input("Enter record ID to delete: "))
|
record_id = int(input("Enter record ID to delete: "))
|
||||||
delete_data(record_id)
|
delete_data(record_id)
|
||||||
else:
|
else:
|
||||||
|
|||||||
353
goodGarden.sql
353
goodGarden.sql
@@ -1,16 +1,341 @@
|
|||||||
-- DROP DATABASE IF EXISTS goodgarden;
|
-- phpMyAdmin SQL Dump
|
||||||
-- CREATE DATABASE goodgarden;
|
-- 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
|
||||||
|
|
||||||
-- CREATE TABLE goodgarden.sensor_data (
|
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||||
-- id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
START TRANSACTION;
|
||||||
-- timestamp INT,
|
SET time_zone = "+00:00";
|
||||||
-- gateway_receive_time VARCHAR(50),
|
|
||||||
-- device INT,
|
|
||||||
-- value DECIMAL(10, 5),
|
|
||||||
-- PRIMARY KEY (id)
|
|
||||||
-- );
|
|
||||||
|
|
||||||
-- Invoegen van gegevens in de 'sensor_data'-tabel
|
|
||||||
-- INSERT INTO goodgarden.sensor_data (timestamp, gateway_receive_time, device, value)
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||||
-- VALUES (1707295162, '2024-02-07T08:39:22Z', 256, 4.107448101043701),
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||||
-- (1707261284, '2024-02-06T23:14:44Z', 322, 4.111111164093018);
|
/*!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 */;
|
||||||
|
|||||||
26
index.html
Normal file
26
index.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Python Script Interaction</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Choose Operation</h1>
|
||||||
|
<label for="operation_choice">Choose operation (C for Create, R for Read, U for Update, D for Delete): </label>
|
||||||
|
<input type="text" id="operation_choice" name="operation_choice" required>
|
||||||
|
<button onclick="executeOperation()">Submit</button>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
import { executeOperation } from './index.js';
|
||||||
|
|
||||||
|
if (typeof executeOperation === 'function') {
|
||||||
|
document.getElementById('operation_choice').addEventListener('input', (event) => {
|
||||||
|
executeOperation(event.target.value);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error('executeOperation function not found.');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
17
index.js
Normal file
17
index.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// your_script.js
|
||||||
|
|
||||||
|
export function executeOperation(operationChoice) {
|
||||||
|
fetch(`/path/to/your_script.py?operation=${operationChoice}`)
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
alert(data); // You can handle the response data as needed
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
2121
package-lock.json
generated
2121
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,11 @@
|
|||||||
"electron": "^23.3.13"
|
"electron": "^23.3.13"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"elctron": "^0.0.1-security"
|
"body-parser": "^1.20.2",
|
||||||
|
"elctron": "^0.0.1-security",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"parser": "^0.1.4",
|
||||||
|
"python-shell": "^5.0.0",
|
||||||
|
"request": "^2.88.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user