-
-
Hey everyone,
Really enjoying getting back into working with my Puck.js v 2.0b Firmware 2v14
I'm trying to get the Puck to notify my iOS app (Xcode 13.4), and I am able to find and connect to the Puck, discover the services and custom characteristic, but when I try to
setNotifyValue(true, for: customCharacteristic)
I get the following error and notifications are clearly do not work when I press the button:ERROR updating notification state error=Error Domain=CBATTErrorDomain Code=6 "The request is not supported." UserInfo={NSLocalizedDescription=The request is not supported.}
The Puck.js code I am using is from the documentation:
var count = 0; NRF.setServices({ 0xBCDE : { 0xABCD : { value: "Hello", maxLen : 20, notify: true }, } }); setWatch(function() { count = count + 1; NRF.updateServices({ 0xBCDE : { 0xABCD : { value : "World "+count+"!", notify: true } } }); }, BTN, { repeat:true, edge:"rising", debounce: 50 });
Appreciate any guidance.
Thanks,
Narath -
-
Okay - so I tried a different tack. I had it do what I ultimately wanted it to do - wake on button, turn on wifi, send a GET request, turn off wifi and go to sleep. I had hoped to send the battery voltage with the GET request, but it looks like E.getBattery is only for the Pico.
Is there a way to read the battery voltage level?
I saved the code given below, and checked the power consumption - and low and behold - it appears to sleep at 0.64 mA !
I am using a LiPo 3.7V 500mAh battery. I have it wired to the + and - terminal. Should I wire it to the 3.3V instead and skip the power regulator to possibly save power (hopefully without nuking the chip).
I'm also ordering more Espruino's from Adafruit, as this is getting very exciting!
Thanks,
Narathvar wifi = require("Wifi"); var http = require("http"); pinMode(A0, 'input_pulldown'); var webhook_url = "WEBHOOK URL HERE"; function wifiOff() { console.log("Trying to turn wifi off"); wifi.disconnect(); A13.read(); } function wifiOn(callback) { console.log("Trying to turn wifi ON"); wifi.connect("WIFI", {"password": "PASSWORD"}, function(ap){ console.log("connected"); callback(); }); } function get(url, done){ console.log("GET"); http.get(url, function(res) { res.on('data', function(data) { console.log("HTTP> "+data); }); res.on('close', function(data) { console.log("Connection closed"); done(data); }); }); } function onInit() { wifiOff(); } setSleepIndicator(LED1); function doneClick(data) { console.log("Done! Go to sleep"); wifiOff(); setDeepSleep(1); } function sendClick() { console.log("Trying to connect"); wifiOn(function(){ get(webhook_url, doneClick); }); } setWatch(function() { sendClick(); }, A0, {repeat: true, edge: 'rising', debounce: 10}); setDeepSleep(1);
-
Hey @Robin, you are right, I had been trying a lot of different things at once. Let me try to bring us back to a shared baseline. Here is process.env:
>process.env ={ VERSION: "2v04.378", GIT_COMMIT: "ca6e4731", BOARD: "ESPRUINOWIFI", FLASH: 524288, STORAGE: 65536, RAM: 131072, SERIAL: "41006e00-0b513532-39333638", CONSOLE: "USB", MODULES: "Flash,Storage,hea" ... ",neopixel,Wifi,AT", EXPTR: 536871212 }
Here is the code - including the state checking:
pinMode(A0, 'input_pulldown'); function onInit() { A13.read(); } function doStuff() { console.log("doing stuff"); setTimeout(function(){ console.log("Going to sleep again"); setDeepSleep(1); }, 2000); } setSleepIndicator(LED1); setWatch(function() { console.log("A0 pressed"); doStuff(); }, A0, {repeat: true, edge: 'rising', debounce: 10}); console.log("A0 = ",getPinMode(A0)); console.log("A1 = ",getPinMode(A1)); console.log("A4 = ",getPinMode(A4)); console.log("A5 = ",getPinMode(A5)); console.log("A6 = ",getPinMode(A6)); console.log("A7 = ",getPinMode(A7)); console.log("B0 = ",getPinMode(B0)); console.log("B1 = ",getPinMode(B1)); console.log("B3 = ",getPinMode(B3)); console.log("B4 = ",getPinMode(B4)); console.log("B5 = ",getPinMode(B5)); console.log("B6 = ",getPinMode(B6)); console.log("B7 = ",getPinMode(B7)); console.log("B8 = ",getPinMode(B8)); console.log("B9 = ",getPinMode(B9)); console.log("B10 = ",getPinMode(B10)); console.log("B13 = ",getPinMode(B13)); console.log("B14 = ",getPinMode(B14)); console.log("Going to sleep"); setDeepSleep(1);
Here is the console output:
>A0 = input_pulldown A1 = analog A4 = analog A5 = analog A6 = analog A7 = analog B0 = analog B1 = analog B3 = analog B4 = analog B5 = analog B6 = af_output B7 = af_output B8 = analog B9 = analog B10 = analog B13 = analog B14 = analog Going to sleep >save() =undefined Compacting Flash... Calculating Size... Writing.. Compressed 114368 bytes to 4919 Running onInit()...
Here is the dump - after reset, upload, save and then reset:
>dump() function onInit() {A13.read();} function doStuff() { console.log("doing stuff"); setTimeout(function(){ console.log("Going to sleep again"); setDeepSleep(1); }, 2000); } setWatch(function () { console.log("A0 pressed"); doStuff(); }, A0, { repeat:true, edge:'rising', debounce : 9.99927520751 }); setSleepIndicator(B2); E.setFlags({ "deepSleep": 1, "pretokenise": 0, "unsafeFlash": 0, "unsyncFiles": 0 }); pinMode(A0, "input_pulldown"); digitalWrite(B2, 1); =undefined
And here is the power consumption: 2.4 mA again.
I'd certainly welcome any ideas.
-
@maze1980 - thanks for pointing that out. I removed all the console lines - and the same power consumption.
@Robin - I tried checking all the pin modes - they don't seem to change. I used this code:
console.log("A0 = ",getPinMode(A0)); console.log("A1 = ",getPinMode(A1)); console.log("A4 = ",getPinMode(A4)); console.log("A5 = ",getPinMode(A5)); console.log("A6 = ",getPinMode(A6)); console.log("A7 = ",getPinMode(A7)); console.log("B0 = ",getPinMode(B0)); console.log("B1 = ",getPinMode(B1)); console.log("B3 = ",getPinMode(B3)); console.log("B4 = ",getPinMode(B4)); console.log("B5 = ",getPinMode(B5)); console.log("B6 = ",getPinMode(B6)); console.log("B7 = ",getPinMode(B7)); console.log("B8 = ",getPinMode(B8)); console.log("B9 = ",getPinMode(B9)); console.log("B10 = ",getPinMode(B10)); console.log("B13 = ",getPinMode(B13)); console.log("B14 = ",getPinMode(B14));
And got this output:
A0 = analog A1 = analog A4 = analog A5 = analog A6 = analog A7 = analog B0 = analog B1 = analog B3 = analog B4 = analog B5 = analog B6 = af_output B7 = af_output B8 = analog B9 = analog B10 = analog B13 = analog B14 = analog
-
@Gordon - I was using the following commands to save:
- reset()
- Upload using IDE with Communication Mode > Save On Send > RAM
- save()
- dump() to check what was written
Interestingly, the Blue LED is now showing again, and A13.read() no longer turns it off, nor does wifi.disconnect();
I did download the latest edge firmware and flash it - unfortunately no change - power consumption still 2.3 mA
- reset()
-
Hey guys, unfortunately - Gordon was right - without me clearly knowing what I had changed to fix it - it returned to it's previous power consumption. I did get an oscilloscope, but unfortunately no current probe (I have a shunt resistor, but have no differential probe, so have not tried reading it yet). I did get an analog meter as well, and it gets the same power reading.
@Gordon, here is my current code on the device:
pinMode(A0, 'input_pulldown'); A13.read(); setSleepIndicator(LED1); function doStuff() { console.log("doing stuff"); setTimeout(function(){ console.log("Going to sleep again"); setDeepSleep(1); }, 500); } setWatch(function() { console.log("A0 pressed"); doStuff(); }, A0, {repeat: true, edge: 'rising', debounce: 10}); console.log("Going to sleep"); setDeepSleep(1);
@Robin, seems reasonable to explicitly set the pinmodes: pinMode looks like it can be all of these: analog', 'input', 'input_pullup', 'input_pulldown', 'output', 'opendrain', 'af_output' or 'af_opendrain'.
These are the pinModes I expect to set, what would you recommend the others be set to:
pinMode(A0, 'input_pulldown'); pinMode(A1, 'input_pulldown'); A13.read();
The pins I expect to set are: A4, A5, A6, A7, B0, B1, B3, B4, B5, B6, B7, B8, B9, B10, B13, B14
Best,
Narath -
-
-
Okay - I am a believer!
Great suggestion by @Robin
Time for a 1% resistor and battery only circuit to prove out the meter will actually read that on the low end? e.g. the meter can actually read below 2uA
I used a 100K resistor on the battery circuit and verified getting uA readings.
Then tested the espruino with the A13.read() and got the readings seen below with pressing the button (no wifi, just turns on, then sets sleep mode)
-
-
-
-
Hi Robin, thanks for sticking with me on this.
Do we know the limits on the current measuring meter. Do we have a spec sheet indicating it's limits? e.g. can it measure down beneath milliamp to microamp?
It can go from milli down to microamps.
'You can call setSleepIndicator(LED1). LED1 will then be lit whenever the device is not sleeping'
http://www.espruino.com/Power+Consumption
Does the Red LED1 illuminate ever?
It does when I have the chip "doing stuff", but then does go off after setDeepSleep(1).
As it was indicated that all five bullet items, post #4 were confirmed, it is known that power save mode will not work using USB.
Yes - thanks, had noticed this when trying to test sleep while connected through the Web IDE :-)
'to instruct to power down (like explicitly telling the wifi to power down)'
This may be the clue, although I am not able to say definitively, as I'm unable to locate specific documentation on the Blue LED and it's indication under battery usage.I see that the blue led is faintly lit on the top surface and another blue led on the undersurface. It does seem that there might be some ongoing power to the 8266 chip.
I have tried reflashing the Espruino and then upgrading the Esp8266 chip. Has not changed the power consumption.
http://www.espruino.com/Reference#Wifi
Has the powersave parameter been supplied an argument to test that as an option?
http://www.espruino.com/Reference#l_Wifi_setConfigInterestingly, that is not an option for me. I get an error when trying to setConfig on wifi:
>var wifi = require("Wifi"); ={ connect: function (a,b,c) { ... }, disconnect: function (a) { ... }, startAP: function (a,b,c) { ... }, stopAP: function (a) { ... }, scan: function (a) { ... }, getIP: function (a) { ... }, setIP: function (a,b) { ... }, getAPIP: function (a) { ... }, setAPIP: function (a,b) { ... }, setHostname: function (a,b) { ... }, ping: function (a,b) { ... }, turbo: function (a,b) { ... }, debug: function () { ... } } >wifi.debug() ={ wifiMode: 0, connected: 0, socks: [ ], sockData: [ "", "", "", "", "" ] } >wifi.setConfig(); Uncaught Error: Function "setConfig" not found! at line 1 col 6 wifi.setConfig(); ^
Typically, the user defined ones are LED1 and LED2, Red and Green. I'm making the assumption, and I feel that from your comment above you are in agreement, that the Blue LED is indicating the WiFi is attempting to turn on. As we know LED's can be power hogs, even when dimmed, this is likely causing the high current draw. But I'm not able to provide a solution on how to resolve that, just yet.
Thanks - it looks like setDeepSleep might not be appropriately powering down the wifi, or the wifi leds.
See note beneath heading 'Saving Power' regarding pinMode.
http://www.espruino.com/Power+Consumption
I suppose it might be possible that one or more of the output pins are taking on a state, not being explicitly defined. Maybe (a bit redundant though) setting every pin to a known state might provide a bit more peace of mind.Will certainly try this if no further progress. I suspect based on https://www.electro-tech-online.com/articles/achieving-low-power-on-adafruit-trinket.830/ that this would only account for a few micro amps.
Thanks again for your help. Hoping we can get to low power sleep at some point.
-
-
Hi Robin,
Thanks for the thoughtful reply. Some responses:
>process.env ={ VERSION: "2v04", GIT_COMMIT: "3956264e", BOARD: "ESPRUINOWIFI", FLASH: 524288, RAM: 131072, SERIAL: "41006e00-0b513532-39333638", CONSOLE: "USB", MODULES: "Flash,Storage,hea" ... ",neopixel,Wifi,AT", EXPTR: 536871212 } >
It was being powered by a LiPoly battery (also tested it with USB power breakout - with the same result).
Have no external LEDs. Had set the SleepIndicator as per the code, but turning that off did not seem to change anything.
The pull down resistor was 10K, I increased this to 100K and it did not change the current draw (and the button still worked). Picture of that attached.
I have noticed that there is a small blue LED on the Espruino that is faintly active when powered by battery.
Thanks again for your help. Hopefully we can get this down to 0.05mA
-
Really enjoying getting to know my Espruino Wifi. I'm trying to build a test simple device that wakes on a button press and sends a signal. I want it to be battery powered so was super excited about the very low power consumption in deep sleep mode and easy wake on interrupt.
When I set this up to wake on a signal to A0, and then go back to sleep I still get a current draw of 2.3 mA (not the hoped for 0.05 mA). Is there something that I need to instruct to power down (like explicitly telling the wifi to power down) to get to the low power consumption?
pinMode(A0, 'input_pulldown'); setSleepIndicator(LED1); setWatch(function() { // doing stuff console.log("doing stuff"); setTimeout(function(){ console.log("Going to sleep again"); setDeepSleep(1); }, 2000); }, A0, {repeat: true, edge: 'rising'}); console.log("Going to sleep"); setDeepSleep(1);
Thanks in advance,
Narath
Okay - got it solved! It was due to the iOS Bluetooth caching. Since I had connected to the device at some point, it cached the initial service and characteristics (which were only read). I did try turning Bluetooth off at the swipe down menu but this apparently did not clear it.
To clear the iOS bluetooth cache I do this:
This did the trick, and now setting notify works correctly, and I get notifications! Woot - go espruino!