Homepage 1 sensor doet eht met data
This commit is contained in:
41
app.py
41
app.py
@@ -3,8 +3,7 @@ import mysql.connector
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Function to get data from the MySQL database
|
||||
def get_database_data():
|
||||
def database_connect():
|
||||
try:
|
||||
connection = mysql.connector.connect(
|
||||
host='localhost',
|
||||
@@ -12,19 +11,30 @@ def get_database_data():
|
||||
password='',
|
||||
database='goodgarden'
|
||||
)
|
||||
cursor = connection.cursor()
|
||||
return connection
|
||||
except Exception as e:
|
||||
print("Database connection failed:", e)
|
||||
return None
|
||||
|
||||
|
||||
# Function to get data from the MySQL database
|
||||
def get_database_data():
|
||||
|
||||
mydb = database_connect()
|
||||
|
||||
if mydb and mydb.is_connected():
|
||||
|
||||
cursor = mydb.cursor()
|
||||
|
||||
# Query to retrieve the latest battery voltage data
|
||||
query = "SELECT id, timestamp, gateway_receive_time, device, value FROM battery_voltage_events ORDER BY timestamp DESC LIMIT 1"
|
||||
query = "SELECT label, last_seen, last_battery_voltage, device_id FROM devices ORDER BY device_id DESC LIMIT 1"
|
||||
cursor.execute(query)
|
||||
battery_data = cursor.fetchone()
|
||||
|
||||
connection.close()
|
||||
|
||||
mydb.close()
|
||||
return battery_data
|
||||
except Exception as e:
|
||||
print("Error fetching data from database:", e)
|
||||
return None
|
||||
|
||||
# def devices_data():
|
||||
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def get_data():
|
||||
@@ -36,13 +46,14 @@ def get_data():
|
||||
|
||||
# Convert the fetched data into a dictionary
|
||||
data_dict = {
|
||||
"id": battery_data[0],
|
||||
"timestamp": str(battery_data[1]), # Convert timestamp to string for JSON serialization
|
||||
"gateway_receive_time": str(battery_data[2]), # Convert timestamp to string for JSON serialization
|
||||
"device": battery_data[3],
|
||||
"value": battery_data[4]
|
||||
"label": battery_data[0],
|
||||
"last_seen": battery_data[1],
|
||||
"last_battery_voltage": battery_data[2],
|
||||
"device_id": battery_data[3]
|
||||
}
|
||||
|
||||
print(data_dict)
|
||||
|
||||
# Return the data as JSON
|
||||
return jsonify(data_dict)
|
||||
|
||||
|
||||
@@ -1,239 +1,239 @@
|
||||
import mysql.connector
|
||||
import requests
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import time
|
||||
# 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"
|
||||
)
|
||||
# # 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)
|
||||
# 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)
|
||||
# # 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()
|
||||
# # 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")
|
||||
# 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
|
||||
# # 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', '')
|
||||
# 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)
|
||||
# # 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")
|
||||
# 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)
|
||||
# # Insert data into the database
|
||||
# insert_data(record)
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error fetching data from {url}: {e}")
|
||||
# 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)
|
||||
# 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()
|
||||
# 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)
|
||||
"""
|
||||
# # 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', '')
|
||||
# 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
|
||||
# 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))
|
||||
# mycursor.execute(insert_query, (timestamp, gateway_receive_time, device, value))
|
||||
|
||||
# Bevestig de wijzigingen
|
||||
mydb.commit()
|
||||
# # Bevestig de wijzigingen
|
||||
# mydb.commit()
|
||||
|
||||
print("Data inserted into the database.")
|
||||
# print("Data inserted into the database.")
|
||||
|
||||
except mysql.connector.Error as err:
|
||||
print(f"Error: {err}")
|
||||
# except mysql.connector.Error as err:
|
||||
# print(f"Error: {err}")
|
||||
|
||||
finally:
|
||||
# Sluit cursor en verbinding
|
||||
mycursor.close()
|
||||
mydb.close()
|
||||
# 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()
|
||||
# # 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")
|
||||
# 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")
|
||||
# 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")
|
||||
# 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}")
|
||||
# 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)
|
||||
# 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()
|
||||
# # 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()
|
||||
# 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()
|
||||
# # 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
|
||||
# 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: ")
|
||||
# # 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
|
||||
"""
|
||||
# # 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}")
|
||||
# # 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))
|
||||
# mycursor.execute(update_query, (new_timestamp, new_gateway_receive_time, new_device, new_value, record_id))
|
||||
|
||||
# Bevestig de wijzigingen
|
||||
mydb.commit()
|
||||
# # Bevestig de wijzigingen
|
||||
# mydb.commit()
|
||||
|
||||
print(f"Update executed. Rowcount: {mycursor.rowcount}")
|
||||
# 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()
|
||||
# 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()
|
||||
# # 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
|
||||
"""
|
||||
# # 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,))
|
||||
# # Voer de query uit
|
||||
# mycursor.execute(delete_query, (record_id,))
|
||||
|
||||
# Bevestig de wijzigingen
|
||||
mydb.commit()
|
||||
# # Bevestig de wijzigingen
|
||||
# mydb.commit()
|
||||
|
||||
# Sluit cursor en verbinding
|
||||
mycursor.close()
|
||||
mydb.close()
|
||||
# # Sluit cursor en verbinding
|
||||
# mycursor.close()
|
||||
# mydb.close()
|
||||
|
||||
print(f"Data with ID {record_id} deleted.")
|
||||
# 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
|
||||
# # 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
|
||||
# # 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()
|
||||
# # 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.")
|
||||
# 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.")
|
||||
|
||||
Binary file not shown.
@@ -63,7 +63,7 @@ body .mainContainer .mainBorder .pagina-titel {
|
||||
body .mainContainer .mainBorder #sectie-1 {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
gap: 0;
|
||||
padding: 0 2.5rem 0 1rem;
|
||||
position: relative;
|
||||
}
|
||||
@@ -74,7 +74,6 @@ body .mainContainer .mainBorder #sectie-1 .parent-algemeen-overzicht {
|
||||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
|
||||
border-radius: 40px;
|
||||
padding: 1rem;
|
||||
margin-top: 1rem;
|
||||
background-color: white;
|
||||
}
|
||||
body .mainContainer .mainBorder #sectie-1 .parent-algemeen-overzicht .algemeen-overzicht {
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["style.scss","style.css"],"names":[],"mappings":"AAGQ,mFAAA;AACA,2GAAA;AAgCR;;;;;EAME,wCApCY;EAqCZ,SAAA;AClCF;;ADqCA;;EAGE,iCAzCU;EA0CV,YAAA;ACnCF;;ADsCA;EAEE,qBAAA;ACpCF;;ADuCA;EAEE,iHAAA;EACA,4BAAA;EACA,sBAAA;EACA,2BAAA;EACA,iCAxDU;EAyDV,aAAA;EACA,uBAAA;EACA,mBAAA;EACA,aAAA;EACA,SAAA;ACrCF;ADuCE;EAEE,WAAA;EACA,aAAA;EACA,2CAAA;EACA,mBAAA;EACA,aAAA;ACtCJ;ADwCI;EAEE,kBAAA;EACA,WAAA;EACA,SAAA;EACA,WAAA;EACA,2BAAA;ACvCN;AD0CI;EAEE,aAAA;EACA,8BAAA;ACzCN;AD4CI;EAEE,uBAAA;EACA,eAAA;EACA,aAAA;EACA,oCAAA;EACA,mBAAA;AC3CN;AD6CM;EAEE,eAAA;EACA,mBAAA;AC5CR;AD+CM;EAEE,aAAA;EACA,sBAAA;EACA,SAAA;EACA,wBAAA;EACA,kBAAA;AC9CR;ADgDQ;EAEE,uBAAA;AC/CV;ADkDQ;EAlGN,2CAAA;EAKA,mBAAA;EAiGQ,aAAA;EACA,gBAAA;EACA,uBAAA;ACjDV;ADmDU;EA/GR,oCAAA;EAeA,mBAAA;EAoGU,kBAAA;EACA,oBAAA;AClDZ;ADoDY;EAEE,WAAA;ACnDd;ADqDc;EAEE,aAAA;EACA,8BAAA;EACA,gBAAA;AC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WAAA;EACA,YAAA;AC9HF;;ADiIA;EACE,UAAA;EACA,QAAA;EACA,SAAA;AC9HF;;ADiIA;EACE,kBAAA;EACA,eAAA;EACA,MAAA;EACA,OAAA;EACA,QAAA;EACA,SAAA;EACA,sBAAA;EACA,mBAAA;EACA,gBAAA;AC9HF;;ADiIA;EACE,kBAAA;EACA,WAAA;EACA,YAAA;EACA,WAAA;EACA,SAAA;EACA,WAAA;EACA,uBAAA;EACA,kBAAA;EACA,gBAAA;AC9HF;;ADiIA;EACE,yBAAA;AC9HF;;ADiIA;EACE,2BAAA;AC9HF;;ADiIA;EACE,aAAA;EACA,oBAAA;AC9HF;;ADiIE;;EAGE,uBAAA;AC/HJ","file":"style.css"}
|
||||
{"version":3,"sources":["style.scss","style.css"],"names":[],"mappings":"AAGQ,mFAAA;AACA,2GAAA;AAgCR;;;;;EAME,wCApCY;EAqCZ,SAAA;AClCF;;ADqCA;;EAGE,iCAzCU;EA0CV,YAAA;ACnCF;;ADsCA;EAEE,qBAAA;ACpCF;;ADuCA;EAEE,iHAAA;EACA,4BAAA;EACA,sBAAA;EACA,2BAAA;EACA,iCAxDU;EAyDV,aAAA;EACA,uBAAA;EACA,mBAAA;EACA,aAAA;EACA,SAAA;ACrCF;ADuCE;EAEE,WAAA;EACA,aAAA;EACA,2CAAA;EACA,mBAAA;EACA,aAAA;ACtCJ;ADwCI;EAEE,kBAAA;EACA,WAAA;EACA,SAAA;EACA,WAAA;EACA,2BAAA;ACvCN;AD0CI;EAEE,aAAA;EACA,8BAAA;ACzCN;AD4CI;EAEE,uBAAA;EACA,eAAA;EACA,aAAA;EACA,oCAAA;EACA,mBAAA;AC3CN;AD6CM;EAEE,eAAA;EACA,mBAAA;AC5CR;AD+CM;EAEE,aAAA;EACA,sBAAA;EAEA,MAAA;EACA,wBAAA;EACA,kBAAA;AC/CR;ADiDQ;EAEE,uBAAA;AChDV;ADmDQ;EAnGN,2CAAA;EAKA,mBAAA;EAkGQ,aAAA;EAEA,uBAAA;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AChIF;;ADmIA;;EAEE,YAAA;EACA,qBAAA;EACA,eAAA;AChIF;;ADmIA;EACE,aAAA;EACA,gBAAA;AChIF;;ADmIA;EACE,kBAAA;EACA,qBAAA;EACA,WAAA;EACA,YAAA;AChIF;;ADmIA;EACE,UAAA;EACA,QAAA;EACA,SAAA;AChIF;;ADmIA;EACE,kBAAA;EACA,eAAA;EACA,MAAA;EACA,OAAA;EACA,QAAA;EACA,SAAA;EACA,sBAAA;EACA,mBAAA;EACA,gBAAA;AChIF;;ADmIA;EACE,kBAAA;EACA,WAAA;EACA,YAAA;EACA,WAAA;EACA,SAAA;EACA,WAAA;EACA,uBAAA;EACA,kBAAA;EACA,gBAAA;AChIF;;ADmIA;EACE,yBAAA;AChIF;;ADmIA;EACE,2BAAA;AChIF;;ADmIA;EACE,aAAA;EACA,oBAAA;AChIF;;ADmIE;;EAGE,uBAAA;ACjIJ","file":"style.css"}
|
||||
@@ -110,7 +110,8 @@ body
|
||||
{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
// gap: 1rem;
|
||||
gap: 0;
|
||||
padding: 0 2.5rem 0 1rem;
|
||||
position: relative;
|
||||
|
||||
@@ -124,7 +125,7 @@ body
|
||||
@include box-shadow;
|
||||
@include border-radius;
|
||||
padding: 1rem;
|
||||
margin-top: 1rem;
|
||||
// margin-top: 1rem;
|
||||
background-color: white;
|
||||
|
||||
.algemeen-overzicht
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Homepage</title>
|
||||
<link rel="stylesheet" href="../src/css/style.css">
|
||||
<script src="../src/js/main.js" defer></script>
|
||||
<script src="../src/js/planten.class.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<section class="mainContainer">
|
||||
<article>
|
||||
<img src="../src/images/logo.png" class="goodgarden-logo">
|
||||
</article>
|
||||
<section class="mainBorder">
|
||||
<section class="content">
|
||||
<section class="kant-links">
|
||||
<table id="planten">
|
||||
<!-- <tr>
|
||||
<td>
|
||||
<article>
|
||||
<img src="images/Icon awesome-apple-alt.png" alt="">
|
||||
<h2>Tomaat</h2>
|
||||
</article>
|
||||
</td>
|
||||
<td>
|
||||
<article id="modalButton" onclick="openModal()">
|
||||
<img id="toevoegen"src="images/Toevoegen.png" alt="">
|
||||
</article>
|
||||
</td>
|
||||
</tr> -->
|
||||
</table>
|
||||
<div id="myModal" class="modal">
|
||||
<span class="close">×</span>
|
||||
<form action="http://localhost:3000/submit-form" method="post" onsubmit="return addplant()">
|
||||
|
||||
<input type="text" name="plant_naam" id="plantNaam">
|
||||
<label for="plantNaam">Naam van de plant</label>
|
||||
|
||||
<input type="text" name="plantensoort" id="plantensoort">
|
||||
<label for="plantensoort">Soort van de plant</label>
|
||||
|
||||
<input type="radio" name="plant_geteelt" id="aanwezig" value="true">
|
||||
<label for="aanwezig">Aanwezig</label>
|
||||
|
||||
<input type="radio" name="plant_geteelt" id="afwezig" value="false">
|
||||
<label for="afwezig">Afwezig</label>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<div id="overlay" onclick="closeOverlay"></div>
|
||||
</section>
|
||||
<!-- White space -->
|
||||
<section>
|
||||
</section>
|
||||
<section class="kant-rechts">
|
||||
<section id="sectie-1">
|
||||
<article class="parent-algemeen-overzicht">
|
||||
<article class="algemeen-overzicht">
|
||||
<table class="table-informatie-kas">
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Dagen tot Oogst</td>
|
||||
<td>12</td>
|
||||
<a href="sensoren.html">sensoren</a>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Dagen in Kas</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Tevredenheid</td>
|
||||
<td>80%</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Aandachtspunten</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
</table>
|
||||
</article>
|
||||
</article>
|
||||
<article class="grafiek">
|
||||
<article class="grafiek-innerbox">
|
||||
<h2>Zonlicht</h2>
|
||||
<canvas
|
||||
id="myCanvas" class="canvas-informatie-kas" width="275" height="275"></canvas>
|
||||
</article>
|
||||
</article>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Binary file not shown.
@@ -1,33 +1,51 @@
|
||||
import json
|
||||
|
||||
from db_connect import database_connect
|
||||
from paho.mqtt import subscribe
|
||||
|
||||
def on_message(client, userdata, message):
|
||||
payload_str = message.payload.decode("utf-8")
|
||||
data = json.loads(payload_str)
|
||||
|
||||
device_256 = None
|
||||
last_seen = None
|
||||
last_battery_voltage = None
|
||||
# Verbinding maken met de database
|
||||
mydb = database_connect()
|
||||
|
||||
device_322 = None
|
||||
last_seen = None
|
||||
last_battery_voltage = None
|
||||
if mydb.is_connected():
|
||||
|
||||
for key in data["results"]:
|
||||
if int(key["id"]) == 256:
|
||||
device_256 = int(key["id"])
|
||||
last_seen = int(key["last_seen"])
|
||||
last_battery_voltage = float(key["last_battery_voltage"])
|
||||
# print(f"{device_256}")
|
||||
print(f"Het device {device_256} is voor het laatst geien op: {last_seen} met de voltage als {last_battery_voltage}")
|
||||
# Creëren van een cursor object
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
elif int(key["id"]) == 322:
|
||||
device_322 = int(key["id"])
|
||||
last_seen = int(key["last_seen"])
|
||||
last_battery_voltage = float(key["last_battery_voltage"])
|
||||
# print(f"{device_256}")
|
||||
print(f"Het device {device_322} is voor het laatst gezien op: {last_seen} met de voltage als {last_battery_voltage}")
|
||||
# SQL query voor het invoegen van de gegevens
|
||||
insert_query = """
|
||||
INSERT INTO goodgarden.devices
|
||||
(serial_number, name, label, last_seen, last_battery_voltage, device_id)
|
||||
VALUES (%s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
|
||||
# Verwerken van de gegevens uit het bericht
|
||||
for record in data['results']:
|
||||
serial_number = record.get('serial_number', '')
|
||||
name = record.get('name', '')
|
||||
label = record.get('label', '')
|
||||
last_seen = record.get('last_seen', '')
|
||||
last_battery_voltage = record.get('last_battery_voltage', '')
|
||||
device_id = record.get("id", "")
|
||||
|
||||
print(f"Inserting data: serial_number={serial_number}, name={name}, label={label}, last_seen={last_seen}, last_battery_voltage={last_battery_voltage}, device_id={device_id}")
|
||||
|
||||
# Uitvoeren van de SQL query
|
||||
mycursor.execute(insert_query, (serial_number, name, label, last_seen, last_battery_voltage, device_id))
|
||||
|
||||
# Commit de transacties naar de database
|
||||
mydb.commit()
|
||||
|
||||
# Sluiten van de cursor en de databaseconnectie
|
||||
mycursor.close()
|
||||
mydb.close()
|
||||
|
||||
print("Data inserted into the database.")
|
||||
|
||||
else:
|
||||
print("Failed to connect to the database.")
|
||||
|
||||
print(f"\033[92mMessage received on topic\033[0m {message.topic}: {data}")
|
||||
|
||||
|
||||
@@ -47,3 +47,5 @@ def fetch_plant_and_write_to_json():
|
||||
|
||||
# Call the function to fetch data and write to JSON
|
||||
fetch_plant_and_write_to_json()
|
||||
# if __name__ == "__main__":
|
||||
# fetch_plant_and_write_to_json()
|
||||
|
||||
@@ -15,31 +15,25 @@
|
||||
"id": 50,
|
||||
"plant_naam": "Appel",
|
||||
"plantensoort": "Fruit",
|
||||
"plant_geteelt": 1
|
||||
"plant_geteelt": 0
|
||||
},
|
||||
{
|
||||
"id": 51,
|
||||
"plant_naam": "Sla",
|
||||
"plantensoort": "Groente",
|
||||
"plant_geteelt": 1
|
||||
},
|
||||
{
|
||||
"id": 52,
|
||||
"plant_naam": "Wietplant",
|
||||
"plantensoort": "Onkruid",
|
||||
"plant_geteelt": 1
|
||||
"plant_geteelt": 0
|
||||
},
|
||||
{
|
||||
"id": 53,
|
||||
"plant_naam": "Patat",
|
||||
"plantensoort": "Aarde",
|
||||
"plant_geteelt": 1
|
||||
"plant_geteelt": 0
|
||||
},
|
||||
{
|
||||
"id": 54,
|
||||
"plant_naam": "asfasfas",
|
||||
"plantensoort": "fasfasfsaf",
|
||||
"plant_geteelt": 1
|
||||
"plant_geteelt": 0
|
||||
},
|
||||
{
|
||||
"id": 55,
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
import os
|
||||
import time
|
||||
import requests
|
||||
import paho.mqtt.client as mqtt
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
API_URL = os.getenv("API_URL")
|
||||
MQTT_HOST = os.getenv("MQTT_HOST")
|
||||
MQTT_PORT = int(os.getenv("MQTT_PORT", 1883))
|
||||
|
||||
def get_data_from_api(request):
|
||||
links = {
|
||||
'battery': '/battery_voltage_events/',
|
||||
'devices': '/devices/',
|
||||
'parEvents': '/par_events/',
|
||||
'humidity': '/relative_humidity_events/',
|
||||
'soilConductifity': '/soil_electric_conductivity_events/',
|
||||
'soilPermittivity' : '/soil_relative_permittivity_events/',
|
||||
'soilTemperature': '/soil_temperature_events/'
|
||||
}
|
||||
headers = {
|
||||
'accept': 'application/json',
|
||||
'Authorization': f'Token {os.getenv("API_TOKEN")}'
|
||||
}
|
||||
url = API_URL + links[request]
|
||||
try:
|
||||
response = requests.get(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.HTTPError as errh:
|
||||
print ("HTTP Error:",errh)
|
||||
return None
|
||||
except requests.exceptions.ConnectionError as errc:
|
||||
print ("Error Connecting:",errc)
|
||||
return None
|
||||
except requests.exceptions.Timeout as errt:
|
||||
print ("Timeout Error:",errt)
|
||||
return None
|
||||
except requests.exceptions.RequestException as err:
|
||||
print ("Something went wrong",err)
|
||||
return None
|
||||
|
||||
data = response.json()
|
||||
return data['results']
|
||||
|
||||
def publish_to_mqtt(topic, message):
|
||||
client = mqtt.Client()
|
||||
client.connect(MQTT_HOST, MQTT_PORT, 60)
|
||||
try:
|
||||
client.publish(topic, message)
|
||||
except mqtt.MQTTException as e:
|
||||
print(f"Failed to publish message: {e}")
|
||||
finally:
|
||||
client.disconnect()
|
||||
|
||||
def process_results(link, results):
|
||||
for result in results:
|
||||
if 'timestamp' in result and 'gateway_receive_time' in result and 'device' in result and 'value' in result:
|
||||
message = f"Timestamp: {result['timestamp']}, Gateway Receive Time: {result['gateway_receive_time']}, Device: {result['device']}, Value: {result['value']}"
|
||||
print(message)
|
||||
publish_to_mqtt(link, message)
|
||||
|
||||
def main():
|
||||
links = ['battery', 'devices', 'parEvents', 'humidity', 'soilConductifity', 'soilPermittivity', 'soilTemperature']
|
||||
while True:
|
||||
for link in links:
|
||||
results = get_data_from_api(link)
|
||||
if results is not None:
|
||||
process_results(link, results)
|
||||
time.sleep(5)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,160 +1,3 @@
|
||||
// const { ipcRenderer } = require("electron");
|
||||
// const axios = require('axios');
|
||||
|
||||
// // document.addEventListener('DOMContentLoaded', () => {
|
||||
// ipcRenderer.send('request-update-temp', ['some', 'arguments']);
|
||||
|
||||
// ipcRenderer.on('update-temp-result', (event, newTemperature) => {
|
||||
// if (newTemperature === 'error') {
|
||||
// console.error('Er is een fout opgetreden bij het ophalen van de nieuwe temperatuur');
|
||||
// } else {
|
||||
// document.getElementById('bodem-temperatuur').textContent = newTemperature;
|
||||
// }
|
||||
// });
|
||||
|
||||
// // Send a message to the main process to execute the Python script
|
||||
// ipcRenderer.send('run-python-script', ['some', 'arguments']);
|
||||
|
||||
// ipcRenderer.on('python-script-response', (event, pythonData) => {
|
||||
// if (pythonData === 'error') {
|
||||
// console.error('An error occurred while retrieving data from Python');
|
||||
// } else {
|
||||
// // Update HTML elements with data received from Python
|
||||
// document.getElementById('bodem-temperatuur').textContent = pythonData.bodemTemperatuur; // Adjust the property based on your actual Python response
|
||||
// }
|
||||
// });
|
||||
|
||||
// // Listen for updates to HTML data from the main process
|
||||
// ipcRenderer.on('update-html-data', (event, data) => {
|
||||
// // Update the HTML with the received data
|
||||
// document.getElementById('batteryVoltage').innerText = data.batteryVoltage;
|
||||
// // Add similar lines for other data fields
|
||||
// });
|
||||
|
||||
// // Trigger an event to request data update
|
||||
// ipcRenderer.send('request-update-data');
|
||||
|
||||
// // Function to open the modal
|
||||
// function openModal() {
|
||||
// const modal = document.getElementById("myModal");
|
||||
// const button = document.getElementById("modalButton");
|
||||
// const close = document.getElementsByClassName("close")[0];
|
||||
|
||||
// // Check if elements are found before attaching events
|
||||
// if (modal && button && close) {
|
||||
// // Show the modal when the button is clicked
|
||||
// button.onclick = function () {
|
||||
// modal.style.display = "block";
|
||||
// }
|
||||
|
||||
// // Close the modal when the 'close' icon is clicked
|
||||
// close.onclick = function () {
|
||||
// modal.style.display = "none";
|
||||
// }
|
||||
|
||||
// // Close the modal when clicked outside the modal
|
||||
// window.onclick = function (event) {
|
||||
// if (event.target == modal) {
|
||||
// modal.style.display = "none";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Call the function to open the modal
|
||||
// openModal();
|
||||
|
||||
// /**
|
||||
// * --- Function to draw the chart. The important arrays are "data" & "xLabels".
|
||||
// */
|
||||
// function drawLineChart() {
|
||||
// const data = [20, 50, 60, 45, 50, 100, 70, 60, 65, 0, 85, 0];
|
||||
// const xLabels = ["", "", "", "", "", 6, "", "", "", "", "", 12];
|
||||
// const yLabels = ["", 20, "", 40, "", 60, "", 80, "", 100]; /*NIET VERANDEREN!!!*/
|
||||
|
||||
// const canvas = document.getElementById("myCanvas");
|
||||
// const ctx = canvas.getContext("2d");
|
||||
|
||||
// ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// const padding = 35; // Increased padding for Y labels
|
||||
// const graphWidth = canvas.width - padding * 2;
|
||||
// const graphHeight = canvas.height - padding * 2;
|
||||
|
||||
// ctx.beginPath();
|
||||
// ctx.moveTo(padding, padding);
|
||||
// ctx.lineTo(padding, canvas.height - padding);
|
||||
// ctx.lineTo(canvas.width - padding, canvas.height - padding);
|
||||
// ctx.stroke();
|
||||
|
||||
// // Set the color of the line
|
||||
// ctx.strokeStyle = "rgb(143, 188, 143)";
|
||||
|
||||
// const xIncrement = graphWidth / (xLabels.length - 1);
|
||||
// const yIncrement = graphHeight / (yLabels.length - 1);
|
||||
|
||||
// // Plot the data
|
||||
// ctx.beginPath();
|
||||
// ctx.moveTo(padding, canvas.height - padding - (data[0] / 100) * graphHeight);
|
||||
|
||||
// for (let i = 1; i < data.length; i++) {
|
||||
// const xPos = padding + i * xIncrement;
|
||||
// const yPos = canvas.height - padding - (data[i] / 100) * graphHeight;
|
||||
// ctx.lineTo(xPos, yPos);
|
||||
// }
|
||||
// ctx.stroke();
|
||||
|
||||
// // Draw Y labels
|
||||
// ctx.fillStyle = "black";
|
||||
// ctx.textAlign = "right"; // Align text to the right
|
||||
// ctx.textBaseline = "middle"; // Center vertically
|
||||
|
||||
// for (let i = 0; i < yLabels.length; i++) {
|
||||
// if (yLabels[i] !== "") {
|
||||
// const yPos = canvas.height - padding - i * yIncrement;
|
||||
// ctx.fillText(yLabels[i], padding - 10, yPos);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Draw X labels
|
||||
// ctx.textAlign = "center"; // Center horizontally for X labels
|
||||
// for (let i = 0; i < xLabels.length; i++) {
|
||||
// if (xLabels[i] !== "") {
|
||||
// const xPos = padding + i * xIncrement;
|
||||
// ctx.fillText(xLabels[i], xPos, canvas.height - padding + 20);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Call the function to draw the line chart
|
||||
// drawLineChart();
|
||||
|
||||
// // Function to fetch battery data from Flask API
|
||||
// function fetchBatteryData() {
|
||||
// axios.get('http://127.0.0.1:5000')
|
||||
// .then(response => {
|
||||
// const batteryData = response.data;
|
||||
// updateBatteryData(batteryData);
|
||||
// })
|
||||
// .catch(error => {
|
||||
// console.error('Error fetching battery data:', error);
|
||||
// });
|
||||
// }
|
||||
|
||||
// // Function to update HTML content with battery data
|
||||
// function updateBatteryData(batteryData) {
|
||||
// document.getElementById('deviceNumber').innerText = batteryData.device;
|
||||
// document.getElementById('voltage').innerText = batteryData.value;
|
||||
// document.getElementById('time').innerText = batteryData.gateway_receive_time;
|
||||
// document.getElementById('zulu').innerText = batteryData.timestamp;
|
||||
|
||||
// // Voeg andere eigenschappen toe zoals nodig
|
||||
// }
|
||||
|
||||
// // Fetch battery data when the page loads
|
||||
// fetchBatteryData();
|
||||
// // });
|
||||
|
||||
const { ipcRenderer } = require("electron");
|
||||
const axios = require('axios');
|
||||
|
||||
@@ -297,10 +140,11 @@ function fetchBatteryData() {
|
||||
|
||||
// Function to update HTML content with battery data
|
||||
function updateBatteryData(batteryData) {
|
||||
document.getElementById('deviceNumber').innerText = batteryData.device;
|
||||
document.getElementById('voltage').innerText = batteryData.value;
|
||||
document.getElementById('time').innerText = batteryData.gateway_receive_time;
|
||||
document.getElementById('tevredenheid').innerText = batteryData.timestamp;
|
||||
document.getElementById('deviceNumber-322').innerHTML = batteryData.device_id;
|
||||
document.getElementById('voltage').innerHTML = batteryData.label;
|
||||
document.getElementById('time').innerHTML = batteryData.last_seen;
|
||||
document.getElementById('tevredenheid').innerHTML = batteryData.last_battery_voltage;
|
||||
|
||||
// Voeg andere eigenschappen toe zoals nodig
|
||||
console.log(batteryData);
|
||||
}
|
||||
@@ -31,36 +31,6 @@
|
||||
</td>
|
||||
</tr> -->
|
||||
</table>
|
||||
<!-- <div class="formulier">
|
||||
<div id="myModal" class="modal" style="display: none;">
|
||||
<h1 id="plant-id">Plant Toevoegen</h1>
|
||||
<form action="http://localhost:3000/submit-form" method="post"onsubmit="return addplant()">
|
||||
<label for="plantNaam">Naam van de plant</label><br>
|
||||
<input type="text" name="plant_naam" id="plantNaam"><br>
|
||||
|
||||
<label for="plantensoort">Soort van de plant</label><br>
|
||||
<input type="text" name="plantensoort" id="plantensoort"><br>
|
||||
|
||||
<label for="aanwezig">Aanwezig in de kas</label><br>
|
||||
<select name="aanwezig_in_kas">
|
||||
<option value="true">Ja</option>
|
||||
<option value="false">Nee</option>
|
||||
</select><br>
|
||||
|
||||
<label for="ontvangenMeldingen">Meldingen ontvangen</label><br>
|
||||
<select name="ontvangen_meldingen">
|
||||
<option value="true">Ja</option>
|
||||
<option value="false">Nee</option>
|
||||
</select><br>
|
||||
|
||||
<section class="knop-container">
|
||||
<br><button class="annulatie-knop" type="button" onclick="closeOverlay()">Annuleren</button>
|
||||
<input type="submit" value="Submit">
|
||||
</section>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div id="overlay" onclick="closeOverlay()"></div> -->
|
||||
<div id="myModal" class="modal">
|
||||
<span class="close">×</span>
|
||||
<form action="http://localhost:3000/submit-form" method="post" onsubmit="return addplant()">
|
||||
@@ -82,18 +52,15 @@
|
||||
|
||||
</div>
|
||||
<div id="overlay" onclick="closeOverlay"></div>
|
||||
</section>
|
||||
<!-- White space -->
|
||||
<section>
|
||||
</section>
|
||||
<section class="kant-rechts">
|
||||
<section id="sectie-1">
|
||||
<article class="parent-algemeen-overzicht">
|
||||
</section>
|
||||
<section class="kant-rechts">
|
||||
<section id="sectie-1">
|
||||
<!-- <article class="parent-algemeen-overzicht">
|
||||
<article class="algemeen-overzicht">
|
||||
<a href="kas_informatie.html">
|
||||
<table class="table-informatie-kas">
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Dagen tot Oogst</td>
|
||||
<td>Planten aanwezig in kas:</td>
|
||||
<td>12</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
@@ -111,16 +78,59 @@
|
||||
</table>
|
||||
<a/>
|
||||
</article>
|
||||
</article> -->
|
||||
<!-- SENSOR 1 -->
|
||||
<article class="parent-algemeen-overzicht">
|
||||
<article class="algemeen-overzicht">
|
||||
<a href="sensoren.html">
|
||||
<table class="table-informatie-kas">
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Sensor:</td>
|
||||
<td id="deviceNumber-322">12</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Locatie:</td>
|
||||
<td id="voltage">2</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Batterijvoltage:</td>
|
||||
<td id="time">80%</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Dagen resterend:</td>
|
||||
<td id="tevredenheid">1</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a/>
|
||||
</article>
|
||||
</article>
|
||||
<article class="grafiek">
|
||||
<article class="grafiek-innerbox">
|
||||
<h2>Zonlicht</h2>
|
||||
<canvas
|
||||
id="myCanvas" class="canvas-informatie-kas" width="275" height="275"></canvas>
|
||||
<!-- SENSOR 2 -->
|
||||
<article class="parent-algemeen-overzicht">
|
||||
<article class="algemeen-overzicht">
|
||||
<a href="sensoren.html">
|
||||
<table class="table-informatie-kas">
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Sensor:</td>
|
||||
<td>12</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Locatie:</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Batterijvoltage:</td>
|
||||
<td>80%</td>
|
||||
</tr>
|
||||
<tr class="tr-informatie-kas">
|
||||
<td>Dagen resterend:</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a/>
|
||||
</article>
|
||||
</article>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sensoren</title>
|
||||
<link rel="stylesheet" href="../src/css/style.css">
|
||||
<script src="../src/js/main.js" defer></script>
|
||||
<script src="../src/js/planten.class.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<section class="mainContainer">
|
||||
<article>
|
||||
<img src="../src/images/logo.png" class="goodgarden-logo">
|
||||
</article>
|
||||
<section class="mainBorder">
|
||||
<section class="content">
|
||||
<section class="kant-links">
|
||||
<section class="border-sensor">
|
||||
<article id="sensor-1">
|
||||
<table>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>4</td>
|
||||
</tr>
|
||||
</table>
|
||||
</article>
|
||||
</section>
|
||||
<section>
|
||||
<article id="grafiek-1">
|
||||
|
||||
</article>
|
||||
</section>
|
||||
</section>
|
||||
<section>
|
||||
|
||||
</section>
|
||||
<section class="kant-rechts">
|
||||
<article id="sensor-2">
|
||||
|
||||
</article>
|
||||
<article id="grafiek-2">
|
||||
|
||||
</article>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user