You are reading a single comment by @Robin and its replies. Click here to read the full conversation.
  • 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

  • Thr 2021.04.08

    Hi @jgrizou and Kudos on your ease of project success!

    'So first, thanks for developing all this!'

    I know that @Gordon will appreciate your kind words for all the hard work and determination he has put into the the creation and success of the Espruino project, making it's ease of use a core goal for evey newcomer.


    'The ability to publish information from the embedded device to the webpage'

    There is a great starting page tutorial with embedded 'Try Me' buttons for each snippet that demonstrate BLE communication both ways:

    note: mentally substitute 'MDBT42Q' for 'Puck.js' and use those snippets as is


    http://www.espruino.com/Web+Bluetooth

    http://www.espruino.com/Interfacing

    http://www.espruino.com/Tutorials



    I'm only able to provide some assistance using Windows10, but this page should assist visually in the connectivity part:

    http://www.espruino.com/Quick+Start+BLE



    I'll defer to Gordon for the technical explanation for the eval() funtionality, and your comments/discussions questions.

About

Avatar for Robin @Robin started