Final versie!

This commit is contained in:
Atilla
2024-04-10 13:59:00 +02:00
parent 6df64fd3a0
commit 7aea48ad67
22 changed files with 702 additions and 688 deletions

View File

@@ -1,113 +0,0 @@
{ "battery_voltage_events": [
{
"timestamp": 1707825721,
"gateway_receive_time": "2024-02-13T12:02:01Z",
"device": 256,
"value": 4.098901271820068
},
{
"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
}
],
"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
}
],
"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
}
],
"soil_electric_conductivity_events": [
{
"timestamp": 1707851215,
"gateway_receive_time": "2024-02-13T19:06:55Z",
"device": 322,
"value": 0.0
}
],
"soil_relative_permittivity_events": [
{
"timestamp": 1707851215,
"gateway_receive_time": "2024-02-13T19:06:55Z",
"device": 322,
"value": 1.52
}
],
"soil_temperature_events": [
{
"timestamp": 1707851215,
"gateway_receive_time": "2024-02-13T19:06:55Z",
"device": 322,
"value": 12.06
}
]
}

View File

@@ -2,6 +2,7 @@ import mysql.connector
import requests
from datetime import datetime, timezone, timedelta
import time
import sys
# Function to make a connection to the database
def database_connect():
@@ -40,10 +41,10 @@ def create_data(url, access_token, repeat_count=5):
value = record.get('value', '')
print(f"\nInserted data: Timestamp: {timestamp}, Device: {device}, Battery Voltage: {value}V\n")
if float(value) < 3.0:
if float(value) < 5.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:
elif float(value) > 6.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")

View File

@@ -3,7 +3,6 @@ import json
import mysql.connector #** TYPE IN TERMINAL: "pip install mysql-connector-python"
from mysql.connector import Error
# Voeg de data uit het formulier toe aan de database
def insert_plant_name(plant_naam, plantensoort, plant_geteelt):

View File

@@ -1,26 +1,14 @@
[
{
"id": 3,
"id": 1,
"plant_naam": "Tomatenplant",
"plantensoort": "Groente",
"plant_geteelt": 1
},
{
"id": 4,
"id": 15,
"plant_naam": "Sla",
"plantensoort": "Groente",
"plant_geteelt": 1
},
{
"id": 5,
"plant_naam": "Peterselie",
"plantensoort": "Kruiden",
"plant_geteelt": 1
},
{
"id": 6,
"plant_naam": "Aardbei",
"plantensoort": "Fruit",
"plant_geteelt": 1
}
]

View File

@@ -1,218 +0,0 @@
import requests
import time
from db_connect import database_connect
##########################* DEVICES #######################
def load_data(data):
mydb = database_connect()
if mydb.is_connected():
mycursor = mydb.cursor()
insert_query = """
INSERT INTO goodgarden.devices (serial_number, name, label, last_seen, last_battery_voltage)
VALUES (%s, %s, %s, %s, %s )
"""
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', '')
print(f"Inserting data: serial_number={serial_number}, name={name}, label={label}, last_seen={last_seen}, last_battery_voltage={last_battery_voltage}")
mycursor.execute(insert_query, (serial_number, name, label, last_seen, last_battery_voltage))
mydb.commit()
mycursor.close()
mydb.close()
print("Data inserted into the database.")
############################### EINDE ########################
# #
# #
# #
# #
##########################* PAR_EVENTS #######################
def load_data(data):
mydb = database_connect()
if mydb.is_connected():
mycursor = mydb.cursor()
# Here you need to adjust the correct column names and data formats based on the API response
insert_query = """
INSERT INTO goodgarden.par_events (timestamp, gateway_receive_time, device, value)
VALUES (%s, %s, %s, %s)
"""
for record in data['results']:
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))
# Commit the changes
mydb.commit()
# Close cursor and connection
mycursor.close()
mydb.close()
print("Data inserted into the database.")
############################### EINDE ########################
# #
# #
# #
# #
##########################* RELATIVE_HUMIDITY_EVENTS #######################
def load_data(data):
mydb = database_connect()
if mydb.is_connected():
mycursor = mydb.cursor()
# Here you need to adjust the correct column names and data formats based on the API response
insert_query = """
INSERT INTO goodgarden.relative_humidity_events (timestamp, gateway_receive_time, device, value)
VALUES (%s, %s, %s, %s)
"""
for record in data['results']:
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))
# Commit the changes
mydb.commit()
# Close cursor and connection
mycursor.close()
mydb.close()
print("Data inserted into the database.")
############################### EINDE ########################
# #
# #
# #
# #
##########################* SOIL_ELECTRIC_CONDUCTIVITY_EVENTS #######################
def load_data(data):
mydb = database_connect()
if mydb.is_connected():
mycursor = mydb.cursor()
# Here you need to adjust the correct column names and data formats based on the API response
insert_query = """
INSERT INTO goodgarden.soil_electric_conductivity_events (timestamp, gateway_receive_time, device, value)
VALUES (%s, %s, %s, %s)
"""
for record in data['results']:
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))
# Commit the changes
mydb.commit()
# Close cursor and connection
mycursor.close()
mydb.close()
print("Data inserted into the database.")
############################### EINDE ########################
# #
# #
# #
# #
##########################* SOIL_TEMPERATURE_EVENTS #######################
def load_data(data):
mydb = database_connect()
if mydb.is_connected():
mycursor = mydb.cursor()
# Here you need to adjust the correct column names and data formats based on the API response
insert_query = """
INSERT INTO goodgarden.soil_temperature_events (timestamp, gateway_receive_time, device, value)
VALUES (%s, %s, %s, %s)
"""
for record in data['results']:
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))
# Commit the changes
mydb.commit()
# Close cursor and connection
mycursor.close()
mydb.close()
print("Data inserted into the database.")
############################### EINDE ########################
# #
# #
# #
# #
##########################* SOIL_TEMPERATURE_EVENTS #######################
def load_data(data):
mydb = database_connect()
if mydb.is_connected():
mycursor = mydb.cursor()
# Here you need to adjust the correct column names and data formats based on the API response
insert_query = """
INSERT INTO goodgarden.soil_temperature_events (timestamp, gateway_receive_time, device, value)
VALUES (%s, %s, %s, %s)
"""
for record in data['results']:
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))
# Commit the changes
mydb.commit()
# Close cursor and connection
mycursor.close()
mydb.close()
print("Data inserted into the database.")