def setupSocketIO(robot_config): global controlHostPort global chatHostPort global infoServer global robot_id global no_chat_server global secure_cert global debug_messages debug_messages = robot_config.getboolean('misc', 'debug_messages') robot_id = robot_config.getint('robot', 'robot_id') infoServer = robot_config.get('misc', 'info_server') no_chat_server = robot_config.getboolean('misc', 'no_chat_server') secure_cert = robot_config.getboolean('misc', 'secure_cert') controlHostPort = getControlHostPort() chatHostPort = getChatHostPort() schedule.repeat_task(60, identifyRobot_task) if debug_messages: print("using socket io to connect to control", controlHostPort) print("using socket io to connect to chat", chatHostPort) if robot_config.getboolean('misc', 'check_internet'): #schedule a task to check internet status schedule.task(robot_config.getint('misc', 'check_freq'), internetStatus_task)
def setupWebSocket(robot_config, onHandleMessage): global robot_key global bootMessage global webSocket global server global version global ipAddr global ood global channel robot_key = robot_config.get('robot', 'robot_key') server = robot_config.get('misc', 'server') if robot_config.has_option('misc', 'api_version'): version = robot_config.get('misc', 'api_version') else: version = 'dev' if robot_config.has_option('robot', 'channel'): channel = robot_config.get('robot', 'channel') bootMessages = robot_config.get('tts', 'boot_message') bootMessageList = bootMessages.split(',') bootMessage = random.choice(bootMessageList) if robot_config.has_option('tts', 'announce_ip'): ipAddr = robot_config.getboolean('tts', 'announce_ip') if ipAddr: addr = os.popen("ip -4 addr show wlan0 | grep -oP \'(?<=inet\\s)\\d+(\\.\\d+){3}\'").read().rstrip() log.info('IPv4 Addr : {}'.format(addr)) bootMessage = bootMessage + ". My IP address is {}".format(addr) if robot_config.has_option('tts', 'announce_out_of_date'): ood = robot_config.getboolean('tts', 'announce_out_of_date') if ood: isOod = os.popen('git fetch && git status').read().rstrip() if "behind" in isOod: commits = re.search(r'\d+(\scommits|\scommit)', isOod) log.warning('Git repo is out of date. Run "git pull" to update.') bootMessage = bootMessage + ". Git repo is behind by {}.".format(commits.group(0)) # log.info("using socket io to connect to control %s", controlHostPort) log.info("configuring web socket wss://%s/" % server) webSocket = websocket.WebSocketApp("wss://%s/" % server, on_message=onHandleMessage, on_error=onHandleWebSocketError, on_open=onHandleWebSocketOpen, on_close=onHandleWebSocketClose) log.info("staring websocket listen process") startListenForWebSocket() schedule.single_task(5, checkWebSocket) if robot_config.getboolean('misc', 'check_internet'): #schedule a task to check internet status schedule.task(robot_config.getint('misc', 'check_freq'), internetStatus_task)
def setupSocketIO(robot_config): global infoServer global apiServer global controlHostPort global chatHostPort global videoPort global audioPort global robot_id global camera_id global no_chat_server global secure_cert global messengerEnable global messengerHost global messengerPort global messengerName global messengerUsername global messengerPassword global bootMessage robot_id = robot_config.get('robot', 'robot_id') camera_id = robot_config.getint('robot', 'camera_id') infoServer = robot_config.get('misc', 'info_server') apiServer = robot_config.get('misc', 'api_server') no_chat_server = robot_config.getboolean('misc', 'no_chat_server') secure_cert = robot_config.getboolean('misc', 'secure_cert') messengerEnable = robot_config.get('messenger', 'enable') messengerHost = robot_config.get('messenger', 'host') messengerPort = robot_config.getint('messenger', 'port') messengerUsername = robot_config.get('messenger', 'username') messengerPassword = robot_config.get('messenger', 'password') messengerName = robot_config.get('messenger', 'robot_name') bootMessages = robot_config.get('tts', 'boot_message') bootMessageList = bootMessages.split(',') bootMessage = random.choice(bootMessageList) controlHostPort = getControlHostPort() chatHostPort = getChatHostPort() videoPort = getVideoPort() audioPort = getAudioPort() schedule.repeat_task(60, identifyRobot_task) log.info("using socket io to connect to control %s", controlHostPort) log.info("using socket io to connect to chat %s", chatHostPort) log.info("using video port %d" % videoPort) log.info("using audio port %d" % audioPort) if robot_config.getboolean('misc', 'check_internet'): #schedule a task to check internet status schedule.task(robot_config.getint('misc', 'check_freq'), internetStatus_task)
def start(): if not no_camera: watchdog.start("FFmpegCameraProcess", startVideoCapture) schedule.task(90, networking.sendOnlineState, True) atexit.register(networking.sendOnlineState, False) if not no_mic: if not mic_off: # watchdog.start("FFmpegAudioProcess", startAudioCapture) watchdog.start("FFmpegAudioProcess", startAudioCapture)