Here's my test bed code (based on your test code). I just load it into the IDE and test via the command line. Hoping some of the PM2 functions does the trick, though I can see lots of questions on the web on how to get this to work. I am switching evenings between writing bits of code and reading the datasheet and doing a test session on another day.
/*
test bed for working out lowest power consumption, with workable GPS
Load into IDE and upload code to RAM when connected to watch
*/
Bangle.on('GPS-raw',function (d) {
if (d[0]=="$") return;
if (d.startsWith("\xB5\x62\x05\x01")) print("GPS ACK");
else if (d.startsWith("\xB5\x62\x05\x00")) print("GPS NACK");
// 181,98 sync chars
else print("GPS",E.toUint8Array(d).join(","));
});
function writeGPScmd(cmd) {
var d = [0xB5,0x62]; // sync chars
d = d.concat(cmd);
var a=0,b=0;
for (var i=2;i<d.length;i++) {
a += d[i];
b += a;
}
d.push(a&255,b&255);
console.log(d);
Serial1.write(d);
}
// quick hack
function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}
function UBX_CFG_PMS() {
// UBX-CFG-PMS - enable power management - Super-E
writeGPScmd([0x06,0x86, // msg class + type
8,0,//length
0x00,0x03, 0,0, 0,0, 0,0]);
}
function UBX_CFG_INTERVAL(period, ontime) {
writeGPScmd([0x06,0x86, // msg class + type
8,0, //length
//v0, interval period ontime reserved
0x00, 0x02, period, 0, ontime, 0, 0, 0 ]);
// the values are little endian, least significant byte first
}
/*
* set update baud rate
*
* the setting is in milliseconds in 2 bytes, max 65 seconds
* we are passing in a value in seconds
* we set the most significant byte only
* 8 seconds ~ 8192ms 0x2000, 0x20 = 32 = 4*8
*
*/
function UBX_CFG_RATE(rate) {
rate = (rate * 4) % 256;
console.log("rate=" + rate);
writeGPScmd([0x06,0x08, // class, id
0x06, 0, // length
0x00, rate, // b0: 8192ms 0x2000, 0x00FF (~65sec)
0x01, 0x00, // b2:
0x01, 0x00]); // b4: timeref GPS
}
/*
* Save configuration otherwise it will reset when the GPS wakes up
*
*/
function UBX_CFG_SAVE() {
writeGPScmd([0x06, 0x09, // class id
0x0D, 0x00, // length
0x00, 0x00, 0x00, 0x00, // clear mask
0xFF, 0xFF, 0x00, 0x00, // save mask
0x00, 0x00, 0x00, 0x00, // load mask
0x01]); // b2=eeprom b1=flash b0=bat backed ram
// code on github had 7 - all 3 set ?
}
function onGPS(fix) {
console.log(fix);
}
Bangle.setGPSPower(1);
UBX_CFG_INTERVAL(30,5);
wait(20);
UBX_CFG_RATE(8);
wait(20);
UBX_CFG_SAVE();
Bangle.on('GPS',onGPS);
I am hoping if you can test connected to a milliamp meter on the bench you might be able to find the right sequence to get to the magic 2mA current usage. I am looking for a usable fix update between 30-60 seconds. This is why I have set UBX_CFG_PM2 to 30 and 20 seconds for the update and search times (though as I say, yet to try these new functions, I have just drafted them out tonight).
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Here's my test bed code (based on your test code). I just load it into the IDE and test via the command line. Hoping some of the PM2 functions does the trick, though I can see lots of questions on the web on how to get this to work. I am switching evenings between writing bits of code and reading the datasheet and doing a test session on another day.
I am hoping if you can test connected to a milliamp meter on the bench you might be able to find the right sequence to get to the magic 2mA current usage. I am looking for a usable fix update between 30-60 seconds. This is why I have set UBX_CFG_PM2 to 30 and 20 seconds for the update and search times (though as I say, yet to try these new functions, I have just drafted them out tonight).