puck.js problem - green led flash 5 times

Posted on
  • Hi,
    My puck.js not advertising anymore, i have changed the battery then the green led flash 5 times sometimes when i click the button.
    In a few weeks, The old battery has suddenly lost all its power from ~90% to ~20%.

    When the battery has died, i changed it with a the same new then impossible to scan it and these flashes started..

    What's the meaning of green led flashing ?


    here the script uploaded :

        var presses=0;
        var timeoutDoubleClick = null;
        var nbClick = 0;
        var activeDebug = "";
        var releasedTime = 0;
        var timeoutReleased = null;
        var switchMode = null;
        var low = 0;
        var state = {press : false, release : false};
        var batteryLevel = 0;
        setWatch(function() {
            state.release = true;
            state.press = false;
                activeDebug = "d";
                activeDebug = "";
            if (!timeoutDoubleClick) {
                timeoutDoubleClick = setTimeout(function(){ 
                    timeoutDoubleClick = null;
                    nbClick = 0;
                }, 500);
            if (nbClick > 1) {
                timeoutDoubleClick = null;
                nbClick = 0;
            if(presses > 98){
          }, BTN, {edge:"falling", debounce:20, repeat:1});
            state.release = false;
            state.press = true;
            timeoutReleased =  setTimeout(function(){
                timeoutReleased = null;
                    releasedTime = !releasedTime;
                    var flicker = 0;
                    switchMode = setInterval(function(){
                        if(flicker == 3){clearInterval(switchMode);}
        }, BTN, {
        function sendBatteryInfo(){
                batteryLevel = Math.round(E.getBattery());
                if(batteryLevel < 20){ low = 1;}
        setInterval(sendBatteryInfo,60 * 60 * 1000);
  • Tue 2019.07.30

    Is it possible that a hard reset is being performed instead of just inserting the battery?

    'The green LED will blink on success'


    'In a few weeks, The old battery has suddenly lost all its power'

    Am I to understand this means a few weeks ago, or does it mean a new battery only lasted a few weeks? Please elaborate.

  • a few weeks ago, the battery lost all its power from ~90% to ~20% then i changed it today and impossible to scan the puck button.
    After changing the battery , the green led flash started sometimes when i click the button .

    I have hard reseted but the problem persist.

  • The green led will flash 5 times if you pressed the button when you applied power to the battery. It's the self-test as Robin points out.

    If you hard-reset according to http://www.espruino.com/Puck.js#hard-res­et then the Puck's Red LED should flash 5 times and all code will be wiped, so you should be back to normal.

    Please can you try to update your firmware as described in http://www.espruino.com/Puck.js#firmware­-updates ? That would be the first place to debug power usage issues.

    I notice that the code itself that you uploaded seems broken (for instance notify is not a function so would create an error on just the third line), so if you uploaded you wouldn't expect that to work.

    Also, if you uploaded 'direct to flash' then the save() you added at the end would actually cause a reboot loop that'd stop the device working until you cleared out saved code. I guess that could be an issue?

  • Ok thank you, i'll remove "notify(0)" and will try to update firmware .
    I upload the script with noble in node.js program, i'm not using the WEB IDE or Espruino program,
    i thought the function to save the script to ram was "save()" .
    I want to keep the script after reboot.

  • Tue 2019.07.30

    'function to save the script to ram was "save()"'    ( sic - save script to flash ROM )

    You are correct.

    However, . . . placing save() in the code itself will have a different effect than typing in on the Left-Hand console side of the WebIDE after upload, as Gordon points out in #4.

    Please verfiy your setting before upload at:

    WebIDE >> Settings >> Communications >> Save On Send


    I am not familiar with the process using Noble

  • Ok, thanks for the clarification - that explains the echo(0). If that's the case then what you're doing is fine.

    Are you definitely sending newline characters after each line? I notice there's an explicit \n at the end - and if that's the only newline then you might be overflowing Espruino's available memory (or not actually executing echo(0) until after the code has already been uploaded).

    Please could you try connecting and uploading with the Web IDE and see if that makes any difference? It could well be that there's an issue with your code upload from Noble, and using tools that we know work would help to narrow down where that problem is.

  • @Christof550, other option with your uploading approach is:

    • put your active code - lines 17..93 - into the onInit() function
    • send the reset(1) command separately as pre-amble (the true-thy arg clears saved code)
    • drop the notify(0); clearInterval(); clearWatch(); - reset() already took care of this;
    • send the code (lines 6..93 with active code in onInit() function)
    • send the save() command separately as post-amble - it will save the code and invoke onInit() and get's 'you' going

    Any restart of the code / power cycle will then just do fine... (load/execute the - initialization and defining the onInit() - code in to ram and then invoke the onInit();).

  • Thanks all of you, i 'll try your advice soon.

  • @Gordon yes it's the only new line \n

  • Thr 2019.08.01

    re: 'yes it's the only new line \n'

    @Christof550 please re-read @Gordon's 2nd pp in #7 above.

    If there is one and only one new line entry, then it is quite possible an attempt is being made to upload one ginormous line of characters. Each code line requires a line terminator, one is not enough.

    Was the leading and trailing single grave accent char in L1 and L94 from code block in #1 there as part of the code, or there to make the outlining in the code block stand out and be more presentable?

  • haa ok ! I'll add a line terminator for each line of codes.
    Yes, it's because . i create a string variable in my program for the entire puck JS script to upload.


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

puck.js problem - green led flash 5 times

Posted by Avatar for Christof550 @Christof550