HTTP Request to host Win10 laptop

Posted on
  • What i'd like to achieve is setting the puck button press as a notifyer to my laptop.

    I'm running a simples web server on http://127.0.0.1/5555/notify

    And have tried

    var options = {
        host: '127.0.0.1', // host name
        port: 5555,            // (optional) port, defaults to 80
        path: '/notify',           // path sent to server
        method: 'GET',       // HTTP command sent to server (must be uppercase 'GET', 'POST', etc)
        //headers: { key : value, key : value } // (optional) HTTP headers
      };
    
    
    require("ble_http").httpRequest(options,­ function(res) {
      res.on('data', function(data) {
        console.log("HTTP> "+data);
      });
      res.on('close', function(data) {
        console.log("Connection closed");
      });
    });
    

    The error i'm seeing in the terminal is:

    Uncaught Error: Field or method "connect" does not already exist, and can't create it on undefined
     at line 1 col 20
    var b;return c.gatt.connect().then(function(a){consol­e.log("...
                       ^
    in function "httpRequest" called from line 8 col 2
    });
     ^
    

    I'll freely admit i'm hacking from various examples and code so i'm not supprised it's not working ..
    Is there an approach from the puck that would send a HTTP request to the paired host?

  • The simple answer is no - you have the same problem with any BLE device.

    Having TCP/IP networking over BLE isn't part of the standard enough that your computer will have a 'bridge' to connect BLE to your computer's network connection pre-installed.

    The simplest way to get one would be to follow the instructions here and set one up on a Raspberry Pi: http://www.espruino.com/Puck.js+Node-RED­

    The sort of thing you're doing would then work - however you'd be better starting off with the ble_http example code as I'm pretty sure what you have there isn't right.

    Or if you're running node.js in your PC, you could use the noble library to receive BLE advertising packets, and could then just set your Puck up to change advertising data when the button was pressed - that'd be pretty much the standard way to do it.

    ... although you would probably want to buy a USB BLE adaptor, as 'noble' wants full control of it when running, and you might still want Windows to be able to access BLE.

    eventually Puck.js will support Bonding, which will allow you to use it as a BLE Keyboard with windows - when that happens that'd be by far the easiest way to get notified when something happens!

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

HTTP Request to host Win10 laptop

Posted by Avatar for Piers @Piers

Actions