Simple Beacon for Android SmartLock workaround.

Posted on
Page
of 2
Prev
/ 2
  • quick question, what would be the syntax to clear the security setting? Would it just be

    NRF.setSecurity({});
    

    ?

  • Yes, that should do it.

  • Ok, so I upgraded the firmware and applied the NRF.setSecurity() call and everything seems to be working just fine. It's still getting the random MAC, but with the PIN, I'm not bothering with the whitelist, so that's fine.

    The only thing I noticed is that the pin only comes into play when connecting with the phone. When I try to connect to the Puck via the IDE, it connects without asking for anything.

    It's not really a big deal, since I'm six floors up and I doubt my neighbors are really into hacking, but I was just curious if that was as designed and/or if there was a way to make the PIN always necessary.

  • Ahh, it's possible that doing NRF.setSecurity({....., mitm:1}); will force it?

    When Espruino is connecting to other devices you can query the state of the connection to see if it's bonded or secure, but looking at it there doesn't seem to be a way to query the state of the connection when Espruino is acting as a peripheral :(

    Just a quick note about passcode - I spotted a bug in the version you would have downloaded which means that NRF.setSecurity({}); would fail (so wouldn't remove the passcode) - current 'cutting edge' firmwares have that fixed though.

  • Update: So everything has been working pretty much perfectly now, but there's just one problem. I've gone through 2 batteries over the last almost 2 months.

    The first battery I just attributed to the heavy load from all the experimentation and testing and bugs leading to infinite connect/disconnect loops. :) But the second battery did not experience anything but normal (and what should be low-drain) use as the beacon that I built it to be.

    I'm attaching a file of all the code that has been running on the puck this whole time. Maybe someone can spot something I did wrong to put an undue draw on the power. I'm already going to comment out the lightshows that happen on connect and disconnect, so that should help (although I spend a lot of time at home, so those should not be firing that much anyway) and I'll add a counter to increment on each connect and disconnect, so the next time the battery dies I can get an idea of how much activity there has been.

    But if this keeps up and there's no obvious fix, maybe I should get the pixl instead for its ability to be plugged into a wall socket for power?


    1 Attachment

  • I just realized that I had an interval set to run every 15 minutes to shut off all the LEDs, just as a backstop because sometimes the lightshows would not stop.

    I wonder if that was doing it.

    Since I'm disabling the lightshows, I can disable that too; hopefully that will help.

  • Sat 2019.03.16

    Hi @FuzzyBumble what duration is the 'whole time' as it isn't really spelled out? A day, week, month?

    from #30 pp3 'all the code that has been running on the puck this whole time'

    Although I did a quick peek at the code file, I didn't spend much time attempting to comprehend it. These might help:

    Excessive LED usage along with repeated advertising and endless Javascript loops are battery killers. 240mAhr capacity. The function lightshow() is drawing 10mA for a second. That could add up.

    https://kitsbitsnbytes.wordpress.com/2017/07/30/puck-battery-how-long-will-that-cr2032-battery-last/

    and under heading Power Consumption

    http://www.espruino.com/Puck.js#power-consumption


    ' maybe I should get the pixl instead for its ability to be plugged into a wall socket for power?'

    More authentic Espruino boards are a good thing !! ;-)

    Have you considered a 5V wall wort, micro USB female receptacle and a 3V regulator? My development setup is wired to Gnd and 3V (adj to D2)

    Image under heading Pinout

    http://www.espruino.com/Puck.js

  • Hi - it's a shame about your power consumption issues. And you're on a pretty recent firmware, because you're using setSecurity? You could try upgrading to the latest on 'cutting edge' release again as I know there have been a few battery power tweaks recently, but nothing too major.

    Realistically the 15 min interval shouldn't really affect your power consumption noticeably. Just to be sure:

    • You're expecting to be connected to your phone around half the time
    • The other half it'll be disconnected?

    For when you're connected you could try NRF.setConnectionInterval(200) (http://www.espruino.com/Reference#l_NRF_setConnectionInterval) - the auto power saving mode should have done that for you if nothing was happening, but I guess it doesn't hurt to be sure :)

    Only thing to watch out for is that'll then make any interactions with the Puck quite slow, so you want to call it after you've finished the upload (maybe in a setTimeout).

  • I work from home (and live in NYC where food delivery is ubiquitous), so I would say that I'm probably connected far more than I'm disconnected. I have on more than one occasion gone almost a week without leaving the apartment.

    I've run the SetConnectionInterval() call, so I'll see if that helps.

    BTW, while I connected via the IDE to do that, I did a call to Puck.getBatteryPercentage() to see where I was at after three days on the new battery, and it returned 100, so I'm not sure if that means my drain is really low or if the unrealistically high value means that the function is not returning the proper value. :-)

  • With the battery percentage, that's about what you'd expect. I've attached a the discharge curve I copied from a CR2032 datasheet I googled: http://data.energizer.com/pdfs/cr2032.pdf

    Basically the voltage doesn't change noticeably for the first 50% of the battery life (in fact it might even rise!) so it's very difficult to come up with any accurate measurement based on it, especially as the voltage changes far more with temperature (and the amount depends on the exact cell used).

    Puck.js's battery measurement doesn't try to do anything smart, it just returns how far the voltage is between 2.8 and 2.2v -so by the time it's registering a drop the battery is already reasonably empty.


    1 Attachment

    • Screenshot at 2019-03-19 08-34-45.png
  • One more update. Looks like the changes I made to try to fix the power consumption issue were successful. I only just now had to change the battery for the first time since I made the changes 7 months ago.

    So everything is going great. Just thought I'd let everyone know. Thanks for all the help!

  • That's great! Thanks for the update!

    Do you remember what the changes were? Just setConnectionInterval?

  • I ran the setConnectionInterval call, but I think what really fixed things was removing the LED lightshows that I would launch on connects and disconnects, as well as removing this setInterval call that I had in my code:

    var autoLEDOffIntID = setInterval("digitalWrite([LED3,LED2,LED1],0);",1000*60*15);
    

    which was there because sometimes the light shows would persist.

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

Simple Beacon for Android SmartLock workaround.

Posted by Avatar for FuzzyBumble @FuzzyBumble

Actions