Skip to content

Instantly share code, notes, and snippets.

@DanEdens
Last active July 7, 2023 17:26
Show Gist options
  • Save DanEdens/1e2a7524d171ffa4f8cca1fb18a29822 to your computer and use it in GitHub Desktop.
Save DanEdens/1e2a7524d171ffa4f8cca1fb18a29822 to your computer and use it in GitHub Desktop.
simple-mqtt-server-agent
import os
import subprocess
import sys
# Define file directories
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
BIN_DIR = os.path.join(ROOT_DIR)
# Add directories to system path
sys.path.insert(0, ROOT_DIR)
sys.path.insert(1, BIN_DIR)
varlist = [
'HzAxis',
'VAxis',
'point_name',
'search_windowX',
'search_windowY',
]
commands = [
'aim',
'shoot',
'learnmode_on',
'learnmode_off',
'TCA_on',
'TCA_off',
'PositionFlag',
'ReadPoint',
'FileList'
]
def run_script(filename):
_path = os.path.join(BIN_DIR, f'{filename}.cmd')
if filename in commands:
try:
subprocess.Popen(r'%s' % _path, shell=True)
except OSError as e:
print(f"Error: {e}")
def main(msg):
key = msg.split('/')
value = key[2].split(' ')
if value[0] in commands:
try:
run_script(value[0])
print(f"Running Command {value[0]}: {value[1]}")
except:
print(f"Error: could not run command {value[0]}")
if value[0] in varlist:
print(f"{value[0]} set to: {value[1]}")
if __name__ == "__main__":
if len(sys.argv) > 1:
main(sys.argv[1])
else:
pass
mosquitto_sub -h %awsip% -p %awsport% -v -t "CHANGE_TO_YOUR_PREFRENCE/device_name/python" | xargs -o -r -I {} python __main__.py {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment