notthetup / sensortag-shake

Shake detector for TI SensorTag
Artistic License 2.0
0 stars 0 forks source link

CC2650 Battery Drain #1

Open ghost opened 4 years ago

ghost commented 4 years ago

I'm not sure if this is the correct place to ask this, but I figured I'd start here. I should begin by saying that I am very new to this, so excuse any dumb mistakes.

I am experiencing very fast battery drain (new battery to dead overnight) using a SensorTag CC2650. I have everything working, but this issue is stopping me from progressing further.

The only thing I have changed is the sensitivity in index.js to 0.2. After experiencing this issue, I did add the "Disabling unnecessary sensors" section in an attempt to disable the unneeded sensors. It doesn't seem to have helped.

async.series([
    function(callback) {
        sensorTag.enableAccelerometer(callback);

        //Disabling unnecessary sensors
        sensorTag.disableIrTemperature(callback);
        sensorTag.disableHumidity(callback);
        sensorTag.disableMagnetometer(callback);
        sensorTag.disableBarometricPressure(callback);
        sensorTag.disableGyroscope(callback);
        sensorTag.disableLuxometer(callback);
     }

If it helps, here is my code:

var SensorTagShake = require('sensortag-shake');
var x = 0;
var shake = 0;
var today = new Date();

console.log("shake.js is running");

function getTime() {
  today = new Date();
  var time = today.getHours() + ":" + today.getMinutes();
  if (time == "23:59") {
    shake = 0;
  };
}

setInterval(getTime, 30000);

function startDiscoveryAgain(){
    var sensortagshake = new SensorTagShake('+z');

    sensortagshake.on('shake', function(data){
        console.log("Shook with ", data.value, "at", data.time);
        x = x + 1;
        if (x == 3){
          console.log("Triggered!");
          x = 0;
      if (shake == 0) {
        //notify script goes here
        console.log("SensorTag shook for the first time today");
      }
          shake = shake + 1;
        }
    });

    sensortagshake.on('connect', function(){
      console.log("Connected to SensorTag!");
    });

    sensortagshake.on('disconnect', function(){
      console.log("Disconnected from SensorTag!");
      startDiscoveryAgain();
    });
}

startDiscoveryAgain();

My goal is to have the SensorTag alert the Raspberry Pi Zero when it notices a shake, and the raspberry pi decides if it is the first shake that day. If so, it should print to the console "SensorTag shook for the first time today." Eventually, I plan to have the sensortag attached to a mailbox so that the pi notifies me when the mail is delivered.

If you have any ideas on what may be causing this battery drain and/or any ideas on solutions, I would really appreciate any help. Thanks!

notthetup commented 4 years ago

Hello. I haven't played with this for ages!

I don't have much insight into what the sensortag library https://github.com/sandeepmistry/node-sensortag does. But I did notice this bit of code in my package :

 sensorTag.setAccelerometerPeriod(100, function(error) {
          // console.log("Starting Accelerometer");
          sensorTag.notifyAccelerometer();
        });

I'm guessing this causes the SensorTag to send Accelerometer readings every 100ms. That might be too often, causing it to constantly transmit and hence run out of battery.

Try to see if increasing that period helps.

ghost commented 4 years ago

I had considered doing this, but would changing this mean that it only would send readings if it was moving on the interval? For example, if I set it to 5 seconds and it moved and stoped moving before the 5 seconds was up, do you think that it would report it?

I appreciate the help!

notthetup commented 4 years ago

That's my guess. But I would try it out before assuming.