diff --git a/api/views/index.ejs b/api/views/index.ejs index 3a30942b..8849a74d 100644 --- a/api/views/index.ejs +++ b/api/views/index.ejs @@ -158,7 +158,7 @@ xhr.onload = (e) => { console.log("response image received"); const img = e.response; - document.getElementById("picture").src = "data:image/png;base64," + img; + document.getElementById("picture").src = img; } console.log("sending picture request") xhr.send(); diff --git a/src/api_communication/api_communication/api_listener.py b/src/api_communication/api_communication/api_listener.py index 6dd22db3..79ec0681 100644 --- a/src/api_communication/api_communication/api_listener.py +++ b/src/api_communication/api_communication/api_listener.py @@ -124,20 +124,17 @@ class ApiListener(Node): self.get_logger().info('Calling take picture service') future = self.take_picture_client.call_async(self.take_picture_request) future.add_done_callback(partial(self.image_request_callback)) - - + def image_request_callback(self, future): try: result_filename = future.result() + result_filename = result_filename.replace("/home/ubuntu/ros2_ws/api/public", "") self.get_logger().info("Received result filename: " + result_filename) - with open(result_filename, 'rb') as f: - self.get_logger().info('Reading image') - image_data = f.read() - self.message_queue.append(json.dumps( - {'type': ResponseMessage.IMAGE.name, 'image': image_data})) + self.message_queue.append(json.dumps( + {'type': ResponseMessage.IMAGE.name, 'image': result_filename})) except Exception as e: - self.get_logger().error('Something went wrong while sending a take picture request and waiting for the response: %r' % (e)) - + self.get_logger().error( + 'Something went wrong while sending a take picture request and waiting for the response: %r' % (e)) def send_available_commands(self): print('Sending available commands') @@ -234,10 +231,12 @@ class ApiListener(Node): self.get_logger().info('Emergency stop command received') # emergency stop: set to attitude mode and stop, also disarm else: - self.get_logger().error('Received unknown command ' + str(message_json['command']) ) + self.get_logger().error('Received unknown command ' + + str(message_json['command'])) self.send_available_commands() except TypeError: - self.get_logger().error('Received unknown type: ' +str(type(message)) + " " + str(message)) + self.get_logger().error('Received unknown type: ' + + str(type(message)) + " " + str(message)) self.send_available_commands() except json.JSONDecodeError: self.get_logger().error('Received invalid JSON') diff --git a/src/camera/camera/camera_controller.py b/src/camera/camera/camera_controller.py index a70b37de..6f1fde70 100644 --- a/src/camera/camera/camera_controller.py +++ b/src/camera/camera/camera_controller.py @@ -21,7 +21,7 @@ class CameraController(Node): if (request.input_name == "default"): self.get_logger().info("Taking picture with default filename") now = datetime.now().strftime("droneimage_%Y-%m-%d_%H-%M-%S") - imagename = "/home/ubuntu/drone_img/" + now + ".jpg" + imagename = "/home/ubuntu/ros2_ws/api/public/img/" + now + ".jpg" response.filename = imagename else: response.filename = request.input_name