Robotics StackExchange | Archived questions

Rosbridge: received a message without an op

I'm starting my web page from my laptop. The Web page is on my raspberry PI 4. I'm starting rosbridge_server from my raspberry PI too. I'm using ROS Noetic and Ubuntu 20.04. I'm trying to access raspberry PI from my laptop using my web page where I try to establish ssh connection.

I've received the following error:

Received a message without an op. All messages require 'op' field with value one of: ['call_service', 'advertise', 'unadvertise', 'publish', 'subscribe', 'unsubscribe', etc...]

How to resolve this issue?

Below is my html code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <script type="text/javascript" src="http://static.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
    <script type="text/javascript" type="text/javascript">
      var ros = new ROSLIB.Ros({
        url: "ws://192.168.100.34:8080",
      });
      var mainSocket = new WebSocket("ws://192.168.100.34:8080");
      mainSocket.onopen = function (event) {
        mainSocket.sent(JSON.stringify({ action: "connect", host: "ubiquityrobot", port: 22, username: "ubuntu", password: "ubuntu" }));
        document.getElementById("conn").innerHTML = "Socket open success";
      };
      ros.on("connection", function () {
        document.getElementById("status").innerHTML = "Connected";
      });
      ros.on("error", function (error) {
        document.getElementById("status").innerHTML = "Error";
      });
      ros.on("close", function () {
        document.getElementById("status").innerHTML = "Closed";
      });
    </script>
  </head>
  <body>
    <h1>Simple ROS User Interface</h1>
    <p>Connection status: <span id="status"></span></p>
    <p id="conn"></p>
  </body>
</html>

Asked by tiho_bg on 2022-09-20 15:14:53 UTC

Comments

Your code is not here, please edit your question + the more info about your setup, the better

Asked by ljaniec on 2022-09-20 17:22:29 UTC

First, you are connecting to rosbridge_server at ws://192.168.100.34:8080, and then you are creating a web socket at the same URI. Later you seem to send data to that socket. This is probably the cause of the error. You should not touch the URI for rosbridge_server again. Furthermore, the default port for rosbridge_server is 9090. If I remember correctly, port 8080 was used by tomcat in the past. I would not pick this port number for rosbridge_server.

Asked by ravijoshi on 2022-09-22 06:07:53 UTC

Thank you for reply. Could you please help me to modify my code without touching the URI again? Thank you in advance!

Asked by tiho_bg on 2022-09-22 11:29:02 UTC

I'm trying to access raspberry PI from my laptop using my web page where I try to establish ssh connection.

I am having a hard time understanding the above line.

Could you please help me to modify my code without touching the URI again?

Just remove var mainSocket = new WebSocket( ... ) and get rid of mainSocket.onopen = ... below.

Asked by ravijoshi on 2022-09-22 23:00:30 UTC

Thank you for your reply! I think that if I remove

mainSocket.onopen = function (event) {
    mainSocket.sent(JSON.stringify({ action: "connect", host: "ubiquityrobot", port: 22, username: "ubuntu", password: "ubuntu" }));

I can't establish a connection with my raspberry PI. Normally I open the shell of Ubuntu and write ssh ubuntu@ubiquityrobot.local. Then I have to write the password and finally I can access my raspberry PI. I would like to make the same procedure with my webpage but without using the shell. Therefore I think that I need this function mainSocket.onopen = ...

Asked by tiho_bg on 2022-09-22 23:44:55 UTC

I understand.

  1. Do you really need ssh access to the Raspberry PI using a WebSocket? Please think about it!
  2. You are using the same port, i.e., 8080, for two purposes, which is incorrect. By default, rosbridge_server and ssh runs on 9090 and 22 port, respectively. Please check and correct those port numbers.
  3. Lastly, it seems difficult to make an ssh connection using a WebSocket. I do not understand why someone would pick a WebSocket to connect to ssh. Please read a similar question asked in StackOverflow for further details.

Asked by ravijoshi on 2022-09-23 00:03:02 UTC

These comments can be helpful for the future readers, please add them as an answer + move the discussion with @tiho_bg here

Asked by ljaniec on 2022-09-23 07:38:53 UTC

Answers

First, you are connecting to rosbridge_server at ws://192.168.100.34:8080, and then you are creating a WebSocket at the same URI. Later you seem to send data to that socket. This is probably the cause of the error. You should not touch the URI for rosbridge_server again. Furthermore, the default port for rosbridge_server is 9090. If I remember correctly, port 8080 was used by tomcat in the past. So, I would not pick this port number for rosbridge_server.

Normally I open the shell of Ubuntu and write ssh ubuntu@ubiquityrobot.local. Then I have to write the password and finally I can access my raspberry PI. I would like to make the same procedure with my webpage but without using the shell. Therefore I think that I need this function mainSocket.onopen = ...

I understand. Based on the above information, I need to make the following points:

  1. Do you really need ssh access to the Raspberry PI using a WebSocket? Please think about it!
  2. You are using the same port, i.e., 8080, for two purposes, which is incorrect. By default, rosbridge_server and ssh runs on 9090 and 22 port, respectively. Please check and correct those port numbers.
  3. Lastly, it seems difficult to make an ssh connection using a WebSocket. Moreover, I do not understand why someone would pick a WebSocket to connect to an ssh server. Please read a similar question asked in StackOverflow for further details.

Asked by ravijoshi on 2022-09-23 11:08:02 UTC

Comments