Bangle.js emulator: Module http not found

Posted on
  • I've tried the Emulator and tried a simple http request.
    I've checked this (http://www.espruino.com/Internet) site and the following code:

    var http = require("http");
    http.get("http://www.espruino.com", function(res) {
      res.on('data', function(data) {
        console.log(data);
      });
    });
    

    But the emulator throws an error: Module http not found.

    Does Bangle.js support http get requests?

    I also had the same error message when i've tried WebSocket. Then it's complaining about missing module "http" and "net".

    What am I doing wrong?
    Does actually Bangle.js support making simple http requests?
    What about WebSocket connections?

    Best regards and thanks for any kind of help in advance.
    ArthurT

  • Tue 2020.02.04

    Is it possible that HTTP over Wifi is being confused with Bluetooth BLE?

    http://www.espruino.com/Bangle.js
    http://www.espruino.com/Bangle.js+TechniĀ­cal

    Module reference

    https://banglejs.com/reference#t_Bangle

    The link to the code extraction from post #1 refers to chips that have built in WiFi.

    Was there some documentation that leads one to believe this is possible? please provide link

  • Bangle.js doesn't support HTTP or TCP/IP, which is why you're getting the error. Bluetooth LE doesn't support networking properly, so if you want to connect to the internet, you'll need some kind of 'bridge' that has both BLE and a network connection - like a phone, PC, or Raspberry Pi.

  • So do I understand it correct, that the issue with my code is, that the Bangle.js emulator does not support network connections?

  • Yes - if you ran that code on a device with a network connection it'd be fine

  • Thank you for pointing that out. I'll be looking forward to get my hands on the Bangle.js :)

  • I've just received the Puck.js and ran the code on the device.
    I guess Robin was right and i've mixed up HTTP over Wifi with Bluetooth BLE.
    From my naive understanding I've thought that, as soon as the device is connected/paired through Bluetooth, that the puck/bangle would have access to the Internet.
    Do I understand it right, that I have to run EspurinoHub on a computer to bridge the device to the internet?
    How would I bridge the puck.js through an android device to the internet?

    I guess one approach would be to run puck.js code in the browser?
    http://www.espruino.com/Web+Bluetooth

    I've also have a weird behaviour on my linux maschine. I've activated the chrome flag for web bluetooth and was capable to transfer code from the browser IDE to the device.

    However, when I run the first example code from here: http://www.espruino.com/Web+Bluetooth
    on my webserver and open it with the same linux browser, I get the message: "This Web Browser doesn't support We Bluetooth."

    I'm a little bit confused at the moment. Maybe somebody can point me into the right direction how i can do http get requests?

    Thank's in advance
    update: I've tried the example Web Bluetooth code also with my smartphone browser which was also capable of running the ide and connect through web bluetooth to the device. Same error message: This Web Browser doesn't support Web Bluetooth.
    update: my page wasn't delivered through https. after activating ssl i can connect via web bluetooth. however, I still need an answer for the bridge question(s) :)

  • I've thought that, as soon as the device is connected/paired through Bluetooth, that the puck/bangle would have access to the Internet

    No, I'm afraid that's not the case. There is no proper support for HTTP or Networking in Bluetooth LE, so there's nothing that 'just works'.

    There is the Bluetooth LE HTTP proxy that you can use with EspruinoHub but it's extremely limited in terms of the data that you can transfer: http://www.espruino.com/BLE+HTTP+Proxy

    How would I bridge the puck.js through an android device to the internet?

    Web Bluetooth would be the best bet as you suggest. It's easy to develop and multiplatform, but you could write an Android App to handle it too if you want something always-on.

    Basically there's no easy way to do an HTTP request direct from Puck.js. The best way is to do the HTTP request on your 'bridge' device and just send the data you need back to the Puck.js over Bluetooth.

    It's a pain, but Bluetooth LE just doesn't have support for networking in it - it's not what it's meant for.

    when I run the first example code from here: http://www.espruino.com/Web+Bluetooth
    on my webserver

    Are you using HTTPS? Web Bluetooth only gets enabled for HTTPS sites, not HTTP. (ahh - I just read at the bottom that you figured this out).

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

Bangle.js emulator: Module http not found

Posted by Avatar for ArthurTent @ArthurTent

Actions