I'm trying to get the Zuno to work as a sensor with two channels. The sensor reports back power values. Watts and KWh (Kilo watt hours).
The problem is that I seem to only get values on one channel.
Maybe I'm not setting the channels up correctly? I read something about some issue if you have two channels with the same type?
All help appreciated
Code: Select all
#define DEBUG 1
// LED pin number
#define LED_PIN 13
// button pin number
#define BTN_PIN 18
// channel number
#define ZUNO_CHANNEL_NUMBER_ONE 1
#define ZUNO_CHANNEL_NUMBER_TWO 2
// Number of blinks per kWh of your meter
#define PULSE_FACTOR 1000
// Pulses per watt hour
float ppwh = ((float)PULSE_FACTOR)/1000;
// The value to report back to controller
//unsigned int kWh;
// Counting the light pulse
volatile uint32_t pulseCount = 0;
volatile uint32_t lastBlink = 0;
volatile uint32_t watt = 0;
volatile uint32_t watt_dummy = 0;
// next macro sets up the Z-Uno channels
// you can read more on http://z-uno.z-wave.me/Reference/ZUNO_SENSOR_BINARY/
ZUNO_SETUP_CHANNELS(
// CHANNEL 1
ZUNO_METER(ZUNO_METER_TYPE_ELECTRIC,
METER_RESET_ENABLE,
ZUNO_METER_ELECTRIC_SCALE_KWH,
METER_SIZE_FOUR_BYTES,
METER_PRECISION_ZERO_DECIMALS,
get_kwh,
reset_kwh
),
// CHANNEL 2
ZUNO_METER(ZUNO_METER_TYPE_ELECTRIC,
METER_RESET_ENABLE,
ZUNO_METER_ELECTRIC_SCALE_WATTS,
METER_SIZE_FOUR_BYTES,
METER_PRECISION_ZERO_DECIMALS,
get_watt,
reset_watt
)
);
// Set the interrupt callback function
ZUNO_SETUP_ISR_INT0(onPulse);
void setup()
{
// Enable interrupt. Triggered when light pulse is detected
zunoExtIntMode(ZUNO_EXT_INT0, RISING);
}
void loop()
{
#ifdef DEBUG
Serial.println("Sending on channel 1");
#endif
zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE); // send report over the Z-Wave to the controller
#ifdef DEBUG
Serial.println("Sending on channel 2");
#endif
zunoSendReport(ZUNO_CHANNEL_NUMBER_TWO); // send report over the Z-Wave to the controller
delay(35000); //sleep 35s
}
// function, which returns the previously saved button state
// this function runs only once the controller asks
uint32_t get_kwh()
{
#ifdef DEBUG
Serial.print("get_kwh called, returned ");
Serial.println(watt, DEC);
#endif
// just return the pulseCount as a debug value
return pulseCount;
}
void reset_kwh()
{
Serial.println("reset_kwh() called");
}
void onPulse()
{
#ifdef DEBUG
Serial.println("onPulse! - Light pulse detected");
#endif
uint32_t newBlink = millis();
uint32_t interval = newBlink - lastBlink;
#ifdef DEBUG
Serial.print("newBlink(");
Serial.print(newBlink, DEC);
Serial.print(") - lastblink(");
Serial.print(lastBlink, DEC);
Serial.print(") = interval(");
Serial.print(interval, DEC);
Serial.println(")");
#endif
watt = (3600000.0 / interval) / ppwh;
lastBlink = newBlink;
pulseCount++;
#ifdef DEBUG
Serial.print("Count:");
Serial.println(pulseCount, DEC);
Serial.print("onPulse! - watt:");
Serial.println(watt, 3);
#endif
}
uint32_t get_watt()
{
watt_dummy++;
#ifdef DEBUG
Serial.print("get_watt called, returned ");
Serial.println(watt_dummy, DEC);
#endif
return watt_dummy;
}
void reset_watt()
{
}