update
This commit is contained in:
@@ -165,7 +165,7 @@ def blink_led(pin, blink_count, delay=1):
|
||||
GPIO.output(pin, GPIO.LOW) # Ensure LED is off
|
||||
print(f"LED on GPIO {pin} turned OFF (cleanup avoided)")
|
||||
|
||||
#get data from config
|
||||
#get data from config (from JSON file)
|
||||
def load_config(config_file):
|
||||
try:
|
||||
with open(config_file, 'r') as file:
|
||||
@@ -175,6 +175,41 @@ def load_config(config_file):
|
||||
print(f"Error loading config file: {e}")
|
||||
return {}
|
||||
|
||||
#get config data from SQLite table
|
||||
def load_config_sqlite():
|
||||
"""
|
||||
Load configuration data from SQLite config table
|
||||
|
||||
Returns:
|
||||
dict: Configuration data with proper type conversion
|
||||
"""
|
||||
try:
|
||||
|
||||
# Query the config table
|
||||
cursor.execute("SELECT key, value, type FROM config")
|
||||
rows = cursor.fetchall()
|
||||
|
||||
# Create config dictionary
|
||||
config_data = {}
|
||||
for key, value, type_name in rows:
|
||||
# Convert value based on its type
|
||||
if type_name == 'bool':
|
||||
config_data[key] = value == '1' or value == 'true'
|
||||
elif type_name == 'int':
|
||||
config_data[key] = int(value)
|
||||
elif type_name == 'float':
|
||||
config_data[key] = float(value)
|
||||
else:
|
||||
config_data[key] = value
|
||||
|
||||
return config_data
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error loading config from SQLite: {e}")
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
#Fonction pour mettre à jour le JSON de configuration
|
||||
def update_json_key(file_path, key, value):
|
||||
"""
|
||||
@@ -207,7 +242,7 @@ def update_json_key(file_path, key, value):
|
||||
# Define the config file path
|
||||
config_file = '/var/www/nebuleair_pro_4g/config.json'
|
||||
|
||||
# Load the configuration data
|
||||
# Load the configuration data (JSON way)
|
||||
config = load_config(config_file)
|
||||
device_latitude_raw = config.get('latitude_raw', 0)
|
||||
device_longitude_raw = config.get('longitude_raw', 0)
|
||||
@@ -224,6 +259,10 @@ npm_5channel = config.get('NextPM_5channels', False) #5 canaux du
|
||||
modem_version=config.get('modem_version', "")
|
||||
modem_config_mode = config.get('modem_config_mode', False) #modem 4G en mode configuration
|
||||
|
||||
#Load config new way
|
||||
config = load_config_sqlite()
|
||||
|
||||
|
||||
#update device id in the payload json
|
||||
payload_json["nebuleairid"] = device_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user