Battery Level Reporting

Ok, so I’ve built up battery operated temp sensor, and it has been working for the last 3 days.

I decided to build up the battery detection circuit and added (copied and pasted the battery example into the temp sensor sketch) the code, but I cannot figure out where to actually pull the value in Vera?? There doesn’t seem to be a battery level device property for the temp sensor node.

How do I use/find the battery property?

Code and Pic below:

[code]#include <Sleep_n0m1.h>
#include <SPI.h>
#include <EEPROM.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <RF24.h>
#include <Sensor.h>

#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
#define MAX_ATTACHED_DS18B20 16
unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds)

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
Sensor gw;
Sleep sleep;
float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=0;
int oldBatteryPcnt = 0;
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
boolean metric = false;

void setup()
{

// use the 1.1 V internal reference
analogReference(INTERNAL);
sensors.begin();
gw.begin();

// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo(“Temperature Sensor”, “1.0”);

// Fetch the number of attached sensors
numSensors = sensors.getDeviceCount();
// Register all sensors to gw (they will be created as child devices)
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
gw.sendSensorPresentation(i, S_TEMP);
}
metric = gw.isMetricSystem();
}

void loop()
{

sensors.requestTemperatures(); // Fetch temperatures from Dallas
delay(100);
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
// Fetch and round temperature to one decimal
float temperature = static_cast(static_cast((metric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
// Only send data if temperature has changed and no error
if (lastTemperature[i] != temperature && temperature != -127.00) {
gw.powerUp(); // Powerup introduces a small delay (which is missing in radio.write powerup)
// Send variable (using registered shortcut) to gw
gw.sendVariable(i, V_TEMP, temperature, 1);
lastTemperature[i]=temperature;
}
}

// get the battery Voltage

int sensorValue = analogRead(BATTERY_SENSE_PIN);
Serial.println(sensorValue);

// 1M, 470K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
// 3.44/1023 = Volts per bit = 0.003363075
float batteryV = sensorValue * 0.003363075;
int batteryPcnt = sensorValue / 10;

Serial.print(“Battery Voltage: “);
Serial.print(batteryV);
Serial.println(” V”);

Serial.print(“Battery percent: “);
Serial.print(batteryPcnt);
Serial.println(” %”);

if (oldBatteryPcnt != batteryPcnt) {
// Power up radio after sleep
gw.sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}

// Power down the radio. Note that the radio will get powered back up
// on the next write() call.
delay(500);
gw.powerDown();
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime
}

[/code]

You will find the battery percentage data in the Advanced Tab of the NODE, not the Temp Sensor. It’s the very last items in the tab, percentage and last date.

So now I’m confused, Is the NODE the MySensor Plugin? (If so, then I don’t see what you are referring to on the advanced tab) Here is a picture of what was installed. The MySensor plugin I installed, and the other was install on inclusion of the temp sensor.

When you created the MySensors device you got that control. It allows you to include sensors by searching for then.

When you include a sensor you should get a NODE item and one item for each sensor attached to the NODE. So if you have a single sensor you should get two items, the NODE and the sensor, if you have three sensors you would get four items and so on. The node will report the name of the sketch, the library and the time of the last update. If it’s a Battery Sensors you will also see the battery symbol.

So how do I fix this? It did not create the node when the sensor was included. How is this even working?

I deleted the sensor in vera, and started the inclusion again, and whola the node was added this time…

The battery value seems to default @ 37, no matter what strength the batteries are. So @ 2.932v it’s 37, and 3.246v it’s 37. (+V is taken before regulator)