@mfalkvidd you are so right!!! the "wait" is the problem... i changed the script.. i use a if to check if the update-interval is over and then i go through the dht loop....
now the bounce are also working..!
here my code...
#define MY_DEBUG
#define MY_RADIO_NRF24
//#define MY_REPEATER_FEATURE
// Define Node ID
#define MY_NODE_ID 101
#define RELAY_ON 1
#define RELAY_OFF 0
#define SSR_A_ID 1 // Id of the sensor child
#define SSR_B_ID 2 // Id of the sensor child
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 0//1
#define SENSOR_TEMP_OFFSET 0
#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>
#include <DHT12.h>
#include <Wire.h>
const int buttonPinA = 7;
const int buttonPinB = 8;
const int relayPinA = 6;
const int relayPinB = 5;
int oldValueA = 0;
int oldValueB = 0;
unsigned long startMillis;
unsigned long currentMillis;
bool stateA = false;
bool stateB = false;
float lastTemp;
float lastHum;
uint8_t nNoUpdatesTemp;
uint8_t nNoUpdatesHum;
bool metric = true;
static const uint8_t FORCE_UPDATE_N_READS = 10;//10
static const uint64_t UPDATE_INTERVAL = 30000;//30000
Bounce debouncerA = Bounce();
Bounce debouncerB = Bounce();
MyMessage msgA(SSR_A_ID, V_STATUS);
MyMessage msgB(SSR_B_ID, V_STATUS);
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
DHT12 dht12;
void setup()
{
//Serial.begin(115200);
Wire.begin();
pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up
pinMode(buttonPinB, INPUT_PULLUP); // Setup the button Activate internal pull-up
// After setting up the buttons, setup debouncer
debouncerA.attach(buttonPinA);
debouncerA.interval(5); //5
debouncerB.attach(buttonPinB);
debouncerB.interval(5);//5
// Make sure relays are off when starting up
digitalWrite(relayPinA, RELAY_ON);
digitalWrite(relayPinB, RELAY_ON);
// Then set relay pins in output mode
pinMode(relayPinA, OUTPUT);
pinMode(relayPinB, OUTPUT);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("2xRelais,2xButton,DHT12", "1.2a");
// Register all sensors to gw (they will be created as child devices)
present(SSR_A_ID, S_LIGHT);
present(SSR_B_ID, S_LIGHT);
present(CHILD_ID_HUM, S_HUM);
present(CHILD_ID_TEMP, S_TEMP);
metric = getControllerConfig().isMetric;
}
/*
Example on how to asynchronously check for new messages from gw
*/
void loop()
{
currentMillis = millis();
debouncerA.update();
// Get the update value
int valueA = debouncerA.read();
if (valueA != oldValueA) {
send(msgA.set(stateA ? false : true), true); // Send new state and request ack back
oldValueA = valueA;
}
debouncerB.update();
// Get the update value
int valueB = debouncerB.read();
if (valueB != oldValueB) {
send(msgB.set(stateB ? false : true), true); // Send new state and request ack back
oldValueB = valueB;
}
// Force reading sensor, so it works also after sleep()
// dht12.readSensor(true);
if (currentMillis - startMillis >= UPDATE_INTERVAL)
{
// Get temperature from DHT library
float temperature = dht12.readTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT!");
} else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
// Only send temperature if it changed since the last measurement or if we didn't send an update for n times
lastTemp = temperature;
// apply the offset before converting to something different than Celsius degrees
temperature += SENSOR_TEMP_OFFSET;
if (!metric) {
temperature = dht12.readTemperature();
}
// Reset no updates counter
nNoUpdatesTemp = 0;
send(msgTemp.set(temperature, 1));
#ifdef MY_DEBUG
Serial.print("T: ");
Serial.println(temperature);
#endif
} else {
// Increase no update counter if the temperature stayed the same
nNoUpdatesTemp++;
}
// Get humidity from DHT library
float humidity = dht12.readHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT");
} else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
// Only send humidity if it changed since the last measurement or if we didn't send an update for n times
lastHum = humidity;
// Reset no updates counter
nNoUpdatesHum = 0;
send(msgHum.set(humidity, 1));
#ifdef MY_DEBUG
Serial.print("H: ");
Serial.println(humidity);
#endif
} else {
// Increase no update counter if the humidity stayed the same
nNoUpdatesHum++;
}
startMillis = currentMillis;
Serial.print("Startzeit: ");
Serial.println(startMillis);
}
// Sleep for a while to save energy
//wait(UPDATE_INTERVAL);
}
void receive(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type == V_STATUS) {
switch (message.sensor) {
case 1:
stateA = message.getBool();
digitalWrite(message.sensor + 4, stateA ? RELAY_ON : RELAY_OFF);
break;
case 2:
stateB = message.getBool();
digitalWrite(message.sensor + 4, stateB ? RELAY_ON : RELAY_OFF);
break;
}
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.println(message.sensor);
//Serial.print("from node:");
//Serial.println(message.sender);
//Serial.print(", New status: ");
Serial.println(message.getBool());
}
}