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

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

    That is actually possible right now. It's not well documented for UART.js, but there is an example for the Puck.js library (which is just like UART.js, except it's Bluetooth only). You basically call connect and then you get a callback whenever data is received (which you can do by calling Bluetooth.println).

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

    or

    https://www.espruino.com/Bangle.js+Data+­Streaming

    There was some talk of whether this could be made easier though - effectively being able to register a UART.on('myevent', callback) function so you could send multiple event types without having to filter them yourself.

    The ability to use an embedded device as if it was a javascript module

    That's really neat! 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/

    While that won't work on Espruino, on the PC you could happily call UART.myfunction(...) and it'd translate it into a similar call:

    Espruino = {};
    Espruino = new Proxy(Espruino, {
      get: (target, prop) => function() { console.log(prop+"("+[].map.call(argumen­ts,x=>JSON.stringify(x)).join(",")+")") },
      has: (target, prop) => true
    });
    
    Espruino.test(1,2,3,"Hello",{a:42});
    // prints 'test(1,2,3,"Hello",{"a":42})'
    

    So if you call a function that doesn't exist it's no big deal - it just creates a referenceError on Espruino.

    In a way, I guess while this could be in UART.js, maybe it even makes sense to built it as a separate library on top of it, that is Espruino specific?

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

About

Avatar for jgrizou @jgrizou started