def receiver_timeout(ip, result): c2 = Connection("c2", ip, 5005) data = c2.receive(timeout=3) result[0] = data return data
def receiver(ip, result): c2 = Connection("c2", ip, 5005) data = c2.receive() result[0] = data return data
def rover_drive(): print("rover_drive") cmd = str(request.get_data('cmd'), "utf-8") print("cmd: " + cmd) # remove fluff, only command remains if cmd: cmd = cmd.split("=")[1] # decode URI cmd = unquote(cmd) if local: rover_ip = "127.0.0.1" base_ip = rover_ip rover_port = 5020 base_port = 5025 else: rover_ip = "172.16.1.30" base_ip = "172.16.1.20" rover_port = 5030 base_port = rover_port print("cmd: " + cmd) sender = Connection("rover_drive_sender", rover_ip, rover_port) error = str(None) try: sender.send(cmd) except OSError: error = "Network is unreachable" print(error) receiver = Connection("rover_drive_receiver", base_ip, base_port) feedback = str(None) error = str(None) try: feedback = receiver.receive(timeout=2) except OSError: error = "Network error" print(error) print("feedback:", feedback) if not feedback: feedback = "Timeout limit exceeded, no data received" return jsonify(success=True, cmd=cmd, feedback=feedback, error=error)
BASE_IP = ROVER_IP ROVER_PORT = 5005 BASE_PORT = 5010 # for competition elif competition: ROVER_IP = "172.16.1.30" BASE_IP = "172.16.1.20" ROVER_PORT = 5015 BASE_PORT = ROVER_PORT # physicial ip, does not need connection to internet to work # elif dynamic: # ROVER_IP = ni.ifaddresses(ni.interfaces()[1])[AF_INET][0]['addr'] print("ROVER_IP: " + ROVER_IP) receiver = Connection("arm_command_receiver", ROVER_IP, ROVER_PORT) sender = Connection("arm_feedback_sender", BASE_IP, BASE_PORT) print("Rover server listening on port {} \n".format(ROVER_PORT)) print("Ready for incoming drive cmds!\n") print(get_commands_list()) RESPONSE_TIMEOUT = 75 PING_TIMEOUT = 1000 key_list = [ 'w', 's', 'e', 'd', 'r', 'f', 't', 'g', 'y', 'h', 'u', 'j', 'q', 'a', 'p', 'z', 'o', 'l' ]
def sender(ip, msg): c1 = Connection("c1", ip, 5005) c1.send(msg)
#!/usr/bin/env python3 from robot.comms.connection import Connection from time import sleep # This code is meant to run first on the odroid receiver = Connection("receiver", "172.16.1.30", 5005) sender = Connection("sender", "172.16.1.20", 5005) feedback = receiver.receive() print("GOT:", feedback) sleep(1) msg = "was gucci" sender.send(msg) print("SENT:", msg)
BASE_PORT = 5025 # for competition elif competition: ROVER_IP = "172.16.1.30" ROVER_PORT = 5030 BASE_IP = "172.16.1.20" BASE_PORT = ROVER_PORT # attempt to get: physicial ip, which should not need connection to internet to work #elif dynamic: # ROVER_IP = ni.ifaddresses(ni.interfaces()[1])[AF_INET][0]['addr'] print("ROVER_IP: " + ROVER_IP) print("BASE_IP: " + BASE_IP) # Create connection object to send/receive data with base-station receiver = Connection("rover_drive_receiver", ROVER_IP, ROVER_PORT) sender = Connection("rover_feedback_sender", BASE_IP, BASE_PORT) print("Rover server listening on port {} \n".format(ROVER_PORT)) print("Ready for incoming drive cmds!\n") print(get_commands_list()) key_list = [ 'w', 'a', 's', 'd', 'i', 'j', 'l', 'o', 'k', 'm', 'n', 't', 'b', 'q' ] # Arduino sketch considers this value to be the signal for the motors to not move REST = 49.5 # initialize throttle/steering speeds to 0
from robot.comms.connection import Connection PORT_NUMBER = 5005 SIZE = 1024 if len(sys.argv) == 2: PORT_NUMBER = int(sys.argv[1]) elif len(sys.argv) >= 3: print( "too many arguments, one optional argument is the port number, otherwise default to 5000" ) print("example usage: python ServerListener.py <port>") print("Ready for incoming drive cmds!\n") c = Connection("c1", "127.0.0.1", 5005) while True: try: command = c.receive() if command == 'w': print("cmd: w --> action: Forward") #mySocket.sendto(str.encode("Forward"), (clientIP, PORT_NUMBER)) #ser.write(str.encode(command)) elif command == 's': print("cmd: s --> action: Back") #mySocket.sendto(str.encode("Back"), (clientIP, PORT_NUMBER)) #ser.write(str.encode(command)) elif command == 'y': print("\nTerminating connection.")