Most recent activity
-
-
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()
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!