def obj(): ili = ILI9341_API(dc=get_config('PIN_ILI9341_DC', 2), rst=get_config('PIN_ILI9341_RST', None)) device = (get_config('DEV_ESP32_SPI_BUS', 1), get_config('DEV_ESP32_SPI_CS', 1)) ili.open(device) ili.start() yield ili ili.close()
def system_debug(): if 'jupyter-notebook' not in system_exec('ps ux | grep jupyter')[1]: logger.debug('Trying to start Jupyter Notebook process...') from embci.utils import get_config, get_host_addr WEBUI_HOST = get_host_addr(get_config('WEBUI_HOST', '0.0.0.0')) HOST = get_config('NOTEBOOK_HOST', WEBUI_HOST) PORT = get_config('NOTEBOOK_PORT', 1106, type=int) code, ret = system_exec('jupyter-notebook --help') if code: return 'Cannot start Jupyter Notebook server: %s' % ret cmd = ('jupyter-notebook --no-browser --allow-root -y ' '--ip=%s --port=%d' % (HOST, PORT)) logger.debug('Executing command: `%s`' % cmd) system_exec('/bin/sh -c "%s" &' % cmd, False) time.sleep(3) url = 'http://{}:{}'.format(HOST, PORT) else: code, ret = system_exec('jupyter-notebook list') servers = ret.split('\n')[1:] if code or not servers: return 'No valid server info: `%s`' % ret logger.debug('Current alive server: ' + servers[0]) url = servers[0].split(' ')[0] bottle.redirect(url)
def test_get_config(): assert get_config('WEBUI_PORT', type=float) == 80
self._measure_impedance = boolean # ============================================================================= # ESP32 Communication # # IMPORTANT! # If you are not using this liberary inside EmBCI (On EmBCI-Board), this # section is useless and can be deleted safely. # import serial from six import string_types from embci.utils import get_config esp_serial = serial.Serial( baudrate=get_config('BAUD_ESP32', 115200, type=int) ) esp_serial.port = get_config('DEV_ESP32_UART_PORT', '/dev/ttyS2') def send_message_esp32(cmd_or_args): if not cmd_or_args: return '' if isinstance(cmd_or_args, (list, tuple)): cmd = ' '.join([str(arg) for arg in cmd_or_args]) elif not isinstance(cmd_or_args, string_types): cmd = str(cmd_or_args) else: cmd = cmd_or_args if not esp_serial.isOpen(): try:
cooperatively to construct a command-recieve-and-execute server. Comparing to JSON-RPC, ZMQ also support local or remote TCP request (and many more mechanisms like PGM, IPC and In-proc). Argparse can provide a neat help output and error handle interface, as well as support to subcommands. ZMQ is preferred if you want to interact with this task from C++/Python/Java or even command line. JSON-RPC is suitable for web users in case someone want to control the task from webpage using JavaScript. ''' from embci.utils import config_logger logger = config_logger(__name__) del config_logger from embci.utils import get_config STM_HOST = get_config('STREAMING_HOST', '0.0.0.0') CMD_PORT = get_config('STREAMING_CMD_PORT', 9997, type=int) RPC_PORT = get_config('STREAMING_RPC_PORT', 9996, type=int) del get_config CMD_ADDR = 'tcp://{}:{}'.format(STM_HOST, CMD_PORT) RPC_ADDR = 'http://{}:{}'.format(STM_HOST, RPC_PORT) HELP = ''' ZMQ interface is listening on `{}`, from wich users can set parameters of data stream at runtime. RPC server binds to `{}`. '''.format(CMD_ADDR, RPC_ADDR) CMD_USAGE = ''' ZMQ Example -----------