after zunoSendDeviceToSleep output is not set at next run

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
billyboy
Posts: 58
Joined: 16 Mar 2013 21:33

after zunoSendDeviceToSleep output is not set at next run

Post by billyboy » 22 Jul 2018 13:58

I am trying to get it work, but I fail. When I add zunoSendDeviceToSleep() to my code, the HC_SR04_POWER_PIN is not set high again.
if I remove zunoSendDeviceToSleep() from my code and add a delay() then the output is set correctly. What do I do wrong?

Code: Select all

// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on Z-Uno thats Digital 9
// Connect SDA to i2c data - on Z-Uno thats Digital 10
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here

//DHT22 pin is 11

#include "ZUNO_BMP180.h"
#include "ZUNO_DHT.h"

//#define DEBUG

#define TANK_TOTAL_CAPACITY 1000

#define LIGHTSENSOR_PIN A0
// BMP085 SCL PIN 9
// BMP085 SDA PIN 10
#define DHT22_PIN 11
#define HC_SR04_READ_PIN 12
#define HC_SR04_TRIGGER_PIN 13
#define HC_SR04_POWER_PIN 19

// channel number (for reporting)
#define ZUNO_CHANNEL_NUMBER_1   1
#define ZUNO_CHANNEL_NUMBER_2   2
#define ZUNO_CHANNEL_NUMBER_3   3
#define ZUNO_CHANNEL_NUMBER_4   4
#define ZUNO_CHANNEL_NUMBER_5   5


ZUNO_BMP180 bmp;
DHT DHT22_sensor(DHT22_PIN, DHT22);

static  int16_t Temperature = 0;
static uint16_t Humidity = 0;
static uint16_t Pressure = 0;
static uint16_t WaterLevel = 0;
static uint16_t Light = 0;

// set up channels
ZUNO_SETUP_CHANNELS(
      ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,         SENSOR_MULTILEVEL_SCALE_CELSIUS,          SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, GetterTemperature),
      ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_RELATIVE_HUMIDITY,   SENSOR_MULTILEVEL_SCALE_PERCENTAGE_VALUE, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, GetterHumidity),
      ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_BAROMETRIC_PRESSURE, SENSOR_MULTILEVEL_SCALE_KILO_PASCAL,      SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_ONE_DECIMAL, GetterPressure),
      ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TANK_CAPACITY,       SENSOR_MULTILEVEL_SCALE_LITER,            SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS, GetterWaterLevel),
      ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_LUMINANCE,           SENSOR_MULTILEVEL_SCALE_PERCENTAGE_VALUE, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, GetterLight)
);

// next macro sets up the Z-Uno frequency
ZUNO_SETUP_FREQUENCY(ZUNO_FREQ_EU);

ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE); // SLEEPING MODE
 
void setup() 
{
#ifdef DEBUG
  Serial.begin(115200);
#endif
  if (!bmp.begin()) 
  {
#ifdef DEBUG
    Serial.println("Could not find a valid BMP180 sensor, check wiring!");
#endif
  }
  DHT22_sensor.begin();

  pinMode(HC_SR04_READ_PIN, INPUT);
  pinMode(HC_SR04_TRIGGER_PIN, OUTPUT);
  pinMode(HC_SR04_POWER_PIN, OUTPUT);
  digitalWrite(HC_SR04_TRIGGER_PIN, LOW);
  digitalWrite(HC_SR04_POWER_PIN, HIGH);              
}
  
void loop() 
{
#ifdef DEBUG  
    Serial.println("=============================================");  
#endif

  Get_BMP085_Sensor();
  Get_DHT22_Sensor();
  Get_Light_Sensor();
  Get_HC_SR04_Sensor();
  
  zunoSendReport(ZUNO_CHANNEL_NUMBER_1);
  zunoSendReport(ZUNO_CHANNEL_NUMBER_2);
  zunoSendReport(ZUNO_CHANNEL_NUMBER_3);
  zunoSendReport(ZUNO_CHANNEL_NUMBER_4);
  zunoSendReport(ZUNO_CHANNEL_NUMBER_5);
  delay(200);
  zunoSendDeviceToSleep();
}

void Get_HC_SR04_Sensor()
{
  int duration;
  int distance;
  digitalWrite(HC_SR04_POWER_PIN, HIGH); 
  delay(10);
    
  // trigger measurement
  digitalWrite(HC_SR04_TRIGGER_PIN, LOW);
  delayMicroseconds(10);
  digitalWrite(HC_SR04_TRIGGER_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(HC_SR04_TRIGGER_PIN, LOW);

  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  duration = pulseIn(HC_SR04_READ_PIN, HIGH, 100000);
 
  // convert the time into a distance
  distance =  duration / 70;//29.1; //cm
  if (distance)
  {
    //WaterLevel = distance;
    WaterLevel = map(distance, 0, 100, TANK_TOTAL_CAPACITY, 0);
  }
  
#ifdef DEBUG
    Serial.println("HC-SR04");
    Serial.print("WaterLevel = ");
    Serial.print(WaterLevel);
    Serial.println(" Liter");
    Serial.println();  
#endif

  //digitalWrite(HC_SR04_POWER_PIN, LOW); 
}

void Get_BMP085_Sensor()
{
    // Get Temperature
    uint16_t Temp = bmp.readTemperature();
    Pressure = (bmp.readPressure() / 100);
    //float Altitude = bmp.readAltitude();
    
#ifdef DEBUG
    Serial.println("BMP085");
    Serial.print("Temperature = ");
    Serial.print(Temp);
    Serial.println(" *C");
        
    // Get Pressure
    Serial.print("Pressure = ");
    Serial.print(Pressure);
    Serial.println(" Pa");
    
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
//    Serial.print("Altitude = ");
//    Serial.print(Altitude);
//    Serial.println(" meters");

  // you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
  //  Serial.print("Real altitude = ");
  //  Serial.print(bmp.readAltitude(101300));
  //  Serial.println(" meters");
    Serial.println();  
#endif
}

bool Get_DHT22_Sensor()
{
  byte result;
  result = DHT22_sensor.read(true); 
  if (result == 0)
  {
    Temperature = DHT22_sensor.readTemperatureC10() * 10;
    Humidity = DHT22_sensor.readHumidityH10();
  }
  //int Humidity = DHT22_sensor.readHumidityH10();
  //float Humidity = DHT22_sensor.readHumidity();
  //float Temperature = DHT22_sensor.readTemperature();
  
#ifdef DEBUG
  //Serial.print("DHT read result = :");
  //Serial.println(result);
  Serial.println("DHT22");
  Serial.print("Temperature = ");
  Serial.print((float)Temperature, 2);
  Serial.println(" *C");
  Serial.print("Humidity = ");
  //Serial.print((float)Humidity, 2); 
  Serial.print(Humidity);
  Serial.println(" %");
  Serial.println();  
#endif

  return (result == 0);
}

void Get_DHT22_RAW()
{
  byte result;
  byte i;
  byte  raw_data[5]; 
  
  result = DHT22_sensor.read(true); 
  Serial.print("DHT read result:");
  Serial.println(result);

  Serial.print("Raw data: { ");
  DHT22_sensor.getRawData(raw_data);
  for(i=0;i<5;i++)
  {
    Serial.print(raw_data[i], HEX);
    Serial.print(" ");
  }
  Serial.println("} ");
}

void Get_Light_Sensor()
{
  int value = analogRead(LIGHTSENSOR_PIN);
  Light = map(value, 0, 1023, 0, 10000);

#ifdef DEBUG
  Serial.println("LDR");
//  Serial.print("Counts = ");
//  Serial.println(value);
  Serial.print("Light = ");
  Serial.print(Light);
  Serial.println(" %");
  Serial.println();    
#endif
}

int16_t GetterTemperature()
{
  return Temperature;
}

int16_t GetterHumidity()
{
  return Humidity;
}
int16_t GetterPressure()
{
  return Pressure;
}
int16_t GetterWaterLevel()
{
  return WaterLevel;
}
int16_t GetterLight()
{
  return Light;
}


p0lyg0n1
Posts: 157
Joined: 04 Aug 2016 07:14

Re: after zunoSendDeviceToSleep output is not set at next run

Post by p0lyg0n1 » 26 Jul 2018 07:50

Hi,
Could you try the new beta?

billyboy
Posts: 58
Joined: 16 Mar 2013 21:33

Re: after zunoSendDeviceToSleep output is not set at next run

Post by billyboy » 16 Aug 2018 15:35

I am now using version 2.14
Where can I find this beta and how to install?

User avatar
PoltoS
Posts: 4224
Joined: 26 Jan 2011 19:36

Re: after zunoSendDeviceToSleep output is not set at next run

Post by PoltoS » 18 Aug 2018 19:44

https://forum.z-wave.me/viewtopic.php?f=3427&t=28785

Please see here how to get the beta. Use 2.1.5

Post Reply