request = serialize_STATE_Request() sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) sock.connect((BD_ADDR, BD_PORT)) print('connected to ' + BD_ADDR) def handler(altitude, variometer, positionX, positionY, heading, velocityForward, velocityRightward): print(altitude, variometer, positionX, positionY, heading, velocityForward, velocityRightward) sock.send(request) parser.set_STATE_Handler(handler) sock.send(request) while True: try: parser.parse(sock.recv(1)) except KeyboardInterrupt: sock.close() break