Avatar for jgrizou

jgrizou

Member since Mar 2021 • Last active Apr 2021
  • 2 conversations
  • 10 comments

Most recent activity

  • in JavaScript
    Avatar for jgrizou

    Thanks @Robin @Gordon for sharing all this, it makes total sense and sounds feasible!

    https://www.espruino.com/Web+Bluetooth#t­wo-way-communications

    I tried with good success. UART.on('myevent', callback) is a great way to implement this combined with a function on the embedded side and format events.

    I guess we could have a UART object defined on the device itself, and then just query the keys for that.
    Another option is actually you can dynamically handle key accesses using Proxy: https://spin.atomicobject.com/2018/07/02­/javascript-proxy-object/

    Amazing! The Proxy thing is great and even more hands-off for the user.

    maybe it even makes sense to built it as a separate library on top of it, that is Espruino specific?

    Understanding this better now, I agree that a separate library makes more sense. I will work on a first version and share it here when it is ready ;)

    That looks like a really neat little robot design! Are you planning to publish it anywhere?

    Thanks! It is a quick prototype but you are right, I will make a repo with some basic info (BOM, wiring, code, etc) and share it with the community.

  • in JavaScript
    Avatar for jgrizou

    Hi Gordon, all,

    I started playing making a robot controlled via a webpage using Espruino, see photos attached and video here: https://youtu.be/xKEqqFrYgNQ

    Building the robot took a few hours. And both embedded code + remote control via basic webluetooth page using uart.js less than one hour, I really didn't expect it would be so quick to get a MVP, the Espruino toolchain and REPL spirit is amazing. See very basic interface here: https://editor.p5js.org/jgrizou/present/­osAAXLUtL. It also seem that I could connect several webpage to the same robot which is quite cool!

    This was mind blowing to me on two aspects:

    • the ease of uploading code to a robot via the WebEditor
    • the ease of simply defining function in the embedded REPL that we can call directly from the uart.js library. No interface or protocol to define and deal with, it is just great!

    So first, thanks for developing all this!

    --

    I would like to brainstorm uart.js extension ideas here and collect the community opinion as to wether it is technically feasible and where I should start to implement it if I wanted to.

    At the moment, I can see two ways to use the UART, write and eval:

    • UART.write('LED1.set();\n');
    • UART.eval('E.getTemperature()', function(t) { // do something with t });

    And my understanding is that eval is calling write with an eval statement "\x10eval(process.env.CONSOLE).println(J­SON.stringify('+expr+'))\n". I not 100% sure how this work but it makes sense.

    Source code here: https://github.com/espruino/EspruinoWebT­ools/blob/master/uart.js

    --

    I would be interested in:

    1) The ability to publish information from the embedded device to the webpage. For example, I might want to send an event if a sensor changes value, say my robot bumped into an object. Ideally, we would be able to a callback in uart.js for all spontaneous incoming messages. And the user can then sort them as they wish.

    Maybe via a function sendToUart(), which can be tested using something like:

    setInterval(function() {sendToUart({'value': true}}), 500);
    

    By doing setInterval(function() {console.log({'value': true}}), 500);, I could see the packet being sent to the webpage but they would need to be processed and formatted. It might also make it harder to differentiate between self-published messages and messages sent after an eval() was called maybe. Althought eval() calls seemed to work well despite that noise.

    Just to be clear, I am interested in self-published events from the robot. That is I want to avoid having to call eval() from the browser at fixed interval.

    2) The ability to use an embedded device as if it was a javascript module. This is mostly to avoid having to use string calls in the write and eval function. That would require having an additional function that, on uart.js connection, could read all function available on the embedded device and publish them under an object so we could do something like this on the webpage:

    var robot = UART.connect()
    robot.left();
    var temp = robot.getTemperature();
    

    In the background, all these call would use uart.js write and eval function. Function to be published could be made explicit via some sort of export statement in the embedded code like:

    exportUart({stop, left, right})

    Similar to module export in javascript.

    --

    Do you have thought on this? To be clear I am not asking anyone to implement this, but rather for some comments/discussions on:

    • whether this is already possible?
    • if it is theoretically/technically possible? If yes, what approach could be used?
    • where should I look in the code and what approach should I consider if I wanted to make this happen?

    Thank you for your time reading this long post, any insight from the community would be very appreciated!

    Jonathan

  • in General
    Avatar for jgrizou

    Obviously for most people, if your web browser asks for Bluetooth permissions you click 'Hell No' without even batting an eyelid. When you finally do get a bluetooth device you want to use with the web browser, clicking that button could have happened over a year ago alongside a barrage of other questions about app permissions :)

    That is for sure what happened here ;)

  • in General
    Avatar for jgrizou

    It works now! It was the most stupid thing as often, it was due to MacOS "Security & Privacy"settings but no warning was shown in Chrome.

    I tried espruino --verbose and indeed found Noble issues.

    Noble: getPorts - initialising... Noble: module couldn't be loaded, no
    node.js Bluetooth Low Energy Error: Cannot find module
    '@abandonware/noble'

    It was not installed, so tried installing it which didn't work at first. I followed the tracks and tried resintalling xcode (https://medium.com/@mrjohnkilonzi/how-to­-resolve-no-xcode-or-clt-version-detecte­d-d0cf2b10a750). Could install noble in the end but still did not work.

    I then looked at npm page for noble (https://www.npmjs.com/package/@abandonwa­re/noble#os-x), which says:

    On newer versions of OSX, allow bluetooth access on the terminal app:
    "System Preferences" —> "Security & Privacy" —> "Bluetooth" -> Add
    terminal app (see Sandboxed terminal)

    I went there and found Chrome app unchecked :/, checked it and everything worked. I could use the app loader and uploaded the t-rex app.

    Somehow Bluetility was in the list and already activated but not the two other apps there. I don't remember having done so for Bluetility otherwise I would have understood . There was no warning in Chrome either to indicate this could be an issue, it was blind to the macOS settings. Even chrome://bluetooth-internals/#adapter was showing Bluetooth as available and working. So I am not sure how you could catch that and show a message from the WebIDE.

    Good to have this mystery sorted!

    Thanks again for your time Gordon and apologies if this is a known issue and I missed it in the documentation.

  • in General
    Avatar for jgrizou

    Thanks Gordon for providing so much help!

    Pixl.js does not appear in Mac OS's own Bluetooth menu. I could not see it anywhere but in Bluetility so far.

    I tried Espruino CLI with node.js with no luck either. Pixl is not listed in the espruino --list command either. See attached.

    If of any use to try an alternative method, I am reading these info from Bluetility

    identifier: 7C699A5C-4CE1-44B8-893B-EC81B93996E1
    MAC: E2-89-0F-82-FC-86
    Local Name: Pixl.js fc86 Service
    UUIDs: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E

    I have no idea how Bluetility can see it but not the other tools.

    Let me know if you have other thoughts, but I do not want to take too much of your time on this as very few people still run macbookpro mid-2014.

  • in General
    Avatar for jgrizou

    Yes Chrome up to date, no funny version either.

    The Bluetility can find the Pixl.js, which is good news but this seems to confirm it is a Web Bleutooth issue most probably coming from Chrome.

    Multiple connection is not the issue here, I have been careful to cut my phone Bluetooth to be sure. Also tried rebooting the computer.

  • in General
    Avatar for jgrizou

    Thanks for the quick reply. Yeah it all looks like it should work, it is quite mysterious.

    WebBluetooth status is showing as Ok. It goes through the motion of scanning for devices but end-up finding nothing and asking for a re-scan. It works well on my Android phone in the exact same condition. I attached screenshots.

    It is my personal laptop so no IT restriction. And the Bluetooth works fine with my usual headphone/speakers, etc.

    It is quite strange, I will keep searching. Please let me know if something pops to mind. I am ok to go for a BLE USB dongle, if you have any recommendation.

  • in General
    Avatar for jgrizou

    Just to complement, I saw that you there is https://shop.espruino.com/accessories/us­b-bluetooth on the official shop, but it seems to have the Chipset CSR8510A10 which is not recommended if I understood well from https://www.espruino.com/Quick+Start+BLE­#requirements.

    Any specific recommendation from the community would be of big help here.

Actions