kopia lustrzana https://github.com/mate-dev/mmrelaynode
Create flag file, remove sleep 4 c-wrapper
rodzic
7d049d6712
commit
af4f6d19c0
|
@ -2,6 +2,8 @@ import os
|
|||
import subprocess
|
||||
import time
|
||||
|
||||
flag_file = '/home/mesh/app/.commands_executed'
|
||||
|
||||
def log_to_file(message):
|
||||
with open('/home/mesh/app/command_output.txt', 'a') as f:
|
||||
f.write(message + "\n")
|
||||
|
@ -13,19 +15,25 @@ def execute_meshtastic_command(options):
|
|||
result = subprocess.run(command, capture_output=True, text=True)
|
||||
log_to_file("Standard Output:\n" + result.stdout)
|
||||
log_to_file("Standard Error:\n" + result.stderr)
|
||||
time.sleep(1) # Pause for 1 second between commands
|
||||
#time.sleep(1) # Pause for 1 second between commands
|
||||
|
||||
# Print all environment variables at the start
|
||||
log_to_file("All environment variables:\n" + str(os.environ))
|
||||
if os.path.exists(flag_file):
|
||||
log_to_file("Commands have already been executed previously. Skipping.")
|
||||
else:
|
||||
# Print all environment variables at the start
|
||||
log_to_file("All environment variables:\n" + str(os.environ))
|
||||
|
||||
# Loop through environment variables in sequence
|
||||
index = 1
|
||||
while True:
|
||||
command = os.environ.get(f'MESHTASTIC_COMMAND_{index}')
|
||||
if command:
|
||||
log_to_file(f"Found command variable: MESHTASTIC_COMMAND_{index} with value: {command}")
|
||||
execute_meshtastic_command(command)
|
||||
index += 1
|
||||
else:
|
||||
log_to_file(f"No more MESHTASTIC_COMMAND variables found, ending at index {index-1}.")
|
||||
break
|
||||
# Loop through environment variables in sequence
|
||||
index = 1
|
||||
while True:
|
||||
command = os.environ.get(f'MESHTASTIC_COMMAND_{index}')
|
||||
if command:
|
||||
log_to_file(f"Found command variable: MESHTASTIC_COMMAND_{index} with value: {command}")
|
||||
execute_meshtastic_command(command)
|
||||
index += 1
|
||||
else:
|
||||
log_to_file(f"No more MESHTASTIC_COMMAND variables found, ending at index {index-1}.")
|
||||
# Create the flag file to indicate that all commands have been executed.
|
||||
with open(flag_file, 'w') as f:
|
||||
f.write("Commands executed on: " + time.ctime())
|
||||
break
|
||||
|
|
Ładowanie…
Reference in New Issue