Comments (7)
@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.
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.
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.
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.
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.
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.
Ok will do!
from arduino-bleperipheral.
Related Issues (20)
- Can't detect remote devices
- NRF5: CCCDs aren't persisted for bonded peers
- How to set service name ? HOT 1
- ANCS Implementation canWrite is false
- Speed / baudrate of the BLE connection?
- Numpad key codes, anyone?
- How to send more than 20bytes in each transaction with bleSerial.write()?
- Olimexino-nano + Olimexino-nano-ble freezes after begin()
- Why is my BLE Service not appearing after a successful flash? HOT 2
- [Question] Sending long string BLECharacteristic
- Abandoned project?
- nrf52840 HOT 4
- Freeze on blePeripheral.begin(); HOT 7
- BLE Scan
- softdevice_sys_evt_handler_set()
- RFDuino using BLEPerfipheralObserver to scan for iBeacons - Issue HOT 2
- Update iBeacon broadcast packet after starting
- Setting chip to idle state in between measurements
- nRF52832 Supported?
- UART Rx hangs after a few seconds when BLEPeripheral.begin(); is called on nRF51802
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-bleperipheral.