def run(): """ TODO """ global THREAD log(LOG_DEBUG, 'Starting timer thread') if not THREAD: THREAD = Tool.start_thread(thread_timer_loop)
def web_cmd(httpClient, httpResponse): """ Shows a form to enter a command and display the result for testing the ezPiC-commands """ cmd = '' err = '' ret = '' formParams = None if httpClient.GetRequestMethod() == 'POST': formParams = httpClient.ReadRequestPostedFormData() else: # GET formParams = httpClient.GetRequestQueryParams() if formParams and 'cmd' in formParams: cmd = formParams.get('cmd') #cmd = html.escape(cmd) if cmd: err, ret = Web.command(httpResponse, cmd, useCLI=True, source=httpClient._addr) ret = Tool.json_str(ret) #ret = html.escape(ret) log(LOG_DEBUG, 'Web command: {}', cmd) vars = {} vars['menu'] = 'tools' vars['cmd'] = cmd vars['err'] = err vars['ret'] = ret return httpResponse.WriteResponsePyHTMLFile('web/www/cmd.html', vars=vars)
def thread_cli_loop(*argv): global _PROMPT time.sleep(0.75) print(Tool.LOGO) while RUN: cmd_str = input(_PROMPT) cmd_str = cmd_str.strip() if not cmd_str: continue err, ret = Cmd.excecute(cmd_str, 'CLI') if cmd_str.startswith('{'): # cmd in JSON -> answer in JSON print(Tool.json_str([err, ret])) elif err is not None and err != 0: print('ERROR {}: {}'.format(err, ret)) elif ret: print(Tool.json_str(ret)) print()
def init(port): """ Prepare module vars and load plugins """ global MWS, PORT PORT = port www = Tool.load_plugins(PLUGINDIR, 'web') MWS = MicroWebSrv(port=port, webPath='web/www') # TCP port 80 and files in /flash/www
def init(): """ Prepare module vars and load plugins """ global RULEPLUGINS plugins = Tool.load_plugins(PLUGINDIR, 'ru') for plugin in plugins: try: RULEPLUGINS[plugin.RUPID] = plugin except: pass
def init(): """ Prepare module vars and load plugins """ global GATEWAYPLUGINS plugins = Tool.load_plugins(PLUGINDIR, 'gw') for plugin in plugins: try: GATEWAYPLUGINS[plugin.GWPID] = plugin except: pass
def init(): """ Prepare module vars and load plugins """ global _GADGETPLUGINS plugins = Tool.load_plugins(_PLUGINDIR, 'gd') for plugin in plugins: try: _GADGETPLUGINS[plugin.EZPID] = plugin except: pass
def process_cli(): time.sleep(0.75) print(Tool.LOGO) while RUN: cmd_str = input(':-> ') if not cmd_str: continue err, ret = Cmd.excecute(cmd_str, 'CLI') #print (err) #JK DEBUG #print (ret) #JK DEBUG if err is not None and err != 0: print('ERROR {}: {}'.format(err, ret)) elif ret: print(Tool.json_str(ret)) print()
def init(): """ Prepare module vars and load plugins """ global _MACHINEPLUGINS plugins = Tool.load_plugins(_PLUGINDIR, 'ma') for plugin in plugins: try: _MACHINEPLUGINS[plugin.MAPID] = plugin except: pass err = None ret = None for mapid, module in _MACHINEPLUGINS.items(): try: machine = module.PluginMachine(module) _MACHINES.append(machine) machine.init() except Exception as e: err = -1 ret = str(e)
""" ezPiC - IoT-Device """ # Meta __version__ = '0.0.1' __version_info__ = (0, 0, 1) __author__ = 'Jochen Krapf et al.' __license__ = "GNU General Public License (GPL) Version 3" #import test from com.Globals import * # get program configuration import com.Tool as Tool Tool.load_cnf() try: # CPython only import com.Args except Exception as e: pass LOG_LEVEL = CNF['logLevel'] # load module dependent on configuration if CNF['useWeb']: try: import web.Web as Web except Exception as e: log(LOG_ERROR, str(e)) CNF['useWeb'] = False if CNF['useIoT']: try:
def run(threaded=True): if threaded: Tool.start_thread(thread_cli_loop, ()) else: thread_cli_loop() # this call never comes back .. normally
def run(): Tool.start_thread(process_cli, ())
def init(): """ Prepare module vars and load plugins """ global COMMANDS plugins = Tool.load_plugins(PLUGINDIR, 'cmd')