Giter Site home page Giter Site logo

Comments (7)

sandeepmistry avatar sandeepmistry commented on July 30, 2024

@gbuesing that is a great idea! A pull request would be awesome. I could also try with a DHT sensor later.

I'm not to keen about making BLEPeripheral calls inside the interrupt handler (it could confuse state inside the lib). So, my suggestion would be to set a "read temperature" flag to true in the interrupt handler and check for it in the loop. Something like this:

bool readTemperature = false;

// ...

void timerHandler() {
  readTemperature = true;
}

// ...

void loop() {
  blePeripheral.poll();

  if (readTemperature) {
    setTempCharacteristicValue();
    readTemperature = false;
  }
}

What do you think? Another, improvement would be to start/stop the timer on connect/disconnect or subscribe/unsubscribe.

On a side note, it's a bit weird that the nRF8001 and nRF51822 don't let you know about read requests, so you can return dynamic data - but a timer is perfect for notify characteristics.

from arduino-bleperipheral.

gbuesing avatar gbuesing commented on July 30, 2024

That makes sense -- just set a flag in the interrupt handler, and do the sensor reading and characteristic setting in loop(). I tested this approach and it seems to work. Created a pull request with this skeleton: #11

Integrating with a DHT is a good idea -- could also expose the humidity as a second service. I'll give this a shot when I get a chance.

Re: starting/stopping timer on connect/disconnect -- if the peripheral spends a lot of its time advertising, that could save work, and maybe battery. But the potential issue I see is: if a client connects and immediately reads the value, they'd see a value from the last connection, which could have occurred a long time ago.

Ultimately would be nice to figure out how to make this run with very little power - though that might be device (e.g. avr/sleep) and use-case dependent.

from arduino-bleperipheral.

gbuesing avatar gbuesing commented on July 30, 2024

I added code to get real temperature and humidity readings from a DHT22 sensor: https://github.com/gbuesing/arduino-BLEPeripheral/blob/temp_sensor/examples/temp_sensor/temp_sensor.ino

I'm only updating the characteristics when there's a significant change in the reading, which should minimize radio usage for notify events.

Pull request: #11

from arduino-bleperipheral.

sandeepmistry avatar sandeepmistry commented on July 30, 2024

Which Arduino board are you using? I've managed to get idle power consumer to < 2mA with the Blend Micro (this is without the DHT22).

from arduino-bleperipheral.

gbuesing avatar gbuesing commented on July 30, 2024

I'm prototyping on an Uno -- I intend to move the circuit to an Adafruit Pro Trinket 3.3V, or possibly a boarduino.

RedBear has a good example of how to dial system functions down for sleep: http://redbearlab.com/blend-low-power-settings/

But AFAICT the TimerOne library (which I'm using to sample the DHT every two seconds) won't work when in SLEEP_MODE_PWR_DOWN.

I think this could be achieved with the watchdog timer, though?

from arduino-bleperipheral.

sandeepmistry avatar sandeepmistry commented on July 30, 2024

I don't have much experience with timers and watchdogs on the Arduino, but once you figure things out a pull request for a low power mode example would be great :)

My <2mA idle power consumption is based on the Blend example.

#11 closes this.

from arduino-bleperipheral.

gbuesing avatar gbuesing commented on July 30, 2024

Ok will do!

from arduino-bleperipheral.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.