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]