Battery Level



  • Hello,

    I'm trying to get the battery level percentage reported but only get battery voltage. Here is my sketch:

    // General settings
    #define SKETCH_NAME "TempSensorSuite"
    #define SKETCH_VERSION "2.0"
    #define MY_BAUD_RATE 9600
    #define MY_NODE_ID 2
    
    #define MY_RADIO_NRF24
    #define MY_SIGNAL_REPORT_ENABLED
    
    #define MY_SPLASH_SCREEN_DISABLED
    
    //#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
    #define MY_TRANSPORT_WAIT_READY_MS  5000
    #define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 2000
    //#define MY_PARENT_NODE_ID 0
    //#define MY_PARENT_NODE_IS_STATIC
    
    #define NODEMANAGER_DEBUG OFF //
    #define NODEMANAGER_DEBUG_VERBOSE OFF
    #define NODEMANAGER_SLEEP ON //
    #define NODEMANAGER_RECEIVE OFF
    #define NODEMANAGER_POWER_MANAGER OFF
    #define NODEMANAGER_CONDITIONAL_REPORT ON
    #define NODEMANAGER_INTERRUPTS OFF
    #define NODEMANAGER_EEPROM OFF
    #define NODEMANAGER_TIME OFF
    #define NODEMANAGER_RTC OFF
    #define NODEMANAGER_SD OFF
    #define NODEMANAGER_HOOKING OFF
    #define NODEMANAGER_OTA_CONFIGURATION OFF
    #define NODEMANAGER_SERIAL_INPUT OFF
    
    // disable Forecast on BME280 - not working with OTA conf Off!
    #define NODEMANAGER_SENSOR_BOSCH_LITE ON
    
    #include <MySensors_NodeManager.h>
    
    // BME280
    #include <sensors/SensorBME280.h>
    #define BME280_ADDRESS (0x76)
    #define SEALEVELPRESSURE_HPA (1019.7)
    //#define CHILD_ID_AMBIENT 1
    SensorBME280 ambient;
    
    // Battery Level (default child_id 201)
    #include <sensors/SensorBattery.h>
    SensorBattery battery;
    
    // Radio Signal Quality (default child_id 202)
    #include <sensors/SensorSignal.h>
    SensorSignal signal;
    
    // before
    void before() {
    
      // call NodeManager setup routine
       
      ambient.children.get(1)->setDescription("tssuite_temp");
      ambient.children.get(2)->setDescription("tssuite_hum");
      ambient.children.get(3)->setDescription("tssuite_press");
      ambient.children.get(4)->setDescription("tssuite_fcast");
      /*ambient.children.get(1)->setValueDelta(0.2);
      ambient.children.get(2)->setValueDelta(0.5);
      ambient.children.get(3)->setValueDelta(0.5);*/
       // let controller know ambient pressure sensor reports in hPa
      ambient.children.get(3)->setUnitPrefix("hPa");
       
      // send unit prefixes to controller (i.e. V, A, hPa, %, etc.)
      nodeManager.setSendUnitPrefix(true);
    
      // battery level - BOD set to 1.8V, 2xAA = 3V max
      battery.children.get(1)->setDescription("tssuite_bat");
      battery.setSendBatteryLevel(true);
      battery.setMinVoltage(1.8);
      battery.setMaxVoltage(3.2);
    
      // sleep cycle
      nodeManager.setSleepMinutes(5);
      //nodeManager.setSleepMinutes(1);
      // 500ms to let the transport send all buffer before sleeping.
      //nodeManager.setSleepBetweenSend(500);
      
      // report freq for ambient measurements
      ambient.setReportIntervalMinutes(5);
      //ambient.setReportIntervalMinutes(1);
    
      // report freq for battery
      battery.setReportIntervalDays(1);
      //battery.setReportIntervalMinutes(1);
    
      // report freq for radio signal - pseudo SR_TX_RSSI and SR_UPLINK_QUALITY are available for NRF24
      signal.children.get(1)->setDescription("tssuite_sin");
      signal.setReportIntervalDays(1);
      //signal.setReportIntervalMinutes(1);  
      signal.setSignalCommand(SR_UPLINK_QUALITY);
    
      //nodeManager.setPowerManager(power);
    
      // call NodeManager before routine
      nodeManager.before();
    }
    
    // presentation
    void presentation() {
    //  long int t1 = millis();
      // call NodeManager presentation routine
      nodeManager.presentation();
    //  long int t2 = millis();
    //  Serial.print("Presentation: "); Serial.print(t2-t1); Serial.println(" milliseconds");
    }
    
    // setup
    void setup() { 
    //  long int t1 = millis();
      nodeManager.setup();  
      ambient.setSampling(Adafruit_BME280::MODE_FORCED,
            Adafruit_BME280::SAMPLING_X1,  // temperature
            Adafruit_BME280::SAMPLING_X1, // pressure
            Adafruit_BME280::SAMPLING_X1,  // humidity
            Adafruit_BME280::FILTER_OFF, //filter
            Adafruit_BME280::STANDBY_MS_0_5);        
    //  long int t2 = millis();
    //  Serial.print("Setup: "); Serial.print(t2-t1); Serial.println(" milliseconds");
    }
    
    // loop
    void loop() {
      //long int t1 = millis();
      ambient.takeForcedMeasurement(); 
      nodeManager.loop();
      //long int t2 = millis();
      //Serial.print("Loop: "); Serial.print(t2-t1); Serial.println(" milliseconds");
    }
    
    #if NODEMANAGER_RECEIVE == ON
    // receive
    void receive(const MyMessage &message) {
      // call NodeManager receive routine
      nodeManager.receive(message);
    }
    #endif
    
    #if NODEMANAGER_TIME == ON
    // receiveTime
    void receiveTime(unsigned long ts) {
      // call NodeManager receiveTime routine
      nodeManager.receiveTime(ts);
    }
    #endif
    

    I'm probably doing something wrong. Any help will be much appreciated.

    Thanks


Log in to reply
 

Suggested Topics

  • 11
  • 1
  • 2
  • 10
  • 4
  • 2
  • 2
  • 16

0
Online

10.7k
Users

10.9k
Topics

111.6k
Posts