Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def timeout_handler(command, args):
    global banned

    if len(command) > 1:
        user = command[1]
        if is_authed(args['name']): # Moderator
            banned.append(user)
            schedule.single_task(5, untimeout_user, user)
            log.info("%s added %s to timeout list", args['name'], user)
            tts.mute_user_tts(user)            
Exemplo n.º 3
0
def timeout_handler(command, args):
    global banned

    if len(command) > 1:
        user = command[1]
        if is_authed(args['sender']):  # Moderator
            banned.append(user)
            schedule.single_task(300, untimeout_user, user)
            log.info("%s added %s to timeout list", args['sender'], user)
            robot_util.sendChatMessage("{} timed out".format(user))
            tts.mute_user_tts(user)
Exemplo n.º 4
0
def move(args):
    global maxSpeedEnabled

    command = args['button']['command']

    if command == 'MAXSPEED':
        handleMaxSpeedCommand()
        maxSpeedEnabled = True
        log.debug("max speed")
        schedule.single_task(120, SpeedNormal)
        return

    if maxSpeedEnabled:
        log.debug("AT MAX.....................")
        log.debug("maxSpeedEnabled : %s", maxSpeedEnabled)
        moveMDD10(command, 100)
    else:
        log.debug("NORMAL.................")
        log.debug("maxSpeedEnabled : %s", maxSpeedEnabled)
        moveMDD10(command, int(float(drivingSpeedActuallyUsed) / 2.55))
Exemplo n.º 5
0
def handleLoudCommand(seconds):
    os.system("amixer -c 2 cset numid=3 %d%%" % 100)
    schedule.single_task(seconds, changeVolumeNormal)
Exemplo n.º 6
0

def SpeedNormal():
    maxSpeedEnabled = False
    print("normal speed")

#MDD10 speed and movement controls
def move(args):
    global maxSpeedEnabled
	                
	  command = args['command']
    if command == 'MAXSPEED':
        handleMaxSpeedCommand()
        maxSpeedEnabled = True
        print("max speed")
        schedule.single_task(120, SpeedNormal)        
        return
        
    if maxSpeedEnabled:
        print("AT MAX.....................")
        print(maxSpeedEnabled)
        moveMDD10(command, 100)
    else:
        print("NORMAL.................")
        print(maxSpeedEnabled)
        moveMDD10(command, int(float(drivingSpeedActuallyUsed) / 2.55))                


def moveMDD10(command, speedPercent):
    if command == 'F':
        GPIO.output(DIG1, GPIO.LOW)