Trying to get access to Leap motion Web Socket

Posted on
  • I'm trying to do a project with the Leap Motion and an ESP8266 E12. I am very new to using the ESP8266. I am trying to connect to the Leap Motion Websocket: located at http://127.0.0.1:6437 but am not able to get a response from the ESP. Ultimately I want to get the hand data from the websocket to control some servos.

    here is my code:
    var WIFI_NAME = "***";
    var WIFI_OPTIONS = { password : "
    **" };

    var wifi = require("Wifi");
    wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
    if (err) {

    console.log("Connection error: "+err);
    return;
    

    }
    console.log("Connected!");
    });

    var host = "127.0.0.1";
    var WebSocket = require("ws");

    var ws = new WebSocket(host,{
      path: '/',
      port: 6473,
      keepAlive: 60
    });
    

    ws.on('open', function() {
    console.log("Connected to server");
    });

    ws.on('message', function(msg) {
    console.log("MSG: " + msg);
    ws.on('error', function(){
    console.log("error");});
    });

    On my console I receive a Connected message but nothing else after that, not even an error.
    I've also attached a link for more information about the Leap Motion WebSocket:
    https://developer-archive.leapmotion.com­/documentation/javascript/supplements/Le­ap_JSON.html

    Any help would be appreciated on how to get this working.

    Thanks

  • 127.0.0.1 is the local machine on each device. You need the IP address of the computer running the leap motion server. Usually that's 192.168.x.y on most LAN's.

  • 127.0.0.1 is the loopback address - is the websocket server running on the same device that is trying to connect to it? That is the only time 127.0.0.1 will work.

  • I just tried switching out the host: 127.0.0.1 to host: IP address of my computer, and left everything else the same but the same thing happened where I didn't get any feedback
    Should I leave the port number the same as well?

  • No I am trying to use the ESP8266 to access the websocket while the Leap Motion is connected to my computer.

    I switched out the 127.0.0.1 address to the Ip address of my own computer and the same port, but no change :(. Do you have any other advice on other things I can try?

  • You do need the port number.

    Can you check that the leap motion server is accessible for other devices? It's possible that default configuration or firewall rule block the communication.

  • I tried doing an echo test through websocket.org and received an error saying undefined. So, it looks like the server isn't accessible to other devices. Is there a way that I can use my own computer to send information from the leap server to an external server that is accessible to the ESP? I don't have much experience with web development and javascript in general. Or are there any other workarounds that you can recommend?

  • I don't have experience with leap motion, maybe there is a configuration option, or guide on how to make it accessible.

  • The leap socket is listening only on the loopback port, to make the socket accessible from the outside execute these commands on Windows (on Linux it's different):

    netsh interface ipv4 install
    netsh interface portproxy add v4tov4 listenport=6437 connectport=6437 connectaddress=127.0.0.1
    

    However, it might be easier to run a local nodejs server on your computer (easier development and debugging). That server would read the leap motion data from the websocket, then interpret it provide a new webpage for the ESP8266 to control the servos directly. Logging and debugging would be much easier this way, and since you need to have the computer running anyway it's basically no extra cost.

  • So I did something similar to what you are suggesting and it works too for anyone looking for a solution: I created a Python script to collect and clean the data from the leapmotion websocket on my local machine. Then I hosted a websocket from my esp8266 and sent the information to that websocket through my computer.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Trying to get access to Leap motion Web Socket

Posted by Avatar for user105886 @user105886

Actions