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 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);


    var host = "";
    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(){

    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:­/documentation/javascript/supplements/Le­ap_JSON.html

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


  • 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.

  • 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 will work.

  • I just tried switching out the host: 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 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 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=

    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

Trying to get access to Leap motion Web Socket

Posted by Avatar for user105886 @user105886