• Board: ESPRUINOWIFI, 2v06
    AT version:0.40.0.0(Aug 8 2015 14:45:58)

    http://www.espruino.com/WiFi#connecting-­to-an-ap
    I copied this code and it works great when connected to device and flashing the code with Web IDE, but when I am disconnected from Web IDE and plug the device into USB, it keeps waiting for the Web ID on this line console.log("Response: ",res);. Once I re-connect with Web IDE, the code continues running. Also, if I change the line to console.log("Response: ",res.statusCode);, it also works without problems. It seems to be problem cumulative size of console output.

    This is easier to notice when you turn on different LEDs during the request, you can reproduce it by replacing the getPage function with this:

    function getPage() {
      LED1.write(1);
      LED2.write(0);
      require("http").get("http://www.pur3.co.­uk/hello.txt", function(res) {
        console.log("Response: ",res);
        res.on('data', function(d) {
          console.log("--->"+d);
        });
        res.on('close', function() {
          LED1.write(0);
          LED2.write(1);
        });
      });
    }
    

    http://forum.espruino.com/conversations/­306063/
    This looks like similar issue, but it feels odd that console.log sometimes works properly and sometimes doesn't.

    Is there some way to check if device is actually connected to Web IDE, so I could rewrite console.log function to discard the output? I tried E.getConsole(), but that returns "USB" no matter if I am actually connected to Web IDE or not. Using a USB cable that doesn't support data returns "Serial1", but that cable never causes the console.log to stop either.

  • Yes, this is a common issue: http://www.espruino.com/Troubleshooting#­i-typed-save-but-espruino-won-t-work-or-­stops-working-quickly-when-powered-from-­a-computer-it-only-works-from-a-usb-powe­r-supply-battery-or-the-computer-when-th­e-web-ide-is-running-

    It's intentional that the board won't drop information if you're connected to USB - because chances are everyone would get upset pretty quick if data that was output just disappeared into thin air if it wasn't read for a second or two

    The issue is that from Espruino's point of view it has no way of knowing the difference between:

    • USB connected, no app running on PC
    • USB connected, app running but busy and not reading data
    • USB connected, app running and reading data just fine (although arguably something could be added to detect a lack of movement of data)

    About all I can suggest is to use a function called log that you set to log=function(){}.

    When you connect with the IDE you can then write log = print

  • Thanks, I'll try to keep that in mind.

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

console.log waits for Web IDE connection when plugged in with data USB cable

Posted by Avatar for tarmo888 @tarmo888

Actions