@waspie Thanks for sharing. First thing I notice is you can probably remove:
NRF_CLOCK->INTENSET=B11;
NRF_CLOCK->TASKS_HFCLKSTART=1;
while (!(NRF_CLOCK->EVENTS_HFCLKSTARTED)) {}
from your setup(). I believe this is legacy code that is now built in to MySensors / nRF5-arduino, and managed based on the features you're utilizing.
I just tested power consumption on NRF51822 with SI7021. Similar to your sketch but using the LowPowerLab SI7021 library.
I didn't have to do any hack or workaround to get ~7uA power consumption.
I'm using MySensors 2.3.2, SandeepMistry/nRF-Arduino 0.6. Just to be sure, I also reburned the bootloader.
I will try to get your sketch running on my NRF51, see if I can rule out the specific library as a cause for your power issues.
#define MY_RADIO_NRF5_ESB
#define MY_NODE_ID 68
#define MY_PARENT_NODE_ID 13
#define MY_PARENT_NODE_IS_STATIC
#define MY_PASSIVE_NODE
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
#define MY_TRANSPORT_CHKUPL_INTERVAL_MS 2000
#define MY_TRANSPORT_WAIT_READY_MS 1000
#define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 2000
#define SLEEP_SHORT_MS (5000)
#define SLEEP_MS 1000 * 60 * 1
#define REBOOT_HRS 24
#define REBOOT_MS 1000 * 60 * 60 * REBOOT_HRS
#define BATTERY_SEND_MS REBOOT_MS
unsigned long sleepTime = BATTERY_SEND_MS;
unsigned long lastReboot = 0;
unsigned long lastBatterySent = 0;
unsigned long lastTemperatureSent = 0;
bool firstBoot = true;
#include <MySensors.h>
#include <SI7021.h>
MyMessage msgBattery( 1, V_VOLTAGE );
MyMessage msgTemperature( 3, V_TEMP );
MyMessage msgHumidity( 4, V_HUM );
static SI7021 sensor;
void setup() {
enableReset();
sensor.begin();
}
void loop() {
bool sendBattery = millis() - lastBatterySent >= BATTERY_SEND_MS || firstBoot;
bool shouldReboot = millis() - lastReboot >= REBOOT_MS;
const float temperature = float( sensor.getFahrenheitHundredths() ) / 100.0;
const float humidity = float( sensor.getHumidityBasisPoints() ) / 100.0;
sleep(SLEEP_SHORT_MS);
send( msgTemperature.set( temperature, 2 ) );
sleep(SLEEP_SHORT_MS);
send( msgHumidity.set( humidity, 2) );
if(sendBattery){
sleep(SLEEP_SHORT_MS);
bool sent = send(msgBattery.set(getInternalVoltage(),3));
if(sent) lastBatterySent = millis();
}
if(shouldReboot){
lastReboot = millis();
hwReboot();
}
firstBoot = false;
sleep(SLEEP_MS);
}
void present() {}
float getInternalVoltage(){
return ((float)hwCPUVoltage())/1000.0;
}
void enableReset(){
NRF_POWER->RESET = 1;
while (NRF_POWER->RESET != 1);
}