• Hi,

    I am happy that i have recieved my espruino.
    Do anyone knows how to link the espruino to a html file?
    Like what you do to connect a javascript file to a html documen with

    <script src="....espruino.js"></script>
    

    Or is this not possible?

    Thanks

  • Hi - do you want to control Espruino from a webpage on your PC (while it is physically connected), or do you want it to be controlled while it's powered from something else?

    If you want to control Espruino from a webpage while it's plugged into the PC, you'll have to make your webpage a Chrome Web App (they have a serial api). Either that or you can serve the webpage from something like node or node-webkit, that itself will have serial support.

    If you want Espruino to actually serve up a webpage, and to then be controlled by it, you'll need to plug in some way to get Espruino onto the net - there's a bunch of information about this and some examples on the Internet page.

  • But just to say, Espruino can't alter the CSS/DOM directly... What it can do is:

    • Create the Webpage, with the CSS+DOM in it
    • Serve up some data (or JavaScript) that can be run on the webpage in order to manipulate the DOM.

    Hope that makes sense!

  • Hi Gordon, Thanks for your quick answer.
    What i was wondering was your first sugestion with physically connection for play around with it, but i think with your info i will get what i am looking for.
    If i have made something i will post it here on the forum.(i hope soon)

    excuses for my poorly english.

    Thanks!

  • Great! There's a nicer explanation of using Chrome Serial here: https://developer.chrome.com/apps/app_serial

    And Google have an example app that includes talking to the Arduino and turning a light on and off: https://github.com/GoogleChrome/chrome-app-samples/tree/master/serial/ledtoggle#readme

    If you were using that on an Arduino as they intended, you'd have to program the Arduino first with this code, but on Espruino you can basically change this line from:

    var is_on = false;
    document.querySelector('button').addEventListener('click', function() {
      is_on = !is_on;
      connection.send(is_on ? 'y' : 'n');
    });
    

    to

    var is_on = false;
    document.querySelector('button').addEventListener('click', function() {
      is_on = !is_on;
      connection.send("digitalWrite(LED1, "+(is_on ? '1' : '0')+");\n");
    });
    

    So instead of sending simple data, you can actually send JavaScript, which is then executed by the Espruino itself...

    Note: you'll have to click the button 3 times before anything happens - if you want to fix that, replace:

    connection.send("hello arduino");
    

    with:

    connection.send("hello espruino\n");
    

    as because there was no new line sent before, it won't be executed, and the first button press will actually execute hello arduinodigitalWrite(LED1,1); - which won't work!

  • I think i have to study this explanation with the serial interface very good before i understand it exactly.
    In big lines i get it but i learn javascript for a little year now.Thats not so long jet.
    Very kind of you how you help people forward with this board and the coding.

    I stay tuned !

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

get access to the aspruino from a website to communicate with the dom and css

Posted by Avatar for Bert-Holland @Bert-Holland

Actions