Manipulating variables between BLE advertising? #1563
Replies: 12 comments
-
Posted at 2021-07-26 by @gfwilliams You can't have code in Espruino that is called each time an advertising packet is sent, but probably the best method is just to use setTimeout?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-27 by user130485 is it possible to stop sending advertisements? I have solar, so during the day the power use is zero (mostly). But because it is resending the last read value, I am currently just sending a 0 (zero) value for power every 30 seconds just to clear it. It is not energy efficient, as I am just sending zero all the time until the next pulse is read, which may be in the afternoon - hours later.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-27 by @gfwilliams You can use It'll have basically the same effect but it's still connectable, and you'll actually get an update of the data to 0, rather than your last received advertising being the last nonzero value. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-27 by user130485
You mean in place of the usual 375/600 ms? I am just worried that ESP32 may not be able to pick it up if it advertises too slow. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-27 by user130485 how does it work with multiple advertisements? If I create one in the main function that it executed on the pulse detection, and then create a different advertisement on timer, do they both exist or whichever was called last? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-27 by @gfwilliams
I meant you can advertise slow when there's no power usage, and then fast when there is. It's then nice easy code.
It's just the one that's called last. If you want them in rotation, you supply an array of them to setAdvertising |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-27 by user130485 no, thats fine as is. Was just confirming to make sure that both don't advertise, taking power. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-28 by @gfwilliams Odd about the battery usage. Definitely being connected uses up a decent amount of power, but apart from that, just advertising, it should last for maybe 6 months. Are you following http://www.espruino.com/Smart+Meter for reading the power usage, or something else? The way the LDR works, the more external light there is the higher the power usage, so that could be it? It's best to get it as dark as possible between the LDR and electricity meter |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-28 by user130485 yes, I am. I have pasted the whole code (modified now a bit) here: Is there a way to test how much power it's using? It's a closed box and I did my best to shield it. It is reading values ok. Signal can hardly get out of the box so had to install esp32 inside it. So dropped the to power to -4 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-28 by @gfwilliams If you have a multimeter that can measure current then you could power the Puck from the gnd/3v pin on it and then measure power consumption that way? It's not super accurate that way but it should be good enough to give you an idea what's going on. Did you connect anything else? I know if D28 is shorted high at boot, it's assumed that is a serial console and then the on-chip serial peripheral is powered up - which can draw ~1mA which sounds like the kind of power draw you're seeing |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-28 by user130485 would be a bit hard to measure with multimeter if I need to keep it in the dark. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-28 by @gfwilliams
No, only if D28 is pulled high. If floating it's fine.
If it's just the LDR I'd maybe see what happens with a fresh battery for now. I'd take the battery percentage reading with a grain of salt - it's not super accurate since the voltage changes with temperature (and the make of battery!). You're definitely running firmware 2v09? With the Puck and LDR I seem to recall I got at least 3 months out of it. Potentially you could even look at adding a rechargeable battery and solar cell. Something like a single LiFePo4 or 2x NiMh batteries would be great. There's so little power drawn than even a small solar cell would easily keep it going forever |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2021-07-14 by user130485
Hi
Have a code that sends BLE advertising like this:
The "power" variable is instantaneous power that I display between pulses. But the issue that I have is that when there is a delay between pulses that goes for too long (have solar), it keeps retransmitting the last value.
Is it possible to manipulate it somehow, so that I can put some code in between the interval resends?
Like if time difference between pulses is over 60 seconds, it will set the "power" variable to 0
Beta Was this translation helpful? Give feedback.
All reactions